What Is a Hosts File? (And How It Blocks Websites)

Blog

What Is a Hosts File? (And How It Blocks Websites)

What is a hosts file? A local DNS override that blocks websites system-wide before public DNS runs. Paths, examples, pros, cons, and LockIn MCP automation.

Mil HoornaertMil Hoornaert · 8 min read

A hosts file is a plain-text file on your computer that maps domain names (like facebook.com) to IP addresses. Before your browser asks a public DNS server where a site lives, the operating system checks this local file first. If a domain is listed, your machine uses that address instead of looking it up on the internet — no browser extension, account, or subscription required. Tools like SelfControl, Pi-hole, and LockIn MCP all use this mechanism to keep distracting sites from loading.

How DNS resolution works vs. the hosts file

When you visit a website, your computer translates the domain name into a numeric IP address through DNS resolution. Normally the OS asks a DNS resolver — your router or a service like Cloudflare (1.1.1.1) — which returns the real server address. Only then does your browser connect.

The hosts file short-circuits that chain. It runs first in the lookup process. If facebook.com points to 0.0.0.0, the OS returns that address immediately — no public DNS query, no redirect. The page never loads.

Simple analogy

Public DNS is directory assistance: you call every time you need an address. The hosts file is a sticky note on your desk — if the name is already there, you never pick up the phone.

That is system-level blocking: it affects Chrome, Firefox, Safari, Slack, and most desktop apps. A browser extension controls one browser; a hosts entry controls the whole machine.

Where the hosts file lives on Windows, macOS, and Linux

Every major desktop operating system ships with a hosts file in a fixed location. You need administrator or root privileges to edit it, which is intentional — a modified hosts file can redirect banking sites or block security updates if misused.

Operating systemPathHow to edit
Windows 10 / 11C:\Windows\System32\drivers\etc\hostsOpen Notepad as Administrator, then File → Open that path
macOS/etc/hostsTerminal: sudo nano /etc/hosts
Linux/etc/hostsTerminal: sudo nano /etc/hosts (or your preferred editor)

After saving changes, flush the DNS cache: ipconfig /flushdns on Windows, or sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder on macOS. LockIn MCP and other blockers edit these same paths programmatically.

Example hosts file entries for blocking websites

Each line in a hosts file follows a simple format: an IP address, whitespace, then one or more hostnames. Lines starting with # are comments. To block a site, point its domain at an address that goes nowhere — typically 0.0.0.0 or 127.0.0.1 (localhost).

# Block social media during focus work
0.0.0.0 facebook.com
0.0.0.0 www.facebook.com
0.0.0.0 twitter.com
0.0.0.0 x.com
0.0.0.0 www.x.com
0.0.0.0 youtube.com
0.0.0.0 www.youtube.com
0.0.0.0 reddit.com
0.0.0.0 www.reddit.com

List both the bare domain and the www variant — browsers may request either. Some blockers also add mobile subdomains like m.facebook.com. Missing a subdomain is a common reason a block fails. Either 0.0.0.0 or 127.0.0.1 works; most guides prefer 0.0.0.0 because it points to no usable address rather than your own machine.

Pros of using a hosts file to block websites

  • System-wide coverage — Blocks apply to every browser and most desktop apps, not just the one where you installed an extension.
  • No browser extension needed — Nothing to pin, update, or disable in a moment of weakness inside Chrome's toolbar.
  • Works offline — Blocks are local; no cloud blocklist or VPN required.
  • Zero ongoing cost — Built into the OS. Free tools like SelfControl use it; LockIn MCP automates it.
  • Persistent across reboots — Entries stay until you remove them.

Switching browsers or opening a private window won't bypass a hosts block — the domain simply doesn't resolve to the real server. For developers and writers whose distractions are YouTube, X, or Reddit during deep work, that removes the easiest escape hatches.

Cons and limitations you should know

  • Manual editing is tedious — Adding dozens of domains by hand, keeping subdomains in sync, and removing blocks later is error-prone.
  • Administrator access required — Every edit needs elevated permissions. Corporate-locked machines may block changes entirely.
  • Bypassable by savvy users — Anyone with admin access can edit the file and undo blocks, or route traffic through a VPN.
  • No scheduling built in — Blocks stay on until you edit the file again.
  • Mobile gap — iOS and stock Android don't expose hosts the way desktop OSes do.

These tradeoffs explain why many people start with a manual hosts edit, hit the maintenance wall within a week, and look for automation. The mechanism is sound; raw file editing is what breaks long-term habits — especially when you need timed sessions or quick unblocks.

How LockIn MCP automates hosts blocking via MCP

LockIn MCP is an MCP (Model Context Protocol) server that manages your hosts file for you. Install with npx -y lockin-mcp install, pick domains in a guided setup, and connect your AI assistant (Poke, Claude Desktop, ChatGPT, or any MCP client). Focus blocking becomes a conversation instead of a manual edit.

Say "block YouTube and Reddit for two hours" and your assistant calls enter_focus_mode or block_domains. LockIn writes the entries with correct permissions, covers www variants, and can auto re-block after a timed break via temporarily_unblock_domains. Check active blocks with get_block_status. Same hosts mechanism — without opening a terminal each session.

  • block_domains — Add custom domains to the hosts file immediately
  • enter_focus_mode — One-shot block of common distraction sites for a focus session
  • temporarily_unblock_domains — Timed access that re-blocks automatically
  • unblock_domains — Remove specific blocks when the session ends
  • get_block_status — See current blocks and system readiness

Blocks survive browser restarts on macOS, Windows, and Linux. A background service keeps temp-unblock timers running so a timed break actually re-blocks when it should. See the LockIn MCP how-it-works page for install, licensing, and MCP connection details.

Ready to go deeper? These guides build on the concepts above — including platform-specific steps and how LockIn fits into an AI productivity stack:

Bottom line

The hosts file is your computer's local DNS override. Point distracting sites at 0.0.0.0 and they stop loading everywhere on that machine — free, fast, and system-wide. Manual upkeep and admin rights make raw editing painful for daily use; LockIn MCP automates the same layer through MCP so your AI assistant can start and end focus blocks without touching the file.

Keep reading