Modifying Your Hosts File
If you are moving a website to a new server but want to keep the old website live during testing,
you can modify the hosts file on your own computer. This allows your computer to view the website
from the new server before changing the live DNS records.
based on the domain’s public DNS records.
What Does the Hosts File Do?
Normally, your computer uses public DNS to find out which server a domain should load from. By editing your hosts file,
you can override this locally and tell your computer to load a domain from a specific IP address instead.
This is useful when testing a website on a new hosting server before changing the domain nameservers or DNS records.
Example Hosts File Entry
A hosts file entry normally uses this format:
server-ip-address example.com
server-ip-address www.example.com Replace server-ip-address with the IP address of your hosting server, and replace
example.com with your own domain name.
Server IP addresses can vary depending on which server your account is hosted on.
Example Cheap Host Server IPs
If you have been advised to test against one of these servers, your hosts file entries may look like the examples below.
31.132.0.114 example.com
31.132.0.114 www.example.com
185.103.96.26 example.com
185.103.96.26 www.example.com
199.231.184.209 example.com
199.231.184.209 www.example.com
Modify the Hosts File on Windows
On Windows, the hosts file needs to be edited with administrator permissions.
- Open the Windows Start Menu.
- Type Notepad into the search box.
- Right-click Notepad.
- Select Run as administrator.
- In Notepad, go to File and then Open.
- Open the hosts file from the path below.
%WinDir%\System32\drivers\etc\hosts If you cannot see the hosts file, change the file type dropdown in Notepad from Text Documents
to All Files.
Add your custom entries at the bottom of the file. For example:
185.103.96.26 example.com
185.103.96.26 www.example.com- Replace the IP address with your correct server IP.
- Replace example.com with your own domain name.
- Save the file using File then Save, or press Ctrl + S.
Modify the Hosts File on macOS
On macOS, the hosts file can be edited using Terminal.
- Open Terminal.
- Run the command below to open the hosts file using Nano.
sudo nano /etc/hosts You may be asked to enter your Mac password. When typing the password, the characters may not appear on screen.
This is normal.
Add your custom hosts entries at the bottom of the file. For example:
185.103.96.26 example.com
185.103.96.26 www.example.com- Replace the IP address with your correct server IP.
- Replace example.com with your own domain name.
- Press Control + O to save the file.
- Press Enter to confirm.
- Press Control + X to exit Nano.
Flush Your DNS Cache
After changing your hosts file, you may also need to clear your local DNS cache so the change takes effect.
Windows
Open Command Prompt as administrator and run:
ipconfig /flushdnsmacOS
Open Terminal and run:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponderTest the Website
Once the hosts file has been updated, open your browser and visit your domain name.
Your computer should now load the website from the IP address specified in the hosts file.
- Use a private or incognito window to avoid browser cache issues.
- Clear your browser cache if the old version still appears.
- Test both the non-www and www versions of the domain.
- Remove the hosts file entries when testing is complete.
Remove Hosts File Changes After Testing
Once you have finished testing, remember to remove the custom hosts file entries or comment them out.
Otherwise, your computer may continue loading the website from the test server instead of using live DNS.
To disable an entry without deleting it, you can place a # at the start of the line:
# 185.103.96.26 example.com
# 185.103.96.26 www.example.comNeed Help Testing a Migration?
If you are unsure which server IP to use, or if your website does not load correctly after modifying your hosts file,
please sign in to your hosting account and open a support ticket.