Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

How do I refresh the hosts file on OS X?

Writer Matthew Harrington

I'm trying to develop using subdomains on OSX but don't want to reboot the computer to refresh the hosts file. Normally on linux I'd do /etc/init.d/networking restart but I can't figure out how to do this on OSX.

1

5 Answers

You don't need to. Simply sudo vim /etc/hosts, change what you need to change and go on. Your changes will be applied instantly.

If ping yourdomain.com still gives you the wrong IP, try clearing your DNS cache:

OSX 10.4 and below: lookupd -flushcache
OSX 10.5 + 10.6: dscacheutil -flushcache
OSX 10.7 + 10.8: sudo killall -HUP mDNSResponder
OSX 10.9 and above: sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
OSX 10.12 and above: sudo dscacheutil -flushcache

5

For macOS El Capitan (10.11), go to the Terminal app and type:

sudo killall -HUP mDNSResponder

Source

I understand from that /etc/hosts and /etc/resolv.conf are really no longer used on OS X Sierra 10.12.* (and probably earlier). Indeed when I tried to add hosts to /etc/hosts and reset the cache with the above instructions, the hosts were not recognized, via the host command. However, ping does recognize them.

The networksetup command replaces the "old" way of doing things, or use the Network GUI. For example, to specify dns servers to use:

sudo networksetup -setdnsservers Wi-Fi 8.8.8.8 8.8.4.4

For macOS Sierra (10.12):

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

from

You will need to enter a command to open the Nano text editor. You will need your administrator password, as well. type sudo nano /etc/hosts and then hit return. Enter your administrator password and then hit return.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy