Saturday 20 December 2025

Hosts file: How to modify it to block websites

YOU_PUT_THE_TITLE_OR_DESCRIPTION_HERE
Guide on how to edit the Hosts file and block websites

How to Block Websites Using the Hosts File

Do you want to block specific websites from your computer without installing any additional programs or applications? The hosts file is a built-in tool in your system that can help you achieve this in a simple and effective way. It does not require any technical knowledge and works on all major operating systems.

What is the Hosts File?

The hosts file is a small but very important file that exists on every computer. You can think of it as a simple “address book.” Every time you type a website into your browser, your computer first checks this file to see if there are any specific instructions.

In simpler terms: if you specify in the hosts file that a specific website, such as facebook.com, should point to the address 127.0.0.1 (i.e. to your own computer), then that page will not open normally. Thus, access to it is blocked before it even connects to the internet.

The important thing is that this check is always done first, before any other process. That's why the hosts file is a simple, reliable and permanent way to limit access to unwanted websites, without additional software and without burdening your computer.
Where is the hosts file located:
  • 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:

  1. Right-click on the Start button (bottom left of the screen)
  2. Select “Windows PowerShell (Admin)” or “Terminal (Admin)” in Windows 11
  3. Type the following command and press Enter
notepad C:\Windows\System32\drivers\etc\hosts
Opening the hosts file in Windows

For Mac/Linux:

  1. Open Terminal from Applications
  2. Type the following command and press Enter
sudo nano / etc / hosts

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.

127.0.0.1 example.com 127.0.0.1 www.example.com

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.

⚠️ Attention: Replace it 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

Hosts file

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:

# Copyright (c) Microsoft Corp. # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost

Example file after processing (with Facebook & YouTube excluded):

# Copyright (c) Microsoft Corp. # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost 127.0.0.1 facebook.com 127.0.0.1 www.facebook.com 127.0.0.1 youtube.com 127.0.0.1 www.youtube.com

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:

127.0.0.1 facebook.com 127.0.0.1 www.facebook.com 127.0.0.1 youtube.com 127.0.0.1 www.youtube.com 127.0.0.1 tiktok.com 127.0.0.1 www.tiktok.com 127.0.0.1 instagram.com 127.0.0.1 www.instagram.com 127.0.0.1 twitter.com 127.0.0.1 www.twitter.com 127.0.0.1 x.com 127.0.0.1 www.x.com

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

  1. Save the file by clicking Ctrl + S in Windows or by pressing Ctrl + X and then Y on Mac or Linux.
  2. 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:

ipconfig / flushdns

For Mac:

Type the command in Terminal:

sudo dscacheutil -flushcache; sudo killall -HUP mDNSReply

For Linux:

sudo systemd-resolve --flush-caches

💡 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

💡 Best Advice: Combining the hosts file with other solutions offers a more reliable result.

📝 summarizing

Editing the hosts file is a simple and cost-effective way to restrict access to unwanted websites. While it's not the most advanced solution, it's ideal for everyday users who want direct control without complicated settings.

Always remember:
  • 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

With this guide, you now have a clear and practical picture of how to control internet access. Good luck!

(I.e. Last updated: December 2025


Evangelos
✍️ Evangelos
Its creator LoveForTechnology.net — an independent and trusted source for tech guides, tools, and practical solutions. Each article is based on personal testing, evidence-based research, and care for the average user. Here, technology is presented simply and clearly.



RELATED TOPICS


⭐ Important Posts

 100% disk usage in windows:  STEP BY STEP

100% disk usage in Windows: How to fix the problem with one setting

 The best mobile browsers = Browsers

The best mobile browsers with low power consumption

💬 Comments

Share your thoughts

Loading comments...