---
title: "Mac /etc/hosts not working: how to edit and apply it · Kilobat Guides"
url: "https://kilobat.app/guides/hosts-file-not-working"
description: "An entry in /etc/hosts has no effect on a Mac. Check the file format, clear the DNS cache and find what bypasses the hosts file."
---

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](https://kilobat.app/guides/flush-dns-cache-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

- 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](https://support.apple.com/en-us/101481)
- 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.

## Related guides

- [Flush the DNS cache on a Mac](https://kilobat.app/guides/flush-dns-cache-mac): macOS keeps DNS answers for some time.
- [DNS not resolving on a Mac](https://kilobat.app/guides/dns-server-not-found): When DNS fails, the Mac cannot change a name such as apple.com into an IP address.
- [Proxy settings stop apps from connecting on a Mac](https://kilobat.app/guides/proxy-settings-breaking-apps): A proxy setting sends traffic through another server.
- [Port already in use on a Mac](https://kilobat.app/guides/port-already-in-use): Only one process can listen on a TCP port and address.
