block website in linux

How to Block Website in Linux

If you are a system administrator of an institution or organization, you may need to block certain websites & domains so that people on your network are unable to access them. Although there are many third-party software and tools available for this purpose, you can easily do this for free too. In this article, we will look at how to block website in Linux. You can use these steps to block websites and domains on any Linux system.


How to Block Website in Linux

Here are the steps to block website in Linux.


1. Open /etc/hosts

Open terminal and run the following command to open /etc/hosts file in a text editor. Whenever a user on your system tries to access a domain, website or IP address this file is used to determine where to direct them.

$ sudo vi /etc/hosts


2. Block Websites in Linux

Let us say you want to block www.facebook.com on your system, then add the following line to your /etc/hosts file.

127.0.0.1 www.facebook.com

Save and close the file. Now try accessing www.facebook.com on your web browser and you will not be able to access it. If the above step does not block the desired website, restart your system or browser and try again.

What the above line does is, when a user on your system tries to access www.facebook.com it redirects them to localhost (127.0.0.1) that is your own system, thereby blocking the address.

Please note, in this case, www.facebook.com and facebook.com are different. If you want to also block facebook.com, you will need to add another line below the above line

127.0.0.1 facebook.com

Similarly, if you want to block multiple websites such as www.youtube.com and www.twitter.com then add them one below the other in /etc/hosts

127.0.0.1 www.youtube.com
127.0.0.1 www.twitter.com

As you can see, /etc/hosts can be used to block websites & domains.

You can also perform the same steps to block website in Windows system. Just open hosts.txt file in C:\Windows\System32\drivers\etc in Notepad or other text editor and add the above lines as per your requirement.

In this article, we have learnt how to block websites & domains in Linux. This is a very common requirement for system administrators who manage networks in educational institutions and business organizations. Instead of spending a lot of money on third-party software, you can easily block websites in Linux using the above steps.

Also read:

How to Clear Terminal History in Linux & MacOS
How to Show Asterisk In Password for Linux
How to Verify PGP Signature of Downloaded Software
How to Convert RPM to DEB File in Linux
How to Install .deb file in Linux

Leave a Reply

Your email address will not be published.