Block Websites

How to use the hosts file to Block Adult Websites

Quickly block thousands of websites for free using the computers hosts file. This is one of the easiest and free ways to block porn on PC.

techlockdown logo
Tech Lockdown Team
|
Updated July 31, 2024

Quickly block thousands of websites for free using the computers hosts file. This is one of the easiest and free ways to  block porn on PC .

Blocking websites using the hosts file is a fairly straightforward process that involves adding a line to the file containing an IP address like 0.0.0.0 or 127.0.0.1 and then the website you want to block (separated by space). The process is the same on Windows and Mac.

For example, you can block websites like Youtube and Facebook by adding the following lines to your hosts file:

# Blocked Sites #

0.0.0.0 www.youtube.com
0.0.0.0 youtube.com
0.0.0.0 www.facebook.com
0.0.0.0 facebook.com

# End Blocked Sites #

Using lists to block thousands of websites

Social media websites like Youtube, Facebook, and Reddit use other web addresses to function properly. If you want to thoroughly block those websites, including any websites that "mirror" them using API services, you should use blocklists.

Additionally, you can block entire categories of websites, such as VPNs & Proxies, services that invade your privacy, and pornographic content.

If you want to block categories like Adult Content on MacBook or windows computers, you can copy/paste the entries from these sources into your hosts file:

Hosts file entries for Enabling SafeSearch

Below are the safe search hosts file entries for search engines with a safe search feature. Copy/paste into your hosts file to enforce safe search on all browsers.

# Google SafeSearch
216.239.38.120 google.com
216.239.38.120 www.google.com
216.239.38.120 google.co.uk
216.239.38.120 www.google.co.uk

# Bing SafeSearch
204.79.197.220 www.bing.com
204.79.197.220 bing.com

# DuckDuckGo SafeSearch
52.149.247.1 duckduckgo.com

# Yahoo SafeSearch
98.137.11.163 search.yahoo.com
98.137.11.163 www.search.yahoo.com

# Yandex SafeSearch
77.88.55.80 yandex.com
77.88.55.80 www.yandex.com

## Youtube Safe Search ##
216.239.38.119 www.youtube.com
216.239.38.119 m.youtube.com
216.239.38.119 youtubei.googleapis.com
216.239.38.119 youtube.googleapis.com
216.239.38.119 www.youtube-nocookie.com

It's easier to block websites and categories and enforce safe search with a DNS Filtering service.

You can install a DNS filter directly on your Windows or Mac computer and also on your home router so that all devices on your home internet inherit the same blocking settings.

For example, with the Tech Lockdown DNS Filter, you can select the "Search Engines & Portals" category, which will force safesearch on all search engines that support safesearch. If a search engine doesn't have a safesearch feature, the filter blocks it entirely.

Additionally, you don't have to manually block each variation of a website. Adding facebook.com to your blocklist will automatically block all versions of the domain (www.facebook.com, mobile.facebook.com, etc.).

Create a DNS Content Policy
Create a DNS Content Policy
Enforce content filtering rules on all your devices.

Edit Hosts file on Windows

Open Notepad as an administrator. If you don't open it as an administrator, you won't be able to save the file.

Example:

# Blocked Sites #

0.0.0.0 blockthiswebsite.com

# End Blocked Sites #

Save the file, then flush your DNS.

Flush DNS on Windows

Edit Hosts file on Mac

Scroll to the bottom of the file and add a comment (comments start with a #).

# Blocked Sites #

0.0.0.0 blockthiswebsite.com

# End Blocked Sites #

After adding the desired host entries, press ctrl+x and then shift+y to save changes. Then, flush your DNS.  

Flush DNS on Mac

If you haven't already, use finder to open terminal again.

sudo killall -HUP mDNSResponder

Ban Porn from your Life

Get access to blocking techniques that actually work

Frequently Asked Questions

Do host file entries need a www at the beginning?

In some of the example host file entries, there are two entries for one website like this:

facebook.com
www.facebook.com

Host file entries block an exact match, which is different from DNS Filtering, which will also block subdomains (like www) if a root domain is blocked. Usually, an entry with the root domain without www is enough, so you shouldn't need two entries.

However, some sites might function if the www version is accessed directly. That is why some host file entries block both versions. 

Usually, the root domain without www is what a website resolves to. In some cases, a website might resolve to the www. version, and accessing domain.com would redirect to www.domain.com. If you block the root domain and your DNS cache is cleared, that redirect to the www version won't be able to occur in the first place. You would have to browse to the www URL directly. Even in this case, most internal URLs wouldn't use the www version, so the website likely wouldn't function properly.

This is a long-winded way of saying: it is not worth the effort and performance drawbacks of duplicating every entry in the host file.

Open chat