Modifying your local hosts file (Mac)

In this tutorial you will be shown how to modify your local hosts file, to manually configure where a domain points to on your local machine. This is useful after a migration, as you are able to browse and test your website on our servers before changing over your nameservers/DNS.

Step 1: Terminal

Open the Mac terminal by navigating to Applications > Utilities > Terminal

Step 2: Edit Hosts File

Once the terminal has opened up, paste in the command:

sudo nano /private/etc/hosts

It will prompt you for your password, which you will have to enter in. It will not show any characters, hit enter when this is completed.

You should now see your hosts file, ready for editing.

Append the file with the IP address and your domain, with a space in between.

It is recommended to add 2 records, one for yourdomain.com, and one for www.yourdomain.com, they must be on separate lines.

We will be able to provide you with your new IP address.

Hit ctrl+x to exit, it will prompt you to save. Hit the y key to continue.

It will then prompt you for the file name, leave this as it is and hit enter.

You have now saved the hosts file!

Step 3: Flush DNS

You will need to clear your DNS cache for the new settings to take effect. This is also done through the terminal.

Simply paste in the command

dscacheutil -flushcache

And hit enter.

Nothing will be printed into the terminal, it will simply prompt you for another command.

You have now successfully modified your hosts file! You can now visit your domain and it will load to the new server specified!