os-x

Add an entry to hosts file on OS X using nano

Adding an entry to the hosts file on OS X is pretty straight forward. First, open up terminal and run the following command.

$ sudo nano /etc/hosts

This will open up the nano editor in terminal.

Default hosts file - OS X

You can now add entires to the file using the following format:

xxx.xxx.xxx.xxx somedomain.com www.somedomain.com

Where xxx.xxx.xxx.xxx is the ip address.

Hosts file - Added entry

When you're finished, press ctrl + o to save the file. Press enter on the filename prompt, then press ctrl + x to exit nano.

Now, enter the following command to flush the DNS cache.

$ sudo dscacheutil -flushcache

Alternatively, if you are using OS X 10.7 or 10.8, you'll want to use this command to flush the DNS cache instead

$ sudo killall -HUP mDNSResponder

more OS X posts