Blocking Websites with /etc/hosts

3,030

Solution 1

Rather then make this block using /etc/hosts I'd suggest using a browser addon/plugin such as this one named: BlockSite for Firefox or StayFocusd for Chrome.

BlockSite

  ss #1

StayFocusd

                    ss #2

But I want to really use /etc/hosts file

If you must do it this way you can try adding your entries like this instead:

0.0.0.0   www.example.com
0.0.0.0   example.com
::0       www.example.com
::0       example.com

You should never add entries to this file other than hostnames. So don't put any entries in there that include prefixes such as http:// etc.

Solution 2

You need to flush your DNS cache. According to this article, you can do that by restarting the following services:

  • nscd
  • dnsmasq
  • named
Share:
3,030

Related videos on Youtube

iosdev
Author by

iosdev

Updated on September 18, 2022

Comments

  • iosdev
    iosdev almost 2 years

    Possible Duplicate:
    Can I show an UISegmentedControl object in vertical?

    How to make a UIsegmentController vertical ,I tried using,

    segmentedControl.transform = CGAffineTransformMakeRotation(M_PI / 2.0);
    

    but its make the segment control fonts to vertical.Can any one help me to code for vertical segmentcontrolbar?

    • Cyrille
      Cyrille over 11 years
      BTW, there's no need to write M_PI / 2.0, there's already a M_PI_2 constant defined (and M_PI_4, for what it's worth).
    • Paras Joshi
      Paras Joshi over 11 years
      see some links in my answer with some desc... :)
  • iosdev
    iosdev over 11 years
    subview.subviews shows error..propert not found
  • iosdev
    iosdev over 11 years
    i just want to make the segment control as like stackoverflow.com/questions/9168840/…
  • iosdev
    iosdev over 11 years
    i want to make like this stackoverflow.com/questions/9168840/…
  • Paras Joshi
    Paras Joshi over 11 years
    hey if insted of segment control you use dropdawn box then its ok??
  • jasonwryan
    jasonwryan about 10 years
    The OP does expressly ask for solutions that don't involve browser plugins/extensions...
  • slm
    slm about 10 years
    @jasonwryan - thanks, missed that last sentence in the Q.
  • Newb
    Newb about 10 years
    The last part of your answer was correct --- my mistake was that I had written http://www.example.com instead of www.example.com. Now the site is blocked.
  • Eric
    Eric over 8 years
    This is useful, and both chrome & firefox has an extension named block site, both great.
  • Rui F Ribeiro
    Rui F Ribeiro over 7 years
    Alas, what I needed was a plug-in that would ignore all the links to other sites than the current one and would be activated to sites of my own choice.
  • Admin
    Admin over 7 years
    The article is from 2008 and appears to be out of date. My linux mint install doesn't have nscd or rndc.
  • Nick
    Nick about 4 years
    sudo systemd-resolve --flush-caches worked on ubuntu 20.04
  • Thorkil Værge
    Thorkil Værge almost 3 years
    A modification to the hosts file should take effect without having to restart anything. In case of redirects, you may have to block the target of the redirect too, though.