Editing the hosts file on MacOS

Posted on November 7, 2015 by - Domain Names and DNS

Here’s a trick we use all the time when a client moves to our servers, but the nameservers haven’t been updated yet. This trick lets us get on with work while we wait for DNS propagation.

Open Mac Terminal (command line)

Applications -> Utilities -> Terminal.

In the terminal window you just opened copy/paste the command string below, and press return.

sudo nano /private/etc/hosts

Edit the hosts file by adding these two lines to the bottom of the file.

ipaddress domain.com
ipaddress www.domain.com

For example, it should look like: infologistix.ca www.infologistix.ca

Save save your changes by pressing control-o on your keyboard then return to accept the filename. Exit the editor by pressing control-x. This takes you back to the terminal screen.
You may need to flush your Mac’s DNS cache, so copy/paste the below command string into terminal, and press return.

sudo dscacheutil -flushcache

Pretty much the same on Ubuntu and other Linux flavors, but the hosts file is at etc/hosts.

On Windows you can fire up Notepad and open C:\Windows\System32\drivers\etc\hosts