Restore Original Hosts File Mac: Step-by-Step Fix
In this article
- What the Hosts File Does on macOS
- Why You Might Need to Restore It
- Before You Start: Backup Your Current File
- How to Restore the Default Hosts File (Terminal Method)
- 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
- Alternative: Replace the File with a Fresh Copy
- 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
- Common Problems and Troubleshooting
- Frequently Asked Questions
To restore the original hosts file on a Mac, you can either reset it to the default Apple entries or replace it with a backup you made earlier. The fastest method is to open Terminal and use a single command to overwrite the file with the default content, which removes any custom entries you or an app added.
What the Hosts File Does on macOS
The hosts file is a plain-text file that maps hostnames to IP addresses. When you type a URL or an app makes a network request, macOS checks this file before querying a DNS server. If the file contains an entry like 127.0.0.1 example.com, your Mac will connect to 127.0.0.1 (your own machine) instead of the real server. This is how many ad blockers, parental controls, and development tools work.
On modern macOS versions (Catalina and later), the hosts file lives at /etc/hosts. The system protects it with System Integrity Protection (SIP), so you need administrator privileges to edit it. The default file is minimal—it contains only a few lines of comments and two entries for localhost and broadcasthost. If you have never touched it, that is what you are restoring.
Why You Might Need to Restore It
You may need to restore the hosts file if you:
- Manually edited it to block websites or redirect domains and now want to undo those changes.
- Installed an app that modified the file (e.g., a VPN, ad blocker, or anti-malware tool) and you removed the app but the entries remain.
- Followed an online guide that told you to add entries, and now you want to revert to a clean state.
- Suspect malware or a misconfiguration is causing connection errors, and you want to rule out the hosts file as the culprit.
Restoring the file does not delete any apps or settings; it only removes the custom hostname-to-IP mappings. If you had entries for a specific purpose (like blocking telemetry), those will stop working after the reset.
Before You Start: Backup Your Current File
Even if you intend to restore the original, it is wise to back up the current file. You might later need to see what was changed, or you might want to reapply some entries. To create a backup, open Terminal and run:
cp /etc/hosts ~/Desktop/hosts.backup
This copies the file to your desktop. If you ever need to restore that backup, run sudo cp ~/Desktop/hosts.backup /etc/hosts. If you are confident you want the factory default, you can skip the backup, but keeping one costs nothing and can save you later.
How to Restore the Default Hosts File (Terminal Method)
The most reliable way is to use Terminal. Here are the steps:
- Open Terminal (from Applications > Utilities, or via Spotlight).
- Type the following command and press Enter. You will be prompted for your administrator password (it will not show as you type):
sudo nano /etc/hosts
- When the file opens in the
nanoeditor, delete everything and paste the default content below:##
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 fe80::1%lo0 localhost - Press
Control+Oto save, thenControl+Xto exit. - Flush the DNS cache so the changes take effect immediately. On recent macOS versions (Ventura, Sonoma, Sequoia), run:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
After this, your hosts file is back to the factory state. Test by visiting a site you previously blocked—it should load normally.
Alternative: Replace the File with a Fresh Copy
If you prefer not to edit manually, you can create a new file and replace the old one. In Terminal, run:
printf '##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 fe80::1%lo0 localhost ' | sudo tee /etc/hosts
This writes the default content directly. Then flush the DNS cache as above. This method is less prone to typos because you are not manually deleting lines.
Common Problems and Troubleshooting
- “Permission denied” when saving: You must use
sudoto edit the file. If you opened it with a text editor like TextEdit, you cannot save directly. Always use Terminal withsudo. - Changes don’t take effect: DNS caching can persist. Run the flush command again, or restart your Mac. Some apps (like browsers) may keep their own cache; try a private window or restart the app.
- You don’t know the original content: The default content is the same across all macOS versions from 10.4 onward. The lines with
::1andfe80::1%lo0are for IPv6 localhost. If you are on an older Mac, those lines are still correct. - You accidentally deleted the file: If you removed
/etc/hostsentirely, you can recreate it with the same command above. The system will use it immediately after creation. - Malware keeps re-adding entries: If you restore the file and it gets modified again, you likely have a persistent infection. Run a malware scan with a reputable tool and check your login items and launch agents.
Frequently Asked Questions
Does restoring the hosts file affect my internet speed?
No. The hosts file only maps a few hostnames. Removing custom entries means your Mac will use DNS for those domains, which is the normal behavior. You might see a tiny delay (milliseconds) for the first lookup, but it is not noticeable.
Will I lose my ad-blocking or parental controls?
If those features relied on hosts file entries, yes, they will stop working. However, most modern ad blockers use a different mechanism (like a local proxy or browser extension) and are unaffected. If you used a dedicated hosts-file-based blocker, you will need to re-add its entries or use an alternative.
Can I restore the hosts file without Terminal?
Yes, but it is more complicated. You can use Finder to navigate to /etc (press Command+Shift+G in Finder and type /etc), then copy the file to your desktop, edit it there, and drag it back. However, macOS will ask for an administrator password, and the process is error-prone. Terminal is the recommended method.
What if I don’t know what was in the original file?
The default content is standard and identical for all Macs. You can safely use the content provided in this article. If you had a backup from Time Machine, you can restore that instead, but the default is what you want for a clean state.
Is it safe to delete the hosts file entirely?
No. macOS expects the file to exist. If you delete it, some network services may fail or behave unpredictably. Always keep a file with at least the default entries. Recreate it immediately if you accidentally delete it.