The hosts file lets you override DNS for a specific domain on a single machine, so your computer connects directly to the IP address you specify. This article shows you how to locate and edit the hosts file on Windows, Linux, and macOS.
What the hosts file does
Modifying your hosts file is useful when you want to preview a site before DNS goes live, test SSL on a temporary URL, verify that an alias site works prior to DNS changes, or troubleshoot other DNS-related issues. Each entry you add includes the IP address you want the site to resolve to and a version of the internet address. For example:
102.54.94.97 example.com 38.25.63.10 www.example.com
Once you save the file, your local machine resolves those addresses directly to the IPs you specified. When testing is complete, remove the entries.
Before you begin
- Administrator or root access on your computer. Editing the hosts file requires elevated permissions on every supported operating system.
- The IP address you want to test against. Get this from your hosting control panel or from Exact Hosting Support.
- A plain-text editor. Notepad on Windows, nano or vi on Linux, or TextEdit (plain text mode) on macOS.
Warning: Remove your test entries from the hosts file once you finish testing. Forgotten entries can mask real DNS issues and cause confusion later.
Modifying the hosts file on Windows
On Windows, you must run your text editor as an administrator to save changes to the hosts file.
- Press the Windows key and type Notepad.
- Right-click Notepad in the search results and select Run as administrator.
- In Notepad, select File > Open and navigate to:
C:\Windows\System32\Drivers\etc\hosts - If you do not see the file, change the file type filter in the Open dialog to All Files.
- Add your new entries on their own lines at the bottom of the file. Each entry is the IP address followed by whitespace and the domain.
- Select File > Save to save your changes.
Note: These instructions apply to currently supported versions of Windows. If you are running an older release, the path to Notepad in the Start menu may differ, but the hosts file location is the same.
Modifying the hosts file on Linux
- Open a Terminal window.
- Run the following command to open the hosts file in a text editor:
sudo nano /etc/hosts - Enter your user password when prompted.
- Add your new entries on their own lines at the bottom of the file.
- Press Ctrl-X to exit, then enter y to confirm you want to save your changes, and press Enter to keep the same filename.
Modifying the hosts file on macOS
- Open the Terminal application (Applications > Utilities > Terminal).
- Run the following command:
sudo nano /etc/hosts - Enter your administrator password when prompted.
- Add your new entries on their own lines at the bottom of the file.
- Press Ctrl-X, enter y to save, and press Enter to confirm the filename.
- Flush the DNS cache so your changes take effect immediately:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Next steps
- Test your site. Open the domain in your browser to confirm it resolves to the IP address you specified.
- Remove test entries when finished. Edit the hosts file again and delete the lines you added to restore normal DNS behavior.
- Troubleshoot site loading issues. See Troubleshooting Website Loading Issues if the site still does not load.
Questions? Contact Exact Hosting Support.
How helpful was this article?
Thanks for your feedback!
Do you still need help? If so please submit a request here.