Editing the hosts file


A computer uses DNS to convert hostnames like freethought-internet.co.uk into an IP address like 194.110.243.242 or 2a00:b980:2::242. When you browse to a website your computer takes the website address you requested and converts it into the IP that is then used to actually make a connection to the server and request the website data.

Sometimes you may want to access a website hosted on a server before that website address is actually "pointed" at that server in public DNS. For example if you've got a website hosted elsewhere but have developed a new website hosted by Freethought you may want to access that new website on the Freethought server to test it before you put it live for everyone by updating DNS.
You can accomplish this by updating your operating system's "hosts" file to point a domain at a given IP and override the public DNS records.

macOS and Linux

  1. Open a terminal prompt by searching for "Terminal" either in Spotlight (macOS) or the universal search in Linux (Ubuntu, Fedora etc)
  2. Type the command sudo nano /etc/hosts
  3. Add a new line to the bottom of the file with the domain you'd like to setup with a new IP. For example:

    194.110.243.194 yourdomain.uk
    194.110.243.194 www.yourdomain.uk

  4. Naturally replace the IP address to that of your new server, and use the domain name you actually want to redirect. Remember to do two lines both with an without the www prefix.
  5. If your ISP and website support IPv6 you may want to add two additional lines with an IPv6 address also.
  6. Press Ctrl + O to save your changes.
  7. Press Ctrl + X to quit the nano text editor.
  8. Close your terminal prompt.

Microsoft Windows

  1. Click the start button in the bottom left corner of the window or press the Windows key on your keyboard.
  2. Searching for "Notepad" by just starting to type once the start menu appears.
  3. Right click the icon for Notepad and select "Run as administrator"
  4. Click File > Open and then browse to and open C:\Windows\System32\Drivers\etc\hosts
  5. Add a new line to the bottom of the file with the domain you'd like to setup with a new IP. For example:

    194.110.243.194 yourdomain.uk
    194.110.243.194 www.yourdomain.uk

  6. Naturally replace the IP address to that of your new server, and use the domain name you actually want to redirect. Remember to do two lines both with an without the www prefix.
  7. If your ISP and website support IPv6 you may want to add two additional lines with an IPv6 address also.
  8. Press Ctrl + S or browse to File > Save to save your changes.
  9. Close Notepad.
  10. Close your terminal prompt.

Once the changes have been made you may have to close and re-open your browser for the changes to start working. Remember once your site has gone live with the new hosting to remove those changes to your hosts file by repeating the steps but removing the lines you added previously. This will avoid any confusion in the future if those changes are left in place.
If you aren't sure what the IP address of your hosting is then contact support or check the hosting control panel which should provide this information.