Want to block access to certain websites from your machine running Ubuntu or Linux Mint? It’s easy to do it by editing the host file.
With the hosts file, you can tell Ubuntu to redirect the specific websites to 127.0.0.1. So that the web browser returns below error:
To do so, edit the /etc/hosts with your favorite editor. Press Ctrl+Alt+T on your keyboard to open terminal. When it opens, run below command to edit the hosts via gedit:
sudo gedit /etc/hosts
Add below lines to the end of the file. Exclude the “http://” and change the domain names.
# block access to certain sites
127.0.0.1 www.websites1.com
127.0.0.1 www.websites2.com
127.0.0.1 websites3.com
127.0.0.1 morewebsites.com
Save the file and re-launch your web browser. Done.
i tried but the hosts file is names as readonly. then what shoud i do
You need root privilege to edit the file. Use the command in the article, or press Alt+F2 -> type gksudo nautilus and hit enter to open Nautilus file browser as root so that you can edit it in your browser.
How to modify so I can block some sites with warning message?
Can you help me? thanks before
You might like a service like OpenDNS. It’s very powerful and free.
facebook then also can be easily opened as when
we type https://www.facebook.com in browser tab
it will be opened even after saving it in host file!
I tried this for Facebook, and it kind of works… If I open my web browser and type in “facebook.com”, the hosts file reroutes “facebook.com” to “127.0.0.1”. HOWEVER, if I open Google and search for “Facebook”, I can still access the Facebook website. How to you prevent access to the “facebook.com” domain completely?
Obviously, this is not really about blocking Facebook; it’s about blocking pornographic websites. I’ve tried configuring OpenDNS (208.67.222.123 and 208.67.220.123) as the default DNS for my home router, but its effects are still spotty–even after flushing the DNS cache of my computer and browser.
I’m wondering if there’s a good way to use UFW to accomplish this? I don’t care if I have to manually list the websites one-by-one or if I can find a way to block all pornography by default–I just want it out of reach.
i want to block facebook