guide · static export
Security

Block Ads System-Wide With the Hosts File

The hosts file resolves a domain to an address you choose. Point known ad servers at nothing and every program on the machine stops reaching them.

by@guidox updated:10/31/26 time:20 min level:Intermediate tested on:Windows 11 24H2 works on:Windows 10, Windows 11 tools:Admin rights, Text editor
TL;DR

Add lines of the form **0.0.0.0 domain.tld** to the hosts file in **drivers\tc**, keep a backup, and clear the DNS cache afterwards. It blocks by name only, so a hardcoded IP is unaffected.

Before you start

Requirements

  • Admin rights
  • A text editor
  • Twenty minutes
Step by step

Instructions

01

Find the file and copy it

The hosts file is a plain text file without an extension. Windows protects it, so copy it to the desktop, edit the copy and write it back.

%SystemRoot%\ystem32\rivers\tc\osts
02

Learn the format before adding lines

Each line starts with an address, then one or more names, separated by spaces. Comments start with a hash. A wrong separator turns the line into a comment or an error.

0.0.0.0 ads.example.com
tipUse 0.0.0.0 rather than 127.0.0.1 for ad hosts. A local web server otherwise answers the request and the page waits.
03

Add only what you can explain

A curated list of a few dozen domains is maintainable. A downloaded list with a hundred thousand entries slows every name lookup and breaks services you use.

⚠ warningBlocking a shared content domain takes the whole site with it. When a page stops loading images, check the list before blaming the browser.
04

Save with the right encoding

Notepad saves UTF-8 by default, which is fine. The file must keep the name hosts with no extension; a hosts.txt file is ignored completely.

05

Flush the DNS cache

Windows caches resolved names. Without a flush the new entries apply only after the cache expires, which looks like the edit did nothing.

ipconfig /flushdns
06

Keep the backup next to the file

A hosts file that breaks a sign-in page is a five-second fix with a backup. Store the original as hosts.bak and swap it back when something misbehaves.

copy hosts hosts.bak
Troubleshooting

Common issues

The file will not save

The editor is not elevated. Open it as administrator or edit a copy and copy it back.

Nothing is blocked

The file has an extension, the cache was not flushed, or the site uses a different domain.

A website broke

A shared content domain is on the list. Remove that line and flush again.

Everything is slow

A very large list. Cut it down to what you actually need.

FAQ

Frequently asked

Does this block ads inside apps?

Only if those apps use DNS names and do not fall back to hardcoded addresses.

Does it survive updates?

Yes. Windows does not reset the hosts file unless a third-party tool rewrites it.

How to undo this

Restore **hosts.bak** over the hosts file, or delete your added lines and run **ipconfig /flushdns**. All lookups return to normal.

Changelog · 1 entry
  1. 2026-10-31
    First version
Interactive version: checklist, feedback, related guides →

Free · no account needed · tracks your progress