There are times when you need to block certain websites’ access from the system. This could be your personal discipline to not waste time on addictive websites or it could be at your workplace where you are asked to do so. Or maybe you do not want someone to access few websites while using the computer. In either of the cases, this article will guide you through the best possible ways to block access to websites on a Linux system.

To block websites on Linux we can use many ways and tools but the two methods that you are going to learn about in this guide are the easiest.

  • Using the ‘hosts’ file
  • Squid

However, in this guide, I am going to focus on the first method. So let’s put the control of the internet in our hands and block some websites on your computer.

Blocking websites on Linux with ‘hosts’ file

Blocking a website with a ‘hosts’ file is pretty easy. You simply, open it up and redirect the websites to your localhost. When anyone tries to visit that website, your system automatically redirects it to a dead-end, showing an error of the website not getting found.

So to archive this, follow below instruction and block some websites on your system.

Firstly, open the ‘hosts’ file (Use any editor you like):

sudo nano /etc/hosts

Now just add the domain names that you want to block and redirect them to a dead address, a good one can be your localhost address – 127.0.0.1.

Blocking websites on Linux with hosts file

After making changes to the ‘hosts’ file, reconnect to the internet and access to the mention websites will be blocked. Sometimes it can take few minutes to take effect.

And that is all you have to do to block any website from in your computer.

Also read: 10 facts about Linux that you should know

Watch Video guide on YouTube

Additionally, You can also watch a step-by-step video guide on YouTube to get a better understanding of it.

Conclusion

So that’s it on how to block websites on Linux. If you have anything to share then let me know what you think about it in the comments. You can also subscribe to the LinuxH2O Youtube channel. Till then, keep enjoying Linux.