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 (*.*)
.
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]
[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
- Open Terminal:
-
Click Launchpad, type
Terminal
, and open it. -
Open the hosts file with elevated permissions:
You’ll be prompted for your administrator password.sudo nano /etc/hosts
-
Use the arrow keys to scroll to the bottom of the file.
-
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.
-
Press Control + O to save, then Enter to confirm, and Control + X to exit.
-
Flush the DNS cache so your changes take effect immediately:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
-
Test the change:
Replaceping [your-domain-name]
[your-domain-name]
with the domain you added to the hosts file.
Example:
ping example.com
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.