Locahl
Buy Locahl
hosts fileresetdefaultWindowsmacOSLinux

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.

L

Locahl Team

Β·4 min read

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)

BASH
# macOS / Linux
sudo cp /etc/hosts /etc/hosts.bak
POWERSHELL
# Windows PowerShell (as administrator)
Copy-Item C:\Windows\System32\drivers\etc\hosts C:\Windows\System32\drivers\etc\hosts.bak

If 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:

TEXT
# 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             localhost

4. Save (Ctrl+S) and close. 5. Flush DNS so the change applies:

TEXT
ipconfig /flushdns

On 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:

BASH
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
EOF

Then flush the DNS cache:

BASH
sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder

More context: edit the hosts file on Mac and flush DNS on Mac.

Reset the hosts file on Linux

BASH
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-caches

The 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

Also readHow to edit the hosts file (all platforms)
Also readIs editing the hosts file safe?
Share this article
Available on Windows, macOS & Linux

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
Buy Locahl β€” $11.99One-time payment, no subscription

Reader Reviews

4.7β˜…(3 reviews)
Erika M.
β˜…β˜…β˜…β˜…β˜…

"The exact default contents for Windows 11 saved me β€” copy, paste, flush DNS, done. Sites resolve normally again."

June 21, 2026

Daniel O.
β˜…β˜…β˜…β˜…β˜…

"Adware had injected dozens of redirect lines. Restoring the default file cleaned it instantly."

June 20, 2026

Lucia F.
β˜…β˜…β˜…β˜…β˜…

"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

10 min read
hosts fileWindowsmacOS

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.

L

Locahl Team

4 min read
DNSflush DNSclear DNS cache

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.

L

Locahl Team

Developer tools team

4 min read
hosts filetroubleshootingDNS

/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.

L

Locahl Team

Developer tools team

2 min read
hosts fileWindowseditors

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.

L

Locahl Team

Developer tools team

3 min read
DNSMicrosoft Edgecache

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.

L

Locahl Team

Developer tools team