Editing your hosts file

09/08/14

When you migrate a site over to a new server you want to test that it works on the new server before updating the DNS or A records. However, you can only view the site if you use the actual domain name.

To solve this problem you can edit your computer's hosts file and tell it what IP a domain name should point to instead of having it look up the DNS records.

In the hosts file you want to add the IP and then the domain name you want to point to the IP address. Each line is for a new entry.

192.168.101.0 example.com
192.168.101.10 example2.com

On Windows the hosts file is located at C:\Windows\System32\drivers\etc\hosts. You will need admin privileges to overwrite it and in some cases you cannot overwrite it directly. If you can’t overwrite it directly you can save a copy of the file somewhere else on your computer, edit it, and replace the original.

On a Mac open up the terminal and edit the file with sudo nano /private/etc/hosts. It will ask you for a password and after entering it you can edit the file. If you do not have a password set for your user then this command may not work and you will need to set up a password for your user.

For Mac users there is also a free application available for managing hosts files called Gas Mask. Highly recommended if you'll need to edit your hosts files regularly!

Profile picture for user robertparker
Name
Robert Parker