Using /etc/hosts on macOS to Point a Domain to a Staging Server
When previewing a website on a migration server before the domain goes live, you can override DNS locally using the /etc/hosts file.
Why This Is Needed
Some domains resolve to both:
- An IPv6 address (often pointing to the live site or CDN)
- An IPv4 address (your staging server)
If you only override IPv4 like this:
162.247.78.69 ama-toronto.com
Firefox and Safari may still prefer IPv6 and show the live site instead.
Instead of overriding IPv6 in the hosts file (which can cause conflicts with local environments), the recommended approach is to temporarily disable IPv6 while testing.
Step-by-Step Instructions
1. Open the hosts file
Open Terminal and run:
sudo nano /etc/hosts
2. Add your domain entry
Add this line to the bottom of the file:
162.247.78.69 ama-toronto.com
If needed, also include the www version:
162.247.78.69 www.ama-toronto.com
3. Save the file
In nano:
- Press
Ctrl + Oto save - Press
Enterto confirm - Press
Ctrl + Xto exit
4. Flush the DNS cache
Run:
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
5. Temporarily disable IPv6 (important)
This ensures your system does not prefer the live IPv6 address.
Run:
networksetup -setv6off Wi-Fi
If your network service is not named Wi-Fi, list available services with:
networksetup -listallnetworkservices
Then use the correct name in the command.
6. Reload your browser
Quit and reopen your browser, then visit the domain.
You may see an SSL warning. This is expected if the staging server does not have a valid certificate for the domain yet.
Re-enable IPv6 after testing
Once you are done testing, re-enable IPv6:
networksetup -setv6automatic Wi-Fi
How to Verify It Worked
Run:
dscacheutil -q host -a name ama-toronto.com
You should see:
ip_address: 162.247.78.69
Summary
Use this setup when:
- Your staging server is IPv4 only
- The live site is available over IPv6
162.247.78.69 ama-toronto.com
Then temporarily disable IPv6 to ensure browsers do not prefer the live IPv6 route.
This avoids conflicts with local environments and ensures your domain resolves to the staging server correctly.
