Skip to content

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.

Operating SystemFile Path
WindowsC:\Windows\System32\drivers\etc\hosts
macOS/private/etc/hosts
Linux/etc/hosts

The format for each entry is:

IP_ADDRESS domain.com

For example:

198.252.96.1 hawkhost.com
198.252.96.1 www.hawkhost.com
  1. Click the Windows button and type notepad.

  2. Right-click on Notepad and select Run as Administrator.

  3. Click Yes when asked “Do you want to allow this app to make changes to your device?”

  4. In Notepad, click File > Open.

  5. 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.

  6. Add your entries at the bottom of the file, one per line.

  7. Save the file (File > Save).

  1. Open Terminal (via Spotlight or Applications > Utilities > Terminal).

  2. Run the following command:

    Terminal window
    sudo nano /private/etc/hosts
  3. Enter your user password when prompted.

  4. Add your entries at the bottom of the file.

  5. Press Control+O then Return to save. Press Control+X to exit.

  1. Open a terminal and run:

    Terminal window
    sudo nano /etc/hosts
  2. Enter your password when prompted.

  3. Add your entries at the bottom of the file.

  4. Press Control+X, then Y to confirm saving, then Return to write the file.