How To Change Hosts File (Windows and Mac)

How to change hosts file

How To Change Hosts File (Windows and Mac)

Sometimes it can be necessary to change the hosts file on your computer so when you go to a website, you are directed to another server. One such reason for this might be that you are building a new website on a new server whilst keeping your existing website online for the time being.

Changing the hosts file on your computer will mean that only you and anyone else who has done the same process with the same information will be able to see the website which is hosted on the different server.

Although some people may feel nervous making such changes, it’s actually very easy to do and won’t do anything bad to your computer, internet connection or website. But just to be safe, always make a copy of the hosts file before changing it.

Mac OSX X

  1. Open Applications > Utilities > Terminal
  2. Type in the following code,
    sudo nano /private/etc/hosts
  3. Type in your Mac login password if prompted
  4. Start a new line at the bottom of the file, and add the hosts entry, I.e.
    100.0.000.00 yourwebsite.com.au www.yourwebsite.com.au (ensure the IP address is changed to that of the server your website is hosted and the domain name is changed to reflect that of your website)
  5. Save the hosts file by pressing ‘Control + X’
  6. Clear the DNS cache by typing in this command,
    dscacheutil -flushcache
  7. Close the terminal

Windows 7 and Vista

  1. Click Start
  2. Type in ‘Notepad’
  3. Right click ‘Notepad’ and select ‘Run as administrator’
  4. Click Continue on the ‘Windows needs your permission’ UAC window
  5. When Notepad opens, click File > Open
  6. In the filename field, type in:
    C:\Windows\System32\Drivers\etc\hosts
  7. Click Open
  8. Start a new line at the bottom of the file and enter the new entry, I.e.
    100.0.000.00 yourwebsite.com.au www.yourwebsite.com.au (ensure the IP address is changed to that of the server your website is hosted and the domain name is changed to reflect that of your website)
  9. Click Save

To undo the change you have made to your hosts file, follow the exact same steps listed above, remove the new line you have entered and save the file.