How to edit your hosts file on Windows, Mac, or Linux
Editing your local hosts file lets you manually point a domain name to a specific IP address instead of relying on public DNS. This is useful for previewing a website on a new server before updating DNS, or for testing after a server migration.
Hosts file locations
Section titled “Hosts file locations”| Operating System | File Path |
|---|---|
| Windows | C:\Windows\System32\drivers\etc\hosts |
| macOS | /private/etc/hosts |
| Linux | /etc/hosts |
The format for each entry is:
IP_ADDRESS domain.comFor example:
198.252.96.1 hawkhost.com198.252.96.1 www.hawkhost.comWindows
Section titled “Windows”-
Click the Windows button and type notepad.
-
Right-click on Notepad and select Run as Administrator.
-
Click Yes when asked “Do you want to allow this app to make changes to your device?”
-
In Notepad, click File > Open.
-
Navigate to
C:\Windows\System32\drivers\etc\. If you don’t see the hosts file, change the file type dropdown from “Text Documents” to All files, then select the hosts file. -
Add your entries at the bottom of the file, one per line.
-
Save the file (File > Save).
-
Open Terminal (via Spotlight or Applications > Utilities > Terminal).
-
Run the following command:
Terminal window sudo nano /private/etc/hosts -
Enter your user password when prompted.
-
Add your entries at the bottom of the file.
-
Press Control+O then Return to save. Press Control+X to exit.
-
Open a terminal and run:
Terminal window sudo nano /etc/hosts -
Enter your password when prompted.
-
Add your entries at the bottom of the file.
-
Press Control+X, then Y to confirm saving, then Return to write the file.