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 on your system, then add the following line to your /etc/hosts file.

Save and close the file. Now try accessing 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 it redirects them to localhost ( that is your own system, thereby blocking the address.

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

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

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.