How to use the hosts file to Block Adult Websites

Ben Bozzay
February 9, 2022
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 #
Note that you should include a line blocking the website with the www
prefix and version without www
.
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:
- Host file blocklists for Adult Content websites
- Social Media Host File Entries
- Trackers and Privacy Host File Entries

Members Only Blocklist Generator
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.
Force 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 ##
216.239.38.120 google.com
216.239.38.120 www.google.com
Force Youtube Strict Mode
Force strict mode on Youtube by adding the following entries to your host file:
## 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
How to configure the Windows 10 Hosts file
Open Notepad as an administrator. If you don't open it as an administrator, you won't be able to save the file.

In notepad, click file > Open, then navigate to C:\Windows\System32\drivers\etc

Select "all files" then open the hosts file.

Scroll to the bottom of the file and add a comment (comments start with a #
).
Example:
# Blocked Sites #
0.0.0.0 blockthiswebsite.com
# End Blocked Sites #
Save the file, then flush your DNS.
Restrict Access to your Hosts File
How to Flush DNS on Windows
On windows machines, open command prompt. Type "CMD" into your search bar and then open it.

Type ipconfig /flushdns
then press enter.

How to configure the Mac Hosts File
Use finder to open Terminal
Type sudo nano /etc/hosts
then press return. Enter your Macbook's password (must be an admin) when prompted and press return.

Use your arrow keys to scroll down the file. The mouse and keyboard don't work as you might expect when using terminal/nano.

Scroll to the bottom of the file and add a comment (comments start with a #
).
Example:
# 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.
Purge Porn From Your Life.
How to Flush DNS on Mac
If you haven't already, use finder to open terminal again.
Type the following command and press enter:
sudo killall -HUP mDNSResponder
If prompted for a sudo password, enter your administrator account password (probably the account you login to your mac with)