Flushing DNS Cache: How to Reload Hosts File Changes on Windows Without Rebooting


4 views

When you modify the Windows hosts file (located at C:\Windows\System32\drivers\etc\hosts), the changes might not take effect right away due to DNS caching. Windows maintains a DNS resolver cache to improve performance, but this means your system may continue using old entries until the cache is cleared.

The most straightforward method is using Command Prompt with administrative privileges:

ipconfig /flushdns

This command clears the DNS resolver cache, forcing Windows to reread the hosts file on the next DNS request.

For applications maintaining their own cache:

# Restart the DNS Client service
net stop dnscache
net start dnscache

Some applications like web browsers have their own DNS caching mechanisms. In such cases, you may need to restart the application or clear its cache.

For those who prefer PowerShell:

Clear-DnsClientCache

This cmdlet performs the same function as ipconfig /flushdns but integrates better with PowerShell scripts.

To confirm your hosts file changes are active:

ping yourdomain.com
nslookup yourdomain.com

These commands will show whether the system is resolving to the IP specified in your hosts file.

For developers who frequently modify the hosts file, consider creating a batch script:

@echo off
echo Applying hosts file changes...
ipconfig /flushdns > nul
echo DNS cache cleared successfully
pause

Save this as flushdns.bat and run as administrator when needed.

If changes still aren't reflected:

  • Check for typos in the hosts file
  • Ensure there's no duplicate entry overriding your change
  • Verify the hosts file isn't read-only
  • Check for Group Policy restrictions

When modifying the Windows hosts file (C:\Windows\System32\drivers\etc\hosts), changes don't take effect immediately because DNS entries are cached. Rebooting works but is inefficient for developers who need quick testing cycles.

Use these commands in sequence:

ipconfig /flushdns
nbtstat -R
nbtstat -RR

For more thorough refresh:

net stop dnscache
net start dnscache

Create a reusable script:

function Update-Hosts {
    Write-Host "Flushing DNS cache..."
    ipconfig /flushdns | Out-Null
    
    Write-Host "Reloading NetBIOS cache..."
    nbtstat -R | Out-Null
    nbtstat -RR | Out-Null
    
    Write-Host "Restarting DNS Client service..."
    Restart-Service -Name Dnscache -Force
    
    Write-Host "Hosts file changes should now be active"
}

Test with ping or nslookup:

ping yourtestdomain.com
nslookup yourtestdomain.com
  • Run Command Prompt as Administrator
  • Check for typos in hosts file
  • Some applications maintain their own DNS cache