Sleezr
Buy Sleezr
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.

S

Sleezr Team

Β·4 min read
How to Reset the Hosts File to Default (Windows, Mac, Linux)

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 Sleezr 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

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

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.

S

Sleezr Team

Developer tools team

10 min read
hosts fileWindowseditors

Best Hosts File Editors for Windows (2026 Comparison)

Compare the best Windows hosts file editors in 2026: Sleezr, PowerToys Hosts File Editor, HostsMan, SwitchHosts, and Notepad. Feature matrix, pros/cons, and who should switch.

S

Sleezr Team

Developer tools team

9 min read
terminalhosts fileGUI

Terminal vs GUI for Editing Hosts Files

Compare editing hosts files in Terminal vs a GUI app: permission issues, typo risks, backups, DNS flush and developer workflow speed.

S

Sleezr Team

10 min read
hosts filetroubleshootingmacOS

Hosts File Not Working on Mac: 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.

S

Sleezr Team

10 min read
hosts filemultiple environmentsproject management

Manage Multiple Hosts Files by Project

Manage hosts file configurations for dev, staging and production. Switch project setups, version configs and streamline team workflows.

S

Sleezr Team