How to Edit Your Hosts File to Test a Website Before Changing Nameservers
When migrating a website to a new hosting server, you may want to test everything before changing the domain's nameservers or DNS records.
By editing your computer's hosts file, you can force your computer to load the website from the new server while the rest of the world continues to see the live site.
What You Need
Before starting, make sure you have:
- Your domain name, for example example.com
- Your new hosting server IP address
Example:
Domain: example.com Server IP: 123.123.123.123
How Hosts File Testing Works
Normally your computer asks DNS servers where a website is located.
When you add an entry to your hosts file, your computer skips DNS and goes directly to the IP address you specify.
Only your computer sees the change. Everyone else continues to see the live website.
Windows Instructions
Step 1: Open Notepad as Administrator
- Click Start.
- Search for Notepad.
- Right-click Notepad.
- Select Run as administrator.
Step 2: Open the Hosts File
In Notepad, click:
File → Open
Browse to:
C:\Windows\System32\drivers\etc\
Change the file type dropdown from:
Text Documents (*.txt)
to:
All Files (*.*)
Then open the file named:
hosts
Step 3: Add Your Domain
Add the following lines at the bottom of the file:
123.123.123.123 example.com 123.123.123.123 www.example.com
Replace:
- 123.123.123.123 with your new server IP address
- example.com with your own domain name
Step 4: Save the File
Press:
Ctrl + S
Clear DNS Cache on Windows
Press:
Windows Key + R
Type:
cmd
Then run:
ipconfig /flushdns
You should see:
Successfully flushed the DNS Resolver Cache
Mac Instructions
Step 1: Open Terminal
- Press Cmd + Space.
- Search for Terminal.
- Open Terminal.
Step 2: Edit the Hosts File
Run:
sudo nano /etc/hosts
Enter your Mac password when prompted.
Step 3: Add Your Domain
Add the following lines at the bottom of the file:
123.123.123.123 example.com 123.123.123.123 www.example.com
Replace the IP address and domain with your own details.
Step 4: Save Changes
Press:
Ctrl + O
Then press:
Enter
Then exit:
Ctrl + X
Clear DNS Cache on Mac
Run:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
No message will normally be displayed.
Testing the Website
Once the hosts file has been updated:
- Open your website in a browser.
- Check that pages load correctly.
- Test contact forms.
- Test logins.
- Check SSL certificates.
- Confirm images and styling load properly.
If WordPress is being migrated, also check:
- The WordPress admin area loads correctly
- Plugins are working
- Contact forms send successfully
- Images, CSS and JavaScript files load correctly
- No mixed content warnings appear
How to Confirm You Are Seeing the New Server
Open Command Prompt on Windows or Terminal on Mac and run:
ping example.com
The IP returned should match your new server IP address.
Example:
Pinging example.com [123.123.123.123]
Remove the Hosts File Entry After Testing
Once the website has been tested and DNS has been updated, remove the lines you added from the hosts file.
This allows your computer to use normal DNS again.
After removing the entries, clear your DNS cache again using the commands above.
Common Issues
Website Still Loads From the Old Server
Clear your browser cache and DNS cache, then try again in a private or incognito window.
SSL Certificate Warning
Make sure the SSL certificate has been installed on the new server for both the main domain and www version.
Cannot Save the Hosts File
On Windows, make sure Notepad was opened as Administrator. On Mac, make sure you used sudo.
Images or Styling Missing
Check that all website files have been migrated correctly and that the database contains the correct website URL.
Example Hosts File Entry
123.123.123.123 example.com 123.123.123.123 www.example.com
Replace the IP address and domain with your own details.
Important Note
Editing the hosts file only affects your own computer. It does not change the live website for visitors and does not update DNS globally.
This makes it a useful way to test a migrated website before changing nameservers or DNS records.