Why Your Hosts File Changes Disappear After Reboot (and How to Fix It)
Hosts file changes gone after restarting Mac? Learn why macOS resets hosts file, how System Integrity Protection (SIP) affects it, daemon configurations, and backup strategies to persist your changes.
Locahl Team
Table of Contents
- Understanding hosts file persistence
- Reason #1: macOS system updates
- When updates reset hosts file
- Why it happens
- Solution: Backup before updates
- Prevention strategy
- Reason #2: System Integrity Protection (SIP) repairs
- When SIP resets files
- Check SIP status
- Verify file integrity
- Solution: Ensure correct permissions
- If SIP keeps resetting
- Reason #3: Time Machine restoration
- When Time Machine restores
- Check Time Machine status
- Solution: Exclude hosts file from restoration
- Manual restoration prevention
- Reason #4: Third-party security software
- Common culprits
- Check for security software
- Solution: Configure security software
- Reason #5: Daemon or service overwriting
- Check for modifying processes
- Common daemons to check
- Solution: Identify the culprit
- Fix daemon issues
- Reason #6: File system issues
- Check disk health
- Use Disk Utility
- Solution: Repair file system
- Reason #7: Manual accidental reset
- Common scenarios
- Solution: Track changes
- Complete persistence strategy
- Layer 1: Regular backups
- Layer 2: Version control
- Layer 3: Documentation
- Layer 4: Use hosts file manager
- Recovery: Restoring lost entries
- Step 1: Find your backup
- Step 2: Restore from backup
- Step 3: Verify and flush DNS
- Step 4: Verify permissions
- Prevention checklist
- Advanced: Monitoring and alerts
- File change monitoring script
- Troubleshooting specific scenarios
- Scenario 1: Changes disappear every reboot
- Scenario 2: Changes disappear after macOS update
- Scenario 3: Random resets with no pattern
- Best practices summary
- Conclusion
You spent time carefully configuring your hosts file, adding all your local development domains, testing everything works perfectly. Then you restart your Mac, and... everything is gone. Your hosts file is back to its default state, all your entries vanished. Sound familiar?
This frustrating scenario is more common than you might think. In this comprehensive guide, we'll explore every reason why your hosts file changes might disappear after a reboot, and provide practical solutions to ensure your configurations persist.
Understanding hosts file persistence
First, let's clarify something important: Under normal circumstances, macOS does NOT automatically reset your hosts file. The /etc/hosts file should persist across reboots just like any other system file. If your changes are disappearing, something specific is causing it.
Simplify your hosts file management
Locahl lets you manage your hosts file visually, without touching the terminal. Automatic DNS flush, multiple environments, and backups included.
Reason #1: macOS system updates
The most common cause of hosts file resets is macOS system updates. During major updates, macOS can restore system files to their default state.
When updates reset hosts file
- Major macOS updates (e.g., Ventura → Sonoma)
- Security updates that modify system files
- System file repairs during update process
Why it happens
macOS updates sometimes: 1. Verify system file integrity 2. Restore files to known-good state 3. Overwrite modified system files
The hosts file, being in /etc (system directory), can be affected.
Solution: Backup before updates
Before any macOS update:
# Create timestamped backup
sudo cp /etc/hosts /etc/hosts.backup.$(date +%Y%m%d)
# Also backup to safe location
sudo cp /etc/hosts ~/hosts-backup-$(date +%Y%m%d).txtAfter update, restore if needed:
# Check if hosts file was reset
diff /etc/hosts ~/hosts-backup-20260206.txt
# Restore if needed
sudo cp ~/hosts-backup-20260206.txt /etc/hosts
sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponderPrevention strategy
1. Always backup before updates 2. Document your entries in a separate file 3. Use version control for hosts configurations 4. Automate backups with scripts or tools
Reason #2: System Integrity Protection (SIP) repairs
System Integrity Protection can repair system files if it detects corruption or unauthorized modifications.
When SIP resets files
SIP might restore /etc/hosts if:
- File permissions are incorrect
- File ownership is wrong
- File integrity check fails
- System detects tampering
Check SIP status
csrutil statusShould show: System Integrity Protection status: enabled.
Verify file integrity
Check if macOS thinks your hosts file is corrupted:
# Check file permissions
ls -la /etc/hosts
# Should show:
# -rw-r--r-- 1 root wheel /etc/hostsSolution: Ensure correct permissions
SIP is less likely to reset files with correct permissions:
# Set correct ownership
sudo chown root:wheel /etc/hosts
# Set correct permissions
sudo chmod 644 /etc/hosts
# Verify
ls -la /etc/hostsIf SIP keeps resetting
If SIP repeatedly resets your hosts file:
1. Check system logs for SIP actions: ``bash log show --predicate 'eventMessage contains "hosts"' --last 24h ``
2. Verify no malware is modifying the file 3. Check for conflicting software that might trigger SIP
Reason #3: Time Machine restoration
If Time Machine is backing up your system, it might restore the hosts file from a previous backup.
When Time Machine restores
- Automatic restoration after system issues
- Manual restoration of system files
- Migration Assistant restoring from backup
Check Time Machine status
tmutil listbackupsSolution: Exclude hosts file from restoration
Prevent Time Machine from restoring hosts file:
1. Open System Preferences > Time Machine 2. Click Options 3. Add /etc/hosts to exclusion list
Or use Terminal:
sudo tmutil addexclusion /etc/hostsVerify exclusion:
tmutil isexcluded /etc/hostsManual restoration prevention
When restoring from Time Machine:
- Don't restore system files unless necessary
- Restore hosts file separately after system restoration
- Keep manual backup outside Time Machine
Reason #4: Third-party security software
Antivirus, firewall, or security software might reset the hosts file as a security measure.
Common culprits
- Antivirus software detecting hosts file modifications
- Firewall applications resetting network configs
- Security suites protecting system files
- MDM (Mobile Device Management) policies
Check for security software
# List running processes
ps aux | grep -i "antivirus|security|firewall"
# Check installed profiles
profiles -PSolution: Configure security software
For each security application:
1. Add exception for /etc/hosts 2. Disable system file protection for hosts file 3. Whitelist hosts file modifications 4. Check logs to see if it's resetting the file
Example - Check if software modified hosts:
# Check file modification time
ls -la /etc/hosts
# Compare with your last edit time
# If modification time is recent but you didn't edit, something else didReason #5: Daemon or service overwriting
Some system daemons or services might overwrite the hosts file.
Check for modifying processes
# Monitor file changes
sudo fs_usage -f filesys | grep hostsThis shows processes accessing the hosts file in real-time.
Common daemons to check
- mDNSResponder: Handles DNS, shouldn't modify hosts file
- configd: Network configuration daemon
- networksetup: Network configuration tool
Solution: Identify the culprit
Monitor file access:
# In one terminal, monitor
sudo fs_usage -w -f filesys | grep "/etc/hosts"
# In another terminal, trigger the issue (reboot, etc.)
# Watch which process modifies the fileCheck launch daemons:
# List all launch daemons
launchctl list | grep -i "network|dns|host"
# Check specific daemon
launchctl list com.apple.mDNSResponderFix daemon issues
If a daemon is overwriting hosts file:
1. Check daemon configuration: ``bash cat /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist ``
2. Restart the daemon: ``bash sudo launchctl kickstart -k system/com.apple.mDNSResponder ``
3. Report the issue if it's an Apple daemon (likely a bug)
Reason #6: File system issues
Corrupted file system or disk errors can cause file resets.
Check disk health
# Check disk
diskutil verifyVolume /
# Repair if needed (in Recovery Mode)
diskutil repairVolume /Use Disk Utility
1. Open Disk Utility 2. Select your disk 3. Click First Aid 4. Click Run
Solution: Repair file system
If disk errors are found:
1. Backup your data 2. Boot to Recovery Mode (hold Cmd+R during startup) 3. Run First Aid from Disk Utility 4. Restore hosts file from backup after repair
Reason #7: Manual accidental reset
Sometimes the reset isn't automatic—you or someone else might have reset it.
Common scenarios
- System Preferences > Network > Advanced > DNS changes
- Terminal commands that modify /etc/hosts
- GUI tools resetting to default
- Scripts overwriting the file
Solution: Track changes
Enable file monitoring:
# Install fswatch (via Homebrew)
brew install fswatch
# Monitor hosts file
fswatch /etc/hosts | while read f; do
echo "Hosts file changed at $(date)"
ls -la /etc/hosts
doneCheck modification history:
# Check when file was last modified
stat -f "%Sm" -t "%Y-%m-%d %H:%M:%S" /etc/hosts
# Compare with your memory of when you edited itComplete persistence strategy
To ensure your hosts file changes never disappear, implement this multi-layered approach:
Layer 1: Regular backups
Automated backup script:
#!/bin/bash
# ~/scripts/backup-hosts.sh
BACKUP_DIR="$HOME/hosts-backups"
mkdir -p "$BACKUP_DIR"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="$BACKUP_DIR/hosts-$TIMESTAMP.txt"
sudo cp /etc/hosts "$BACKUP_FILE"
sudo chown $(whoami) "$BACKUP_FILE"
echo "Backed up to: $BACKUP_FILE"
# Keep only last 30 backups
cd "$BACKUP_DIR"
ls -t hosts-*.txt | tail -n +31 | xargs rm -fRun automatically:
Add to crontab (runs daily):
crontab -e
# Add this line:
0 2 * * * /Users/yourname/scripts/backup-hosts.shLayer 2: Version control
Store hosts configurations in Git:
# Initialize repo
mkdir ~/hosts-config
cd ~/hosts-config
git init
# Copy current hosts file
sudo cp /etc/hosts ./hosts.current
sudo chown $(whoami) ./hosts.current
# Commit
git add hosts.current
git commit -m "Initial hosts file backup"After each edit:
cd ~/hosts-config
sudo cp /etc/hosts ./hosts.current
sudo chown $(whoami) ./hosts.current
git add hosts.current
git commit -m "Updated hosts file $(date +%Y-%m-%d)"
git push # If using remote repoLayer 3: Documentation
Keep a separate documented file:
# ~/hosts-entries.txt
cat > ~/hosts-entries.txt << 'EOF'
# My Hosts File Entries
# Last updated: 2026-02-06
# Project Alpha - Development
127.0.0.1 alpha.local
127.0.0.1 api.alpha.local
# Project Beta - Development
127.0.0.1 beta.local
EOFLayer 4: Use hosts file manager
GUI tools like Locahl provide:
- Automatic backups before each edit
- Version history of all changes
- Export/import for easy restoration
- Cloud sync (if supported)
Recovery: Restoring lost entries
If your hosts file was reset, here's how to recover:
Step 1: Find your backup
# Check backup directory
ls -la ~/hosts-backups/
# Or check Time Machine
tmutil listbackupsStep 2: Restore from backup
# Restore from manual backup
sudo cp ~/hosts-backups/hosts-20260206_103000.txt /etc/hosts
# Or restore from Time Machine (if available)
sudo tmutil restore /etc/hostsStep 3: Verify and flush DNS
# Verify contents
cat /etc/hosts
# Flush DNS cache
sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder
# Test
ping yourdomain.localStep 4: Verify permissions
# Ensure correct permissions
sudo chown root:wheel /etc/hosts
sudo chmod 644 /etc/hostsPrevention checklist
Before any operation that might reset your hosts file:
- [ ] Backup hosts file to safe location
- [ ] Document entries in separate file
- [ ] Commit to version control if using Git
- [ ] Check Time Machine exclusion settings
- [ ] Verify security software won't interfere
- [ ] Test backup restoration process
- [ ] Note modification time before operation
Advanced: Monitoring and alerts
Set up monitoring to detect when hosts file is reset:
File change monitoring script
#!/bin/bash
# ~/scripts/monitor-hosts.sh
LAST_CHECKSUM=$(md5 -q /etc/hosts 2>/dev/null)
while true; do
sleep 60 # Check every minute
CURRENT_CHECKSUM=$(md5 -q /etc/hosts 2>/dev/null)
if [ "$LAST_CHECKSUM" != "$CURRENT_CHECKSUM" ]; then
echo "ALERT: Hosts file changed at $(date)"
echo "Previous: $LAST_CHECKSUM"
echo "Current: $CURRENT_CHECKSUM"
# Send notification (requires terminal-notifier)
# terminal-notifier -message "Hosts file was modified!"
LAST_CHECKSUM=$CURRENT_CHECKSUM
fi
doneTroubleshooting specific scenarios
Scenario 1: Changes disappear every reboot
Check: 1. Security software resetting file 2. Launch daemon overwriting 3. File system issues 4. Time Machine auto-restore
Solution: Implement backup strategy and identify the resetting process.
Scenario 2: Changes disappear after macOS update
Expected behavior - Always backup before updates.
Solution: Restore from backup after update completes.
Scenario 3: Random resets with no pattern
Check: 1. File monitoring to identify trigger 2. System logs for clues 3. Security software logs 4. Disk health
Solution: Monitor file access and identify the culprit.
Best practices summary
1. Always backup before major operations 2. Use version control for configurations 3. Document entries separately 4. Monitor file changes if resets occur 5. Verify permissions are correct 6. Exclude from Time Machine if needed 7. Use hosts file manager with auto-backup 8. Test restoration process regularly
Conclusion
Hosts file changes disappearing after reboot is frustrating, but preventable. The most common causes are macOS updates, Time Machine restorations, security software, or daemon overwrites. By implementing a robust backup strategy and understanding what can reset your file, you can ensure your configurations persist.
Remember: Backup regularly, document your entries, and monitor for unexpected changes. With these practices, you'll never lose your hosts file configuration again.
For the easiest experience with automatic backups, version history, and easy restoration, consider using Locahl (€9.99). It handles all the complexity of hosts file management, ensuring your changes are always safe and easily recoverable.
If you're experiencing persistent issues, check our hosts file troubleshooting guide or learn about fixing permission issues that might be related.
Ready to simplify your workflow?
Stop wasting time with the terminal. Locahl lets you manage your hosts file in a few clicks, with automatic validation and no risk of errors.
- Intuitive visual interface
- Automatic DNS flush
- Multi-environment management
- Automatic backups
- JSON Import/Export
Reader Reviews
"This explained everything! I had no idea macOS could reset the hosts file. The backup strategy section is gold."
February 6, 2026
"Finally found the answer! The daemon configuration section solved my persistent issue. Great troubleshooting guide."
February 6, 2026
"Very helpful! Would have liked more information about macOS updates specifically resetting hosts file, but covers the main scenarios well."
February 6, 2026
Frequently Asked Questions
Why do my hosts file changes disappear after rebooting Mac?
macOS can reset the hosts file during system updates, when System Integrity Protection (SIP) repairs system files, or if certain daemons overwrite it. The file might also be restored from a Time Machine backup or reset by security software. Always backup your hosts file before major updates.
How do I prevent hosts file from being reset after reboot?
Create regular backups of your hosts file, verify file permissions are correct (644, owned by root:wheel), and avoid disabling System Integrity Protection. Use a hosts file manager that automatically backs up configurations. Check for daemons or security software that might be overwriting the file.
Does macOS automatically reset hosts file?
macOS doesn't automatically reset /etc/hosts under normal circumstances. However, system updates, SIP repairs, Time Machine restorations, or third-party security software can restore the file to a previous state. Always backup before major operations.
Can System Integrity Protection reset hosts file?
SIP can repair system files if it detects corruption, but it shouldn't reset /etc/hosts during normal operation. If SIP is resetting your hosts file, there may be a deeper system issue. Check SIP status with csrutil status and verify file integrity.
How do I backup my hosts file?
Create a timestamped backup: sudo cp /etc/hosts /etc/hosts.backup.$(date +%Y%m%d). Store backups in a safe location like ~/hosts-backups/. Use a hosts file manager like Locahl that automatically creates backups before each edit.
What should I do if hosts file keeps resetting?
Check for security software that might be overwriting it, verify no daemons are modifying /etc/hosts, ensure file permissions are correct, and check System Integrity Protection status. Consider using a hosts file manager with automatic backup and restore features.
Related Articles
Hosts File Not Working After Edit on Mac: Complete Fix Guide
Your hosts file changes not taking effect? Learn how to fix DNS cache issues, browser cache, file permissions, syntax errors, and encoding problems on macOS.
Locahl Team
Hosts File Permission Denied on Mac: Every Fix Explained
Getting "permission denied" when editing hosts file? Learn how to fix sudo access, System Integrity Protection (SIP), file ownership, chmod permissions, and disk permissions on macOS.
Locahl Team
Terminal vs GUI: Why Developers Are Switching to Hosts File Apps
Compare editing hosts file via Terminal vs using Locahl GUI. Learn about permission issues, typo risks, backups, DNS flush, and why GUI hosts file managers are better for developers.
Locahl Team