How to Block Websites Using the Hosts File
📋 Article Contents
What is the Hosts File?
- Windows: C: \ Windows \ System32 \ drivers \ etc \ hosts
- Mac/Linux: / Etc / hosts
The file is protected by the system, so special permissions are required to edit it.
Step by Step: How to Block a Website
1Opening the File
For Windows:
- Right-click on the Start button (bottom left of the screen)
- Select “Windows PowerShell (Admin)” or “Terminal (Admin)” in Windows 11
- Type the following command and press Enter
For Mac/Linux:
- Open Terminal from Applications
- Type the following command and press Enter
You will be asked for your computer password. It is not displayed as you type, which is completely normal.
2Add the Website You Want to Block
At the end of the hosts file, add a new line for each website you want to block. The process is the same for all cases and does not change.
With this simple addition, your computer can no longer load the specific web pages, as it is redirected to the wrong address. The result is that the page does not open, even if you have an active internet connection.
example.com with the address of the website you want to block. It is important to also add the format with www and without, so that the blocking works correctly in all cases.
📌 Where exactly to add the lines
It is important to don't bother the lines that start with the symbol #. These lines act as system notes and explanations and do not affect the operation of the computer. Simply scroll down to the end of the file and add the new addresses you want to block there.
This way you ensure that no problems will be caused to the basic operation of the system and that your changes will be safe and easily reversible.
Example file before processing:
Example file after processing (with Facebook & YouTube excluded):
Once you're done adding the lines, simply save the file and close it. From that point on, the websites you've added to the list will no longer be able to open on that computer.
📌 Ready-made list for blocking popular social networking sites:
You can copy and paste these lines directly into the hosts file, without any additional setup or technical knowledge required.
With this method, every time you try to visit one of the above websites, your computer will prevent access. Usually, a message will appear saying that the page is unavailable or cannot be loaded, which indicates that the blocker is working properly.
3Saving and Applying Changes
- Save the file by clicking Ctrl + S in Windows or by pressing Ctrl + X and then Y on Mac or Linux.
- For the changes to take effect immediately, it is a good idea to clear your computer's cache by following the simple instructions below.
For Windows:
Type the following command in the PowerShell you already have open:
For Mac:
Type the command in Terminal:
For Linux:
💡 Tip: If the changes don't take effect immediately, try closing and reopening your browser. In rare cases, a computer restart solves the problem.
Advantages and disadvantages
✅ Advantages:
- Free and simple: No additional programs required
- It works everywhere: Applies to all browsers and applications
- Quick application: The results are visible almost immediately.
- No charge: Does not affect computer performance
- Full control: You choose which pages to block
❌ Disadvantages:
- Easy undo: Can be undone by an experienced user
- Per device: Must be done separately on each computer
- Limited coverage: Does not automatically block similar websites
- Manual management: The list needs updating from you.
- Possible restart: Sometimes a restart is required
Alternatives
If using the hosts file doesn't fully satisfy you, there are other easy-to-use ways to restrict or control access to websites.
🛡️ Router Settings
Through the router settings you can block websites for all devices of the home. It is an ideal solution for families and shared networks.
Advantage: Central control without additional settings on each device
🔧 Browser Add-ons
Additives such as BlockSite allow easy blocking, scheduling of times and quick activation or deactivation.
Advantage: Ideal for novice users
👨👩👧👦 Parental Control
Modern operating systems offer parental control tools for screen time and content filtering.
Advantage: Complete and organized control
🌐 Change DNS Server
Services such as Clean Browsing or OpenDNS Family Shield automatically block inappropriate content at the network level.
Advantage: Protection without installing apps
📝 summarizing
- Keep a backup before any change
- Add lines only at the end of the file
- Check if the blocking is working properly
- Combine solutions for better protection
(I.e. Last updated: December 2025
Loading comments...