Skip to content

How to Configure the Hosts File (Windows & macOS)

Sometimes you may need to manually override DNS for specific domains.

DNS (Domain Name System) is what translates human-friendly names (like cadiz3.com.au) into IP addresses that computers understand.

By editing the hosts file on your computer, you can tell it to use a specific IP address for a domain name, bypassing regular DNS lookups. This is useful for testing, troubleshooting, or forcing a specific server to be used.


Windows: Editing the Hosts File

Step 1. Open the Start Menu, type Notepad, but do NOT press Enter yet.

Step 2. Right-click on Notepad and select Run as administrator. This is required to edit system files.

Step 3. In Notepad, click File → Open.

Step 4. In the Open dialog, first select This PC in the left panel, then navigate to:

C:\Windows\System32\drivers\etc

Step 5. In the file dialog, change the filter from Text Documents (*.txt) to All Files (*.*).

Screenshot showing file dialog with "All Files" selected

Step 6. Open the file named hosts.

Step 7. Scroll to the bottom of the file and paste entries in the following format:

[IP address]    [domain name]
[IP address]    [another.domain.name]

Example:

202.3.109.11    example.com
202.3.109.11    www.example.com

Important: - Replace the IP address and domain names with the correct values for your use case. - Do NOT include a # at the beginning of these lines. Any line starting with # is treated as a comment and will be ignored.

Step 8. Save the file (File → Save) and close Notepad.

Step 9. Open the Command Prompt: - Press Windows Key + R - Type cmd - Press Enter

Step 10. In Command Prompt, type:

ping [your-domain-name]
Replace [your-domain-name] with the domain you added to the hosts file.

   **Example:**
   ```
   ping example.com.au
   ```
   You should see the IP address you added in the hosts file (for example, `202.3.109.11`) in the ping results.

macOS: Editing the Hosts File

  1. Open Terminal:
  2. Click Launchpad, type Terminal, and open it.

  3. Open the hosts file with elevated permissions:

    sudo nano /etc/hosts
    
    You’ll be prompted for your administrator password.

  4. Use the arrow keys to scroll to the bottom of the file.

  5. Add entries in the following format:

    [IP address]    [domain name]
    [IP address]    [another.domain.name]
    

Example:

202.3.109.11    example.com
202.3.109.11    www.example.com

Important: - Replace the IP address and domain names with the correct values for your use case. - Do NOT include a # at the beginning of these lines. Any line starting with # is treated as a comment and will be ignored.

  1. Press Control + O to save, then Enter to confirm, and Control + X to exit.

  2. Flush the DNS cache so your changes take effect immediately:

    sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
    

  3. Test the change:

    ping [your-domain-name]
    
    Replace [your-domain-name] with the domain you added to the hosts file.

Example:

ping example.com
You should see the IP address you added in the hosts file (for example, 202.3.109.11) in the ping results.


Notes

  • Editing the hosts file overrides DNS for these domains on this computer only.
  • Changes take effect immediately (after saving and, on macOS, flushing the DNS cache).
  • Use this method carefully — incorrect entries can prevent access to websites.