DNS
Changes to /etc/hosts do not work on a Mac
The /etc/hosts file maps names to IP addresses on this Mac only. mDNSResponder reads it, but some apps and settings go around it.
Symptoms
- You add a line to
/etc/hosts, but the browser still opens the old site. - The entry works in Terminal but not in one app.
example.comworks, butwww.example.comdoes not.
Likely causes
- A wrong line format. Each line must start with the IP address, then the host name. A
#starts a comment. - A missing name. The file maps exact names. Add each name that you need, for example
www.example.comas well asexample.com. - Cached answers. macOS or the browser can keep the old address for some time.
- A proxy or an app's own DNS. With a proxy, the proxy server looks up the name. Some apps also have their own DNS settings.
How to check
Show the file.
cat /etc/hostsAsk the macOS resolver for the name. It must show the address from the file.
dscacheutil -q host -a name example.comShow the system proxy settings. A proxy looks up names itself.
scutil --proxy
How to fix it
Open the file in a text editor as an administrator.
sudo nano /etc/hostsNeeds an administrator password.
Add one line for each name. Put the IP address first, then one or more names.
127.0.0.1 example.com www.example.comSave the file. In nano, press Control-O, then Return, then Control-X.
Clear the DNS cache. See Flush the DNS cache on a Mac.
sudo killall -HUP mDNSResponderNeeds an administrator password.
Quit and open the browser again.
If the app uses a proxy, test without the proxy, or add the entry on the proxy server.
Questions
Do I need to restart the Mac?
No. Save the file, clear the DNS cache, then open the app again.
Can I use a wildcard such as *.example.com?
No. The hosts file format has an address, an official host name and aliases. Add each name on the line.
Sources
- hosts(5), man page installed with macOS 27.2
- mDNSResponder(8), man page installed with macOS 27.2
- Apple Support (archived): Reset the DNS cache in OS X
- scutil(8), man page installed with macOS 27.2
Sources checked on 29 October 2026. Man pages are the ones installed with macOS; open one with man <name> in Terminal.