I would like to restrict some websites to be surfed. I mean I want to prevent access to some websites. Please guide me on how to do the same in Ubuntu 14.04 LTS.
3 Answers
The easiest way, which works system-wide, is to set up entries in /etc/hosts
For example, add the following lines to the end of /etc/hosts
, one for each site you want to block:
127.0.0.1 example.com
127.0.0.1 www.example.com
127.0.0.1 example.net
127.0.0.1 www.example.net
This tells the system's DNS resolver "please override the name to IP resolution for these host names" and since it overrides it to 127.0.0.1
, those sites won't work.
Note that it is possible for users to circumvent this by using an HTTP proxy in the browser or if they were somehow to use an alternative DNS resolver, or if the site accept connections based on IP address only, and so on.
-
2This is pretty much simple and explain it very well. Further, I'd prefer if you can add
sudo nano /etc/hosts
orsudo vi /etc/hosts
to your answer. This may come in handy in future if any newbie users or similarly looking for an answer. :)– AzkerMJul 13, 2014 at 5:25
Open a terminal, and type sudo vi /etc/hosts
.
Type Shift+G
, then Shift+A
, then I
.
You should now see --INSERT--
at the bottom of the screen. Then, cut and paste this code:
127.0.0.1 siteyouwanttoblock.com
To save, press :
and type wq
and click enter.
It's as simple as that!
Note: I have NOT come up with this answer. I just made it more simple for the newbies. All credits go to you, @neon_overload.
Best way for blocking and allowing sites
Url Blocking :
your website ip and press tab type your ur website
go to Terminal and type sudo gedit /etc/hosts
xxx.xx.x.x yourwebsite.com
175.XXX.xxx.xx yourwebsite.com
202.XX.xx.xx yourwebsite.com
deny all sites (*.*.*.*
) means all IPs
Open sudo gedit /etc/hosts.deny
and add *.*.*.*
in last line
allow host ips(url ips). Find your URL IPs with nslookup cmd
command
open sudo gedit /etc/hosts.allow
175.xxx.xxx.xx
175.1.xxx.xx
x.x.x.x
x.x.x.x
Open sudo gedit /etc/resolv.conf
and type #
before servername 127.0.0.1
and add
servername 0.0.0.0
-
This could be much, much clearer with a little thought. As it is I don't even want to try it because of the ambiguity.– kentfxOct 9, 2017 at 13:55