How to block certain website access in Linux without hardware firewall

If you want to block social media sites or certain list of sites in LINUX without any third party software or hardware firewall.It is possible in LINUX. You can do this via /etc/hosts file. For this you should have root access. Just follow the below steps to do it will take just few seconds.

Make sure /etc/hosts file is important one because it will handle all the DNS request, So before making changes you need to take backup.

Tested Environment.

Root level Access Yes
Tested site
Tested site

For example, I’m going to disable & access from my PC.

Open the /etc/hosts file with your favorite text editor and add the below colored lines. If you want to block different website, add the corresponding website name instead of or Save your text editor and exit.

[email protected]:~$ sudo nano /etc/hosts
[sudo] password for magesh: 

GNU nano 2.2.6                                   File: /etc/hosts                                                                           localhost       magesh-desktop

# block access to social media sites

Now, I’m going to check both website on browser whether its working or not.

1) Facebook website is not opening in my PC because of hosts file.

2) youtube website is not opening in my PC because of hosts file.
Both are not opening, So the configuration is working properly.

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...