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.

  • You probably just need to clear your web browser's cache.
    – ma11hew28
    May 17, 2018 at 15:43

5 Answers 5


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
OSX 10.14.5 and above: dscacheutil -flushcache

  • For clearing dns cache, see: support.opendns.com/hc/en-us/articles/… Sep 20, 2014 at 21:36
  • 2
    Make sure you obviously use the right order too (IP address, then DNS). Dec 12, 2014 at 23:03
  • @user1442960 That sounds so simple, but I had a brain fart and added host entries that were incorrect. As vzwick said, the changes were applied instantly as soon as I corrected them. Sep 9, 2017 at 2:53
  • OSX 10.12 here, sudo dscacheutil -flushcache was just enough to clear the cache
    – oski86
    Sep 13, 2017 at 13:41
  • 1
    On MacOS 10.14.5 dscacheutil -flushcache was enough
    – zengabor
    Jun 9, 2019 at 10:06

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

sudo killall -HUP mDNSResponder



For macOS Sierra (10.12):

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

from https://www.indabaa.com/how-to-reset-flush-dns-cache-in-macos-sierra/


I understand from https://serverfault.com/questions/478534/how-is-dns-lookup-configured-for-osx-mountain-lion 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

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .