Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

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: example.com www.example.com example.net 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, 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.

share|improve this answer
This is pretty much simple and explain it very well. Further, I'd prefer if you can add sudo nano /etc/hosts or sudo vi /etc/hosts to your answer. This may come in handy in future if any newbie users or similarly looking for an answer. :) –  AzkerM Jul 13 '14 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: 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.

share|improve this answer
A good explanation like this is always needed. –  A Umar Mukthar Sep 6 '14 at 4:04

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


Open sudo gedit /etc/resolv.conf and type # before servername and add

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.