Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I was having a discussion with someone who asked me whether a Linux OS has to be rebooted when the hosts file is modified.

From personal experience, on Windows I change the file but don't reboot and I've seen others do the same thing. I assume Linux has no exception(s), but is there any reason why a reboot is not required (to at least justify my actions)?

Thanks

share|improve this question
add comment

2 Answers

On each DNS request the hosts file is read. This means it is not saved to memory, so the changes you make are in real time.

share|improve this answer
    
So you mean to say that the contents of the file remain on disk but when a request comes into the DNS server, it reads the HOSTS file on my machine? –  gs5 Oct 18 '10 at 23:04
    
Your machine checks the hosts file first. If a mapping is not found for a hostname, then it asks your DNS server. –  Madison S Oct 19 '10 at 0:04
    
I agree with the above. Check out /etc/nsswitch.conf –  JT.WK Oct 19 '10 at 0:11
add comment

In Mac OS X, you do not have to reboot after editing the hosts file. All you have to do is type dscacheutil -flushcacheFor Windows, at least newer than Windows 9x, changes are immediate because of the changes Microsoft made. Since there are a lot of different Linux distributions, each one probably restarts the network service differently, but for Red Hat based OS's, service network restartshould do the trick. Technically, you don't have to restart the Linux machine at all, you just have to restart all the services dependent on the network and your hosts file. It is possible that these services should not be restarted without a full system reboot, but rebooting the system is much easier than killing and relaunching 8+ services and daemons :)

share|improve this answer
    
You should not need to restart any services for editing the hosts file on any OS. The changes should appear as soon as you save the file. –  Zac Garrett Oct 18 '10 at 22:09
    
"Should" is the keyword. Important services cache things all the time. By flushing the cache or restarting the services, the services have to ask the system for the most recent information(which would include the host file changes). While you would expect a read from the hosts file, if a process has something in its cache that hasn't expired, it is going to use the cache. –  Madison S Oct 18 '10 at 22:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.