Skip to content
How to Reset the Hosts File to Default (Windows, Mac, Linux)

How to Reset the Hosts File to Default (Windows, Mac, Linux)

Updated 7 min read

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.

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.

The default hosts file at a glance

SystemFile locationWhat the default contains
Windows 10 and 11C:\Windows\System32\drivers\etc\hostsMicrosoft comments only; localhost is resolved inside DNS itself
macOS/etc/hostslocalhost, broadcasthost and the IPv6 localhost line
Debian and Ubuntu/etc/hostslocalhost, a 127.0.1.1 line with your hostname, and IPv6 lines
Fedora and RHEL/etc/hostslocalhost with its localhost4 and localhost6 aliases

Anything beyond that is a custom entry: a project domain, an ad blocker, a VPN client, or something unwanted.

Back up the current file first (30 seconds)

# macOS / Linux
sudo cp /etc/hosts /etc/hosts.bak
How many times will you retype this command this month?Automate it with ToggleHosts
# 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.

See what you are about to remove

Before wiping the file, list the lines that are not comments, so you know which custom entries you will lose:

# macOS / Linux
grep -v '^#' /etc/hosts | grep -v '^$'
# Windows (Command Prompt)
findstr /v /b /c:"#" C:\Windows\System32\drivers\etc\hosts

On Windows this prints the lines that do not start with #, blank lines included. If you recognise a few of them as project entries, copy them somewhere safe and add them back after the reset.

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 localhost
  1. Save (Ctrl+S) and close.
  2. Flush DNS so the change applies:
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.

If Windows will not let you save the file

  • "Access is denied": Notepad was not started as administrator. Close it and reopen it with Run as administrator.
  • The file is read-only: some software sets the read-only attribute. Clear it from an elevated Command Prompt with attrib -r C:\Windows\System32\drivers\etc\hosts, then save again.
  • Security software reverts the change: antivirus tools and Controlled Folder Access can protect the file. Pause the protection briefly, save, then turn it back on.
  • The saved file is named hosts.txt: Notepad added an extension. Rename it to hosts with no extension, or choose All files in the save dialog.

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
EOF

Then flush the DNS cache:

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

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 heredoc is not quoted on purpose, so the shell fills in your hostname. 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.

On Fedora and RHEL-based systems the default is different:

sudo tee /etc/hosts >/dev/null <<'EOF'
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
EOF

Some environments rewrite the file on their own. WSL regenerates /etc/hosts at every start unless generateHosts = false is set under [network] in /etc/wsl.conf, and cloud images can manage it through cloud-init. If your reset does not survive a restart, check for one of those first.

Check that the reset worked

cat /etc/hosts
dscacheutil -q host -a name localhost
# Windows (Command Prompt)
type C:\Windows\System32\drivers\etc\hosts
ping -n 1 localhost

localhost should answer from 127.0.0.1 or ::1. If a site you cleaned still opens the wrong page, flush DNS again and restart the browser. If the page still opens wrong, look for another layer: a browser extension, a VPN, or a custom DNS setting.

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.

Entries that come back after a reset

A reset removes everything custom, but some software writes its own lines again:

  • Docker Desktop adds entries such as host.docker.internal and restores them when it starts. That is normal, not a sign the reset failed.
  • Ad blockers for desktop apps (for example patches for music players) and some VPN or privacy tools add blocking lines. If they return, uninstall or reconfigure that tool.
  • Malware and adware rewrite the file repeatedly. If unknown entries reappear after every reset, run a malware scan first.
  • WSL and cloud images regenerate /etc/hosts, as described above.

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 ToggleHosts 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. The best hosts file editors for Windows, Mac and Linux are compared side by side.

_Last tested: June 2026 on Windows 11, macOS 26 Tahoe and Ubuntu 24.04._

Sources and further reading

Frequently Asked Questions

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.

Open Notepad as administrator, replace the contents of C:\Windows\System32\drivers\etc\hosts with the Microsoft default text, save, then run ipconfig /flushdns.

No. The default already includes the localhost loopback entries. Resetting only removes the custom redirects you (or malware/adware) added.

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.

Related Articles

© 2026 ToggleHosts · All rights reserved[email protected]