201

On Windows, how do you refresh the hosts file without rebooting?

10 Answers10

180

You don't need to reboot. Any changes you make to the hosts file are immediate. You used to need to reboot for changes to take effect in Windows 9x. That is no longer the case.

However, you may need to restart any applications that do internal hostname or DNS caching, such as web browsers.

Ashley
  • 650
  • 1
  • 6
  • 15
Ferruccio
  • 2,583
  • 2
  • 19
  • 10
  • 11
    But you might need to reboot running applications since DNS entries might be cached. – Barfieldmv Feb 28 '12 at 09:24
  • 1
    Definitely add in the running applications DNS, as that's what ultimately matters. Firefox, from my knowledge and test a few moments ago, takes 60 seconds to refresh. – Xonatron May 21 '12 at 13:44
  • 9
    Restarting Chrome won't pick up changes you make to your hosts file on Windows. Navigate to chrome://net-internals/#dns and press the "Clear host cache" button. – 2Toad Nov 27 '13 at 19:02
  • Sorry but it's not working on my Windows 7. Everyone should look to the other solutions proposed like this: http://computerstepbystep.com/dns_client_service.html – Revious Dec 22 '14 at 11:46
  • Actually I was wrong: no one of the proposed solutions worked. I had to restart windows. Even ping wans't getting the update. A monitoring with ProcMon of ping could help to see which process is called while trying to resolve a domain. – Revious Dec 22 '14 at 11:58
  • @Revious The PING tool is a bit odd in how it handles DNS requests. It's possible for it to be wrong altogether and it happens all the time when resolving hostnames. To check DNS you should be using nslookup. Unfortunately, nslookup doesn't help for hostnames that are set using the HOSTS file. – Nilpo Jul 14 '15 at 16:07
  • @Ferruccio As of which Windows version? You make it sound like everyone's on Windows 10, which is definitely not the case. Thanks! – jpaugh Jul 11 '16 at 19:57
  • @jpaugh - I'm certain this worked for XP, which is what I was using when I answered the question, but I suspect that it worked on every version based on the NT kernel. – Ferruccio Jul 11 '16 at 20:50
  • Ok, thanks! That's awesome. So you mean that a *change* in Windows 9 made reboots necessary? I'm curious because I've never questioned the common wisdom that a restart was necessary. – jpaugh Jul 11 '16 at 21:50
  • Nevermind, I get it. You mean Windows 95, 98; not `9.x`. – jpaugh Jul 11 '16 at 21:51
  • Thank you, helped me a lot! I forgot to reboot software... – QtRoS Mar 11 '20 at 08:01
56

Have you tried ipconfig /flushdns ? I haven't found the need to reboot, though.

38

Just a warning, NSLOOKUP will still retrieve results from DNS Server will never look at hosts file; To check if your new name works try the ping command.

24

IE caches DNS entries. You need to start a new IE instance in order to see host file changes.

21

ipconfig /flushdns will flush the local dns cache.
nbtstat -R will flush netbios cache.

You may want to ensure there are no current connections to the host for which the name resolution you added by using netstat -a or something like tcpview.

Unless you have dns suffixing setup to append the domain names to the end of the host, you can usually tell if it is netbios by the use of a single name for resolution. It is common for corporate networks to suffix domains and add search orders to ease local resolution of hosts on the network.

I have noticed some of the applications I use also cache some of these responses, and must ensure they are completely closed before the resolution works properly. Firefox and IE like to occasionally run in the background, despite not having any active windows, but that may be more my fault than the applications.

Bdoserror
  • 184
  • 1
  • 13
Bob
  • 211
  • 2
  • 2
5

Because changes are seen immediately, you might be seeing another DNS cache in your application. Firefox has a DNS cache with a TTL of around 60 seconds, I believe: I usually just restart firefox if I've made a change and can't wait a minute.

  • Thank you for this! I had no idea I only had to wait 60 seconds (I didn't time it but it's about this) for Firefox to update the DNS. Much better than if it takes more than 60 seconds to re-setup your workflow. – Xonatron May 21 '12 at 13:43
4

This helped for me once: "Restart the dnsclient service and DNS server service" Dave Guenthner [MSFT] Microsoft

Jake Andrew
  • 279
  • 2
  • 4
  • 10
  • For me, `>ipconfig /flushdns` alone did not work without reboot, but that followed by restarting dnsclient did. Thanks! – Kristen Waite Dec 12 '13 at 17:26
2

As @Ferruccio said, Hosts changes should be immediate in Windows. However, if you're using something like Microsoft Firewall Client Management software, that could be doing the DNS queries for you. Try disabling any proxy software and see if that works.

1

I use Windows Vista connect to an office via a VPN. I use the LMHOSTS file to define names for IP addresses the other side of the VPN.

Unlike the other comments, I find that pinging a name after updating the LMHOSTS file does not use the new IP immediately. It does happen eventually but to speed up the process I use:

nbtstat -R

"-R (Reload) Purges and reloads the remote cache name table"

I have tried ipconfig /flushdns but it did not work for me.

[You have to open the command as an Administrator. Or run it from a command prompt with administrator privileges]

JamPickle
  • 111
  • 4
0

Powershell cmdlets Set-HostsEntry and Remove-HostsEntry no reboot needed, can be scheduled, could probably be triggered upon connection to specific Wifi or Network names

Syntax: Set-HostsEntry -IPAddress 10.5.6.7 -HostName 'myserver' and Remove-HostsEntry -HostName 'myserver'

install as part of carbon package from http://get-carbon.org/

worked for me and my temporary internal email server.

IronOak
  • 19
  • 1