Results

See more...

How To Block Websites In Ubuntu (Linux)

Just like Windows you can easily block websites in Linux too. However before Windows Vista everyone can edit HOSTS file but now only Administrator can edit HOSTS file in Windows Vista and Windows 7. Similarly in Ubuntu there exist a HOSTS file which can be used to block websites. Only root user is allowed to edit HOSTS file. So in order to edit HOSTS file from a normal account, you have to use SUDO command.

How To Block Websites Using HOSTS File

Open Terminal by navigating to Applications->Accessories->Terminal

3792444052 def2b76075 o How To Block Websites In Ubuntu (Linux)

Use the following command to edit HOSTS file

sudo gedit /etc/hosts

Suppose you want to block YouTube and Facebook on Ubuntu. Just add the following two lines in file as shown in the screenshot and click save.

0.0.0.0 www.youtube.com
0.0.0.0 www.facebook.com

3930557019 2585742077 o How To Block Websites In Ubuntu (Linux)

Restart your computer. Now you won't be able to access these websites, no matter whatever web browser you use ;)

Note: You can find number of custom HOSTS file on Internet created to block advertisements and stuff etc.

Contact Us for News Tips, Corrections and Feedback
32 comments
Leave a message...

  •  
    desprit1 year, 1 month ago

    Sorry, this page deletes carriage returns — To open hosts hosts file with admin privilage you can also; — open
    terminal, alt+t — enter – sudo nautilus — enter admin password — nautilus will
    open with admin privilages — navigate to etc/hosts and open it with gedit.  – 
    You can edit hosts and save — close gedit, nautilus, and terminal

    •  
      ito10 months, 4 weeks ago

      thankyou!!

  •  
    steven1 year, 2 months ago

    I try this and it opens up a blank document. I got through with the file manager, and it doesn’t allow modification. Please help.

  •  
    raja1 year, 4 months ago

    i need password protection…like k9 ….does linux hav that?

  •  
    Santosh Shetty1 year, 4 months ago

    Its really a good source to website in Linux. Thanks for such a great help…..

  •  
    baldtaco1 year, 5 months ago

    works in 12.10

  •  
    Tulgaa1 year, 6 months ago

    Thanks

  •  
    hrit.path1 year, 6 months ago

    good. working in 11.4 also.

  •  
    Gdsmr0782 years, 1 month ago

    It’s working fine for me, 

    Thanks.

  •  
    Calviccool2 years, 2 months ago

    how to unblocke a website after blocking it. thx
    Dennis

  •  
    Lech2 years, 5 months ago

    Thanks :) it’s easy and very helpful

  •  
    Stefan Lalev2 years, 7 months ago

    Extrimely helpful.Finnaly I get rid of facebook.com

  •  
    Ganesh Kulpe2 years, 9 months ago

    Thanks it is working and it is really helpful

  •  
    Ronnie2 years, 9 months ago

    Thanks!
    We are deleting ours accounts and I dont want accidently to login to facebook so this is perfect. And I also learn something new here…. thanks

  •  
    Phirun2 years, 9 months ago

    i want to block facebook in my PC, i use ubuntu but i can’t find ” use commend line” in terminal. How can i find it?

  •  
    Fred2 years, 10 months ago

    Works for me in Ubuntu 11.04. Make sure to restart your computer.

  •  
    Csaba2 years, 11 months ago

    Not working at all on Natty Narwhal!

  •  
    yooyo3 years, 4 months ago

    Do you have a way to block only a specific site of a web address? For example, I would like to block only http://www.example.com/news, but do not want to block http://www.example.com.

    Putting
    0.0.0.0 http://www.example.com/news
    in the hosts file does not work.

    (This is used only as an example, blocking news.google.com would work for the purpose of this example, but I would like to know how to block the partial websites directly. Adblock pluggins do not work well since it is too easy to change back and forth — at the end indeed it is not technology but the mental toughness that counts)
    Thanks

  •  
    enmae3 years, 6 months ago

    I’ve tried this. It was really useful.
    But when I type the IP address, it seems it doesnt work…
    I CAN enter the sites.
    for examle, facebook.com’s IP address seems 69.63.181.12 .
    and I tried to add in /etc/hosts like this:
    0.0.0.0 69.63.181.12 (<- facebook)

    So how completely block sites on Linux?
    Mine is ubuntu 9.10 Mozilla.

    btw, this is cool blog! thanks .

    •  
      Wolverine3 years, 6 months ago

      Well Facebook has different servers and each one of them has different IP address, so you need to enter site name (www.facebook.com) instead of the IP addresses which may change arbitrarily.

  •  
    Tommy3 years, 7 months ago

    When i open the file it comes up as “Read only” so i cant remove the files.
    what do i do !

    •  
      Wolverine3 years, 7 months ago

      You need to use SUDO command. (via Sathis)

  •  
    aditra3 years, 9 months ago

    and how to unlock the facebook again?
    same with the procedure or there’s something else?

    •  
      Wolverine3 years, 9 months ago

      Just remove the lines you added in HOSTS file.

  •  
    Jaxov3 years, 11 months ago

    Well only root users are allowed to edit HOSTS file. So either login as a root user or use SUDO before gedit /etc/hosts.

    Example: sudo gedit /etc/hosts

    •  
      nyandwi1 year ago

      hello ! i have a computer working as a firewall/router and it uses Ubuntu linux 12.04. so, I want to block some websites so that no one can access them inside the organization’s LAN. HELP ME. THANKS !

  •  
    muhin3 years, 11 months ago

    i can not save hosts file bcz this file is read only….. how can i save hosts file?????

  •  
    Lozu4 years, 1 month ago

    Thanks very much, that was hell lot useful.

  •  
    Ruslan4 years, 1 month ago

    thank you. that was useful, forced myself to block all social networks + livejournal + some torrent sites as they were killing my time:)

  •  
    SM20994 years, 2 months ago

    Hi. Great tip. Although I was wondering if it could be used on a Linux box enabled as a bridge. Since the bridge is just letting data inside and out… if you ad these lines of codes to the /etc/hosts, will that maybe is a firewall-esque sense block websites to people who are conected to the the bridge and trying to access the websites going through it?

    Great site and thanks in advance.

  •  
    rozi4 years, 2 months ago

    thx, it’s really efficient and helpfull