How to Block YouTube Using the Hosts File (Windows, Mac & Linux)
Editing the hosts file is the most popular free way to block YouTube on a single computer. This is the deep dive on that one method - to compare it against router blocks, Family Safety, and channel-level control, start with our complete guide to blocking YouTube on a child's computer.
What the Hosts File Actually Does
The hosts file is a plain text file on every computer that maps website names to IP addresses. Before your laptop asks the internet where youtube.com lives, it checks this file first. If you point youtube.com at 127.0.0.1 (your own computer), the browser tries to load YouTube from your machine, finds nothing, and the page fails to open.
That is the whole trick. No software to buy, no account to create, and it works in every browser on the computer at the same time. It works the same way on an HP laptop, a Lenovo laptop, a Dell, or a custom build, because the hosts file is part of the operating system, not the hardware.
How to Block YouTube in the Hosts File on Windows 11
- Click Start, type Notepad, right-click it, and choose Run as administrator. This step matters. If you open Notepad normally, you will not be able to save the file.
- In Notepad, choose File > Open and paste this into the filename box:
C:\Windows\System32\drivers\etc\hosts - Change the file type dropdown from "Text Documents" to All Files so the hosts file appears.
- Open it and add these lines at the very bottom:
127.0.0.1 youtube.com
127.0.0.1 www.youtube.com
127.0.0.1 m.youtube.com
127.0.0.1 youtu.be
127.0.0.1 youtube-nocookie.com
127.0.0.1 www.youtube-nocookie.com
- Save the file (Ctrl+S).
- Open Command Prompt and run
ipconfig /flushdnsso the change takes effect immediately.
This is the same process on a Windows 10, HP, Lenovo, or any other Windows laptop. The hosts file lives in the same place on all of them.
How to Block YouTube in the Hosts File on Mac
- Open Terminal (press Cmd+Space, type Terminal, press Enter).
- Type
sudo nano /etc/hostsand press Enter. - Enter your Mac password when asked (you will not see characters appear, that is normal).
- Use the arrow keys to move to the bottom and add the same six lines shown above.
- Press Ctrl+O then Enter to save, and Ctrl+X to exit.
- Run
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponderto apply it.
How to Block YouTube in the Hosts File on Linux
- Open a terminal.
- Type
sudo nano /etc/hosts. - Add the same six lines at the bottom.
- Save with Ctrl+O, exit with Ctrl+X. Most Linux distributions apply the change instantly.
How to Unblock YouTube Again
To reverse any of the above, open the hosts file the same way you did before, delete the lines you added, and save. On Windows, run ipconfig /flushdns again. On Mac, flush the cache again. YouTube will load normally within a few seconds.
This makes the hosts file a reasonable option for a temporary block. If you want YouTube gone during homework hours and back in the evening, you can add and remove the lines as needed, though doing that by hand every day gets old fast.
Why the Hosts File Is Not a Real Parental Control
The hosts file is a blunt instrument, and it has real weaknesses parents should know about before relying on it:
- It is easy to undo. Any child who can search "how to unblock a website" will find the hosts file in minutes. Editing it back takes thirty seconds.
- It only covers one computer. A blocked laptop does nothing to stop YouTube on a phone, tablet, or game console.
- It is all or nothing. YouTube is either completely gone or completely open. There is no middle ground for letting a child watch approved educational channels.
- Kids use workarounds. A VPN, a proxy site, or simply the YouTube mobile app sidesteps the hosts file entirely.
| Feature | Hosts File | Channel-Level Control |
|---|---|---|
| Cost | Free | Paid |
| Bypass difficulty | Very easy | Hard |
| Works across browsers | Yes | Yes |
| Allows approved content | No | Yes |
| Survives a curious kid | No | Yes |
A Better Approach: Approve Channels Instead of Blocking Everything
Most parents do not actually want to block YouTube entirely. They want to block the endless feed, the recommendations, and the random content, while still letting their child watch the science channels, the math tutorials, and the creators they have reviewed.
3Eyes does this by flipping the model. Instead of blacklisting YouTube, you approve specific channels from a parent dashboard. Your child browses and searches videos only within those approved channels through a built-in viewer. There is no recommendation feed and no rabbit hole, and the control cannot be undone by editing a text file. It also resists the usual bypass tricks that defeat the hosts file.
If you only need to block YouTube on one computer for a short time, the hosts file is a fine free tool. If you want something a determined kid cannot reverse in thirty seconds, channel-level control is the upgrade worth making.
Frequently asked questions
How do I block YouTube on Windows 10 with the hosts file? Exactly as shown above for Windows 11 - the hosts file lives at C:\Windows\System32\drivers\etc\hosts on both. Edit it as administrator and run ipconfig /flushdns.
Does the hosts file block the YouTube app? No. It only affects browser requests on that computer. The YouTube mobile app, smart-TV app, and any phone on cellular data are unaffected.
Why can my child still open YouTube after I edited the hosts file? Three common reasons: a browser with "secure DNS"/DNS-over-HTTPS turned on can route around it, they edited the file back, or they're using a different device. This is why the hosts file isn't a real parental control - see the full comparison of methods.
How do I unblock YouTube again? Reopen the hosts file the same way, delete the lines you added, save, and flush DNS. YouTube loads within seconds.