How to Block Ads System-Wide on Mac Without an App

You don't need an app to block ads in every program on your Mac. The hosts file, built into macOS, can send known ad, tracker and malware domains nowhere. The most widely used list is Steven Black's unified hosts file (free, MIT licence; the adware + malware version listed about 73,600 entries on 17 Oct 2026). Here's how to install it by hand in about five minutes, and how to undo it.

The Terminal way
Free · 5 minutes

1. Back up your current hosts file

sudo cp /etc/hosts /etc/hosts.backup

2. Download the unified hosts file

curl -fsSL https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts -o ~/Downloads/hosts-stevenblack

Open it in a text editor and skim it first. It's plain text: one 0.0.0.0 domain per line. If you had custom lines in your old file (local dev domains, for example), paste them at the top.

3. Install it

sudo cp ~/Downloads/hosts-stevenblack /etc/hosts

4. Flush the DNS cache

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

5. Check it worked

ping -c1 doubleclick.net

It should show 0.0.0.0. To undo everything: sudo cp /etc/hosts.backup /etc/hosts, then flush DNS again.

Pros
  • ✓
    Free, nothing installed
  • ✓
    Works in every app, not just browsers
  • ✓
    Works on any network, with no hardware
Cons
  • ✗
    Updating means repeating the steps
  • ✗
    One list at a time; mixing lists is manual
  • ✗
    A bad edit can break name resolution

What hosts blocking can't do

The one-click way: SaneHosts
$14.99 One-Time

The same lists, with no Terminal. SaneHosts includes Steven Black's lists alongside Hagezi, AdGuard and 200+ others, grouped into five protection levels. It adds profiles, Touch ID or password approval for each change, automatic backups and automatic DNS flush. SaneHosts is listed in the Steven Black README's third-party tools.

Start the 14-day trial

macOS 14 (Sonoma) or later. No credit card for the trial.

Questions people ask

How do I block ads system-wide on a Mac without installing an app?

Replace your /etc/hosts file with a blocklist hosts file such as Steven Black's unified hosts (adware + malware, about 73,600 entries), then flush the DNS cache. Every app on the Mac then skips those domains. The Terminal steps are on this page.

Where is the hosts file on a Mac?

It's at /etc/hosts. On current macOS, /etc points to /private/etc, so the real file is /private/etc/hosts. Editing either path changes the same file.

How do I flush the DNS cache on a Mac?

Run: sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

How do I undo it?

Copy your backup back over the file (sudo cp /etc/hosts.backup /etc/hosts) and flush DNS again. That's why the first step on this page is making a backup.

How do I keep the blocklist up to date?

Steven Black's lists are rebuilt often. By hand, you repeat the download step. SaneHosts can import the same lists by URL and offers them as one-click protection levels.