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 April 4, 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 or 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 #

# 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:

Force Safesearch

You can use the hosts file to force Google Safesearch or Youtube restricted mode so that the user can't override the setting.

Google Safesearch

The host file can be used to force safesearch on some of the well known search engines.

Adding the following lines will trigger the safesearch mode on Google.

## Google Safe Search ##

Youtube Strict Mode

Force strict mode on Youtube by adding the following entries to your host file:

## Youtube Safe Search ##

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 to your blocklist will automatically block all versions of the domain (,, etc.).

Get Powerful DNS Filtering
Get Powerful DNS Filtering
Create and enforce a Content Policy 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.


# Blocked Sites #

# 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 #

# 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:

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 would redirect to 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