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.

PC OS UBUNTU 14.04 LTS
Root level Access Yes
Tested site facebook.com
Tested site youtube.com

For example, I’m going to disable facebook.com & youtube.com 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 facebook.com or youtube.com. Save your text editor and exit.

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

GNU nano 2.2.6                                   File: /etc/hosts                                                                            

127.0.0.1       localhost
127.0.1.1       magesh-desktop

# block access to social media sites
127.0.0.1       www.youtube.com
127.0.0.1       www.facebook.com

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

1) Facebook

Facebook.com website is not opening in my PC because of hosts file.
how-to-block-certain-website-access-in-linux-without-hardware-firewall-1

2) youtube

Youtube.com website is not opening in my PC because of hosts file.
how-to-block-certain-website-access-in-linux-without-hardware-firewall-2
Both are not opening, So the configuration is working properly.

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...