Raspberry Pi

How to Block a Website on Raspberry Pi?

Blocking the unnecessary websites is beneficial as it minimizes the effect of getting harmful viruses through untrusted websites. There are multiple ways to block the URLs in Raspberry Pi OS but not every method proves to be good. So, if you are looking to block some random popups or certain websites access on your Raspberry Pi then try the methods mentioned in this guide.

Methods for blocking websites on Raspberry Pi

Raspberry Pi can be used for many applications due to its diversified specification, for instance you can use it as a mini-PC for your kids. In that case you need to block the access of some websites to keep your children safe. So, there are two ways to block websites in Raspberry Pi:

  • Using terminal command
  • Using Pi-hole

Using Terminal

This is the easiest way to block the access of any website as it requires minimal effort and only a few steps:

Step 1: Open the “/etc/hosts” file in the text editor by using the given command:

$ sudo nano /etc/hosts

Now add the URL of the website whose access you want to block in the text file like this:

127.0.0.1 www.youtube.com

Here in the command above first the IP is given and then the URL of the website is stated. Now save and close the file, just to be sure enter the URL and check if it is blocked or not:

To Unblock the website, open the “/etc/hosts” text file and remove the IP address and the URL, after that save the file and you are good to go.

Using Pi-hole

Pi hole is a third party application that is used to block ads and monitor all the incoming and outgoing traffic. It also has an option of not only blocking websites but also provides the opportunity to add websites that can be accessed through the internet connection. The process of installing Pi-hole is quite lengthy so read: how to setup Pi-hole on Raspberry Pi. After you have installed Pi-hole in Raspberry Pi open it and follow the given steps to block any website:

Step 1: Click on the “Domains” option from the menu on the left, next add the URL you want to block and then click on “Add to Blacklist”:

So, this is how you can block website on Raspberry Pi and to unblock a website simply click on it and press the trash icon below the URL in the “List of domains” tab:

Conclusion

Blocking unnecessary and harmful websites is a very essential task to keep computers safe from hackers and viruses. On the other hand, educational institutes also block sites that are potentially harmful for students. There are several ways to block websites especially when you are using Linux based systems like Raspberry Pi. Adding the URLs in /etc/host file and using Pi-hole for this purpose are the best two ways one can try to block websites on Raspberry Pi.

About the author

Aaliyan Javaid

I am an electrical engineer and a technical blogger. My keen interest in embedded systems has led me to write and share my knowledge about them.