You can test a website's functionality on your local computer before updating public DNS records by mapping a domain name to a specific IP address in your local hosts file. This allows you to verify that a website loads correctly on a new server while the rest of the internet still sees the old version.
Before you begin
You will need:
A computer with administrative or administrator privileges.
The IP address of the server where the website is currently hosted or being moved to.
The domain name (e.g.,
example.com) you wish to test.
How to test a website locally
The process for editing the hosts file depends on your computer's operating system.
Windows
Click the Start menu and type
Notepad.Right-click Notepad and select Run as administrator.
In Notepad, go to File > Open.
Navigate to the following path:
C:\Windows\System32\drivers\etcIn the "Files" dropdown menu (next to the address bar), change the selection from Text Documents (*.txt) to All Files (.).
Select the file named
hostsand click Open.Scroll to the bottom of the file and add a new line with the IP address, a space, and the domain name. Example:
192.0.2.10 example.comSave the file and close Notepad.
macOS
Open Terminal (found in Applications > Utilities).
Type the following command and press Enter:
sudo nano /etc/hostsEnter your system administrator password when prompted (characters will not appear as you type).
Use the arrow keys to move to the bottom of the file.
Add a new line with the IP address, a space, and the domain name. Example:
192.0.2.10 example.comPress Control+O to save the changes, then press Enter to confirm the filename.
Press Control+X to exit the editor.
Confirm the result
Open a web browser.
Clear your browser cache or open a private/incognito window.
Type the domain name (e.g.,
example.com) into the address bar.The browser should load the website from the IP address specified in your hosts file.
If the website still shows the old version
If the site does not update after you have edited the hosts file, your computer may be using a cached DNS result.
Clear your local DNS cache.
Windows: Open Command Prompt and type
ipconfig /flushdns.macOS: Open Terminal and type
sudo dscache_ -flushdns.
Restart your browser.
Check for a Proxy or VPN. If you are using a VPN or a proxy service, it may bypass your local hosts file settings. Disable these services to test the local connection.
Limitations
Local Scope: This change only affects the computer you performed the edit on. Other devices and users will still see the original site until the public DNS records are updated.
Browser Caching: Browsers often cache DNS and site data. If you see the old site, try an Incognito window to bypass the cache.
Reversion: To return to normal browsing, you must delete the line you added to the hosts file or restart your computer.
