How to Reset the Hosts File to Default (Windows, Mac, Linux)
Reset and restore the hosts file to its default contents on Windows, macOS and Linux. Copy the exact default file, back up first, then flush DNS so the reset takes effect.
Locahl Team
Table of Contents
To reset the hosts file to default, replace its contents with the clean default for your OS, save it with admin rights, then flush DNS. This undoes any custom redirects β including adware/malware injections or broken entries β and restores normal domain resolution. Always make a quick backup first; the steps below cover Windows, macOS and Linux.
Back up the current file first (30 seconds)
# macOS / Linux
sudo cp /etc/hosts /etc/hosts.bak# Windows PowerShell (as administrator)
Copy-Item C:\Windows\System32\drivers\etc\hosts C:\Windows\System32\drivers\etc\hosts.bakIf anything you needed was in there, you can restore it from hosts.bak.
Reset the hosts file on Windows 10 and 11
1. Press Windows key, type Notepad, right-click it, choose Run as administrator. 2. File β Open, paste C:\Windows\System32\drivers\etc\hosts (set the filter to *All files*). 3. Select all, delete, and paste the Microsoft default:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost4. Save (Ctrl+S) and close. 5. Flush DNS so the change applies:
ipconfig /flushdnsOn Windows, localhost resolution is built in, so the loopback lines stay commented in the default. For editing methods and permission fixes, see edit the hosts file on Windows and edit the hosts file as administrator.
Reset the hosts file on macOS
Open Terminal and write the macOS default:
sudo tee /etc/hosts >/dev/null <<'EOF'
##
# 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
EOFThen flush the DNS cache:
sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponderMore context: edit the hosts file on Mac and flush DNS on Mac.
Reset the hosts file on Linux
sudo tee /etc/hosts >/dev/null <<'EOF'
127.0.0.1 localhost
127.0.1.1 $(hostname)
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
sudo resolvectl flush-cachesThe 127.0.1.1 <hostname> line is Debian/Ubuntu convention; keep your machine's hostname there. If a reset fails with "Operation not permitted," the file may carry the immutable flag β remove it with sudo chattr -i /etc/hosts, reset, then optionally restore it. See flush DNS on Linux.
Why reset the hosts file?
- Adware / malware cleanup β unwanted software often injects redirect lines (e.g. pointing antivirus or ad domains elsewhere). A reset wipes them.
- Undo broken edits β a malformed or forgotten custom line can send a real site to the wrong IP.
- Clean baseline β start troubleshooting from a known-good file.
- Restore localhost β if the loopback line was deleted, the default brings it back. Related: localhost refused to connect.
If unknown redirects pointed your bank, email, or antivirus domains somewhere unexpected, run a malware scan after resetting β see is editing the hosts file safe?.
Keep a clean hosts file without manual resets
Constantly nuking the file is a blunt tool. A hosts manager like Locahl keeps your default entries protected, lets you toggle custom domains on and off per project, and flushes DNS automatically β so you rarely need a full reset, and when you do, your real mappings are one click away.
_Last tested: June 2026 on Windows 11, macOS 26 Tahoe and Ubuntu 24.04._
Sources and further reading
- How to reset the Hosts file back to the default (Microsoft Support)
- The hosts file explained (Wikipedia)
- hosts(5) manual page (man7.org)
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
"The exact default contents for Windows 11 saved me β copy, paste, flush DNS, done. Sites resolve normally again."
June 21, 2026
"Adware had injected dozens of redirect lines. Restoring the default file cleaned it instantly."
June 20, 2026
"Clear and safe β I liked the backup step before resetting. A Linux immutable-flag note helped."
June 19, 2026
Frequently Asked Questions
What is the default hosts file?
A near-empty file containing only comments plus the loopback entries (127.0.0.1 localhost and ::1 localhost on most systems). Windows 10/11 ship it with comments only; macOS and Linux include the localhost lines.
How do I reset the hosts file on Windows?
Open Notepad as administrator, replace the contents of C:\Windows\System32\drivers\etc\hosts with the Microsoft default text, save, then run ipconfig /flushdns.
Will resetting the hosts file delete localhost?
No. The default already includes the localhost loopback entries. Resetting only removes the custom redirects you (or malware/adware) added.
Why would I reset my hosts file?
To undo broken or forgotten custom entries, remove adware/malware redirects, fix sites loading the wrong IP, or return a machine to a clean baseline before troubleshooting.
Do I need to flush DNS after resetting the hosts file?
Yes. The old entries can stay in the DNS cache. Flush DNS (ipconfig /flushdns, or the macOS/Linux command) so the reset takes effect immediately.
Related Articles
How to Edit the Host File (Windows, Mac & Linux)
Edit the host file on Windows, macOS and Linux: file location, admin rights, syntax, DNS flush, and troubleshooting when changes do not apply.
Locahl Team
How to Flush DNS Cache (Windows, Mac, Linux & Chrome)
How to flush or clear the DNS cache on Windows, Mac, Linux and Chrome. Copy the exact command for your system, learn what flushing DNS does and whether it is safe.
Locahl Team
Developer tools team
/etc/hosts Not Working? Fixes for Windows, Mac & Linux
The hosts file is ignored or /etc/hosts changes do not take effect? Fix it on Windows, Mac and Linux: flush DNS, check syntax, IPv6, line endings, resolver caches and save permissions.
Locahl Team
Developer tools team
Best Hosts File Editors for Windows (2026)
The best hosts file editors for Windows in 2026: Locahl, Notepad as admin, Hosts File Editor+, SwitchHosts and BlueLife Hosts Editor. Pros, cons and when to use each.
Locahl Team
Developer tools team
Clear DNS Cache in Microsoft Edge (2026)
Clear the DNS cache in Microsoft Edge with edge://net-internals/#dns, flush socket pools, and clear the Windows DNS cache so hosts changes take effect.
Locahl Team
Developer tools team