Learn how to modify your hosts file to sanity check your website before changing your nameservers or DNS
When migrating a domain or website, you may wish to test the new environment before updating your nameservers or DNS settings.
Modifying the Hosts File allows us to do such a task. By modifying the hosts file, we are spoofing our machine to be able to force it to look at a different IP address than the one the rest of the internet is looking at.
Once you have followed the step for either macOS/Linux or Windows below, you should be able to see your website on your new server.
macOS and Linux
To modify your /etc/hosts file on your machine if running macOS or Linux, please do the following –
- nano /etc/hosts
- Add the server’s IP address (you can find this in your Welcome Email or cPanel) and domain name under the last try in the file (see below),
- Save your changes,
- Either reload your web browser or open a new Private Browsing / Incognito window.
93.189.2.226 example.com
You may also add subdomains, which we haven’t covered adding in this guide –
93.189.2.226 example.com hello.example.com 5wire.example.com trees.example.com
Remove or comment out the line once you have completed Step 8.
Microsoft Windows
To modify the /etc/hosts file on a Windows machine, please do the following –
- Open the Start menu.
- If you use Windows 8 or Windows 10, type Win+X on the keyboard or click the Windows icon in the lower-left corner of your desktop interface, or if you use Windows 7 or Windows Vista®, click Start,
- Enter Notepad in the search text box,
- Right-click Notepad and select Run as Administrator,
- In Notepad, open the following file: C:\Windows\System32\Drivers\etc\hosts
- Add the server’s IP address (you can find this in your Welcome Email or cPanel) and domain name under the last try in the file (see below),
- Save your changes,
- Either reload your web browser or open a new Private Browsing / Incognito window.
93.189.2.226 example.com
You may also add subdomains, which we haven’t covered adding in this guide –
93.189.2.226 example.com hello.example.com 5wire.example.com trees.example.com
Remove or comment out the line once you have completed Step 8.
Sanity check my host file is pointing to the right IP
A quick way to check you are viewing your website on the new IP address is to ping your domain.
macOS/Linux
- Open the Terminal,
- Type ping example.com
- If the IP address corresponds to the one you set in the host file, it means you are seeing your website on your new web hosting package.
Microsoft Windows
- Open cmd.exe
- Type ping example.com
- If the IP address corresponds to the one you set in the host file, it means you are seeing your website on your new web hosting package.