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.

Applies to: All current macOS versions.Checked: 29 October 2026

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.com works, but www.example.com does 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.com as well as example.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

  1. Show the file.

    cat /etc/hosts
  2. Ask the macOS resolver for the name. It must show the address from the file.

    dscacheutil -q host -a name example.com
  3. Show the system proxy settings. A proxy looks up names itself.

    scutil --proxy

How to fix it

  1. Open the file in a text editor as an administrator.

    sudo nano /etc/hosts

    Needs an administrator password.

  2. Add one line for each name. Put the IP address first, then one or more names.

    127.0.0.1   example.com www.example.com
  3. Save the file. In nano, press Control-O, then Return, then Control-X.

  4. Clear the DNS cache. See Flush the DNS cache on a Mac.

    sudo killall -HUP mDNSResponder

    Needs an administrator password.

  5. Quit and open the browser again.

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

Sources checked on 29 October 2026. Man pages are the ones installed with macOS; open one with man <name> in Terminal.