How do I refresh the hosts file on OS X?
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
For El Capitan, go to the Terminal app and type:
sudo killall -HUP mDNSResponder
Source