How to Edit the Hosts File in macOS Sequoia (2026 Updated Guide)

Editing the hosts file is one of those fundamental Mac skills that web developers, network admins, and technically curious users reach for again and again. Whether you're redirecting a domain to your local development server, blocking a site at the network level, or testing a website migration before DNS propagates, the hosts file is your tool.

The process in macOS Sequoia is nearly identical to previous macOS versions, but there are a few things worth knowing — especially around System Integrity Protection (SIP) and the updated Terminal behavior. This guide walks you through everything from scratch, including how to back up first, how to flush your DNS cache afterward, and how to undo your changes if something goes wrong.


What Is the Hosts File?

The hosts file is a plain text file on your Mac that maps hostnames (domain names) to IP addresses. When you type a URL into your browser, your Mac checks the hosts file before it consults a DNS server. That means you can override where a domain points — just for your machine — without changing anything on the actual DNS.

Common uses include:

  • Local web development: Point mysite.local or even a real domain to 127.0.0.1 (your own machine) so you can test a site locally
  • Pre-launch DNS testing: Verify a new server is working correctly before changing your live DNS records
  • Blocking websites: Redirect a domain to 0.0.0.0 or 127.0.0.1 to make it unreachable on your Mac
  • Network development and testing of custom domain structures

The hosts file lives at: /private/etc/hosts


Before You Start: A Note on System Integrity Protection

macOS has had System Integrity Protection (SIP) since El Capitan, and it's still very much active in Sequoia. SIP protects critical system files from modification — but /private/etc/hosts is not protected by SIP. You can edit it freely as long as you use sudo (administrator privileges), which we'll do below.

You do not need to disable SIP to edit the hosts file. Anyone telling you otherwise is pointing you toward an unnecessary and risky step.


Step 1: Open Terminal

Open Terminal using one of these methods:

  • Spotlight: Press Command + Space, type "Terminal", press Enter
  • Finder: Go to Applications > Utilities > Terminal
  • Launchpad: Open Launchpad and search "Terminal"

Step 2: Back Up Your Hosts File First

Before making any changes, always create a backup. This single step has saved me from headaches more times than I can count. If you make a typo or something stops working, you can instantly restore the original.

Type this command and press Return:

sudo cp /private/etc/hosts ~/Documents/hosts-backup

Enter your administrator password when prompted. You won't see the password as you type — that's normal. The backup file will be saved to your Documents folder as hosts-backup.

To verify the backup was created:

ls ~/Documents/hosts-backup

If it shows the file path, you're good to go.


Step 3: Open the Hosts File in nano

Now open the hosts file for editing using nano, the Terminal text editor. Type this command and press Return:

sudo nano /private/etc/hosts

Enter your administrator password again. The hosts file will open inside Terminal and look something like this:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost

Those top entries are the defaults — leave those alone. You'll add your custom entries below them.


Step 4: Add or Edit Your Entries

Use the arrow keys to move to the bottom of the file. Add your new entries there, one per line. The format is:

IP_ADDRESS    hostname

Separate the IP address and hostname with a tab or multiple spaces. Here are some common examples:

Redirect a domain to your local machine (for development):

127.0.0.1    myproject.local
127.0.0.1    dev.mywebsite.com

Block a website:

0.0.0.0    distractingwebsite.com
0.0.0.0    www.distractingwebsite.com

Point a domain to a specific IP (for pre-launch testing):

123.456.78.90    www.mywebsite.com

Pro tip: Add comments to your hosts file to remind yourself why you added an entry. Start a line with # to make it a comment:

# Local dev environment - WordPress site
127.0.0.1    mywordpresssite.local

Step 5: Save and Exit nano

When you're done making changes:

  1. Press Control + O (the letter O, not zero) to write/save the file
  2. Press Return/Enter to confirm the filename
  3. Press Control + X to exit nano

You'll be back at the standard Terminal prompt. The changes are saved.


Step 6: Flush the DNS Cache

This is the step that trips a lot of people up. After editing the hosts file, your Mac's DNS cache may still have the old mappings stored. You need to flush it to force your Mac to start using the new entries immediately.

In macOS Sequoia (and Sonoma, Ventura, Monterey), the command is:

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Press Return, enter your password if prompted, and you're done. Your new hosts file entries will take effect immediately — no restart required.

Note: You may also need to clear the cache in your specific browser. In Safari, go to Develop > Empty Caches. In Chrome, enter chrome://net-internals/#dns in the address bar and click "Clear host cache."


Step 7: Verify Your Changes Are Working

To confirm your hosts file changes are active, use the ping command in Terminal:

ping -c 1 myproject.local

If it resolves to the IP you set (like 127.0.0.1), your hosts file is working correctly. You can also use:

cat /private/etc/hosts

This prints the current contents of your hosts file so you can confirm your entries are there.


How to Undo Your Changes

If something isn't working right and you want to go back to the original hosts file, restore from your backup:

sudo cp ~/Documents/hosts-backup /private/etc/hosts

Then flush the DNS cache again:

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Your Mac will be back to its original configuration.


How to View Your Hosts File Without Editing

If you just want to see the current contents of the hosts file without making any changes, use:

cat /private/etc/hosts

Or for a more readable line-numbered view:

cat -n /private/etc/hosts

Using a GUI Instead of Terminal

If you'd rather not work in Terminal, there are a few free/paid apps that provide a graphical interface for editing the hosts file:

  • Hosts.prefpane — a free, open-source System Preferences pane for managing hosts entries
  • Gas Mask — a popular free app for managing multiple hosts file configurations and switching between them

These are especially handy if you regularly switch between different hosts configurations for different projects.


Quick Reference: All Commands at a Glance

Task Command
Back up hosts file sudo cp /private/etc/hosts ~/Documents/hosts-backup
Open hosts file for editing sudo nano /private/etc/hosts
Save in nano Control + O, then Return
Exit nano Control + X
Flush DNS cache sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
View current hosts file cat /private/etc/hosts
Restore backup sudo cp ~/Documents/hosts-backup /private/etc/hosts

Troubleshooting Common Issues

Changes aren't taking effect

Make sure you flushed the DNS cache after saving. Also clear your browser's cache — browsers often cache DNS independently. Try opening an incognito/private window to test.

"Permission denied" error

Make sure you're using sudo before the command. If you're not an administrator on the Mac, you won't be able to edit the hosts file.

I can't find the hosts file at /private/etc/hosts

/etc is a symlink to /private/etc on macOS — both paths point to the same file. Either one will work in Terminal commands.

My changes disappeared after a restart

This shouldn't happen normally. Check if any security software (like some VPN or parental control apps) is actively managing your hosts file and overwriting your changes.


Conclusion

Editing the hosts file in macOS Sequoia is a quick, safe process once you know the steps. The key things to remember: always back up first, use sudo nano to edit, and always flush your DNS cache afterward.

If you're doing regular local web development on your Mac, getting comfortable with the hosts file is well worth the few minutes it takes to learn. Pair it with a local development stack like MAMP or Laravel Herd and you have a powerful local development environment with zero cost.

Questions? Have a different approach you use for managing local domains? Leave a comment below — I'd love to hear how you're using the hosts file in your workflow.

Previously covered on this blog: Edit the Host File in Mac OS X Yosemite — this is the updated version for macOS Sequoia.