4

I want to block every website on the stackexchange network (as I often tend to waste a lot of time on those). How can I do it?

One solution is to obviously write all the sites' entries manually in the hosts file, but is there a better solution?

Note that just blocking on the regex *.stackexchange.com won't work as a lot of websites have unique names like superuser and askubuntu.

I am using Ubuntu 16.04.

Edit:

I've posted this question here not to learn self-control, but because I am genuinely curious about its technical feasibility.

Please write the reason for the downvotes in the comments so that I can act on it!

12
  • 12
    I feel I shouldnt answer this on principal
    – Keltari
    Commented Jul 3, 2016 at 3:47
  • 3
    Are you saying that every last SE site is irresistible, and if you just block them all, you won't find other sites out there to satisfy your addiction? I don't know, it sounds like an XY problem to me. :-)
    – fixer1234
    Commented Jul 3, 2016 at 3:57
  • 4
    Since you obviously asked this question under a pseudonym, kindly please post your real SE name and password. The problem will take care of itself in no time.
    – dxiv
    Commented Jul 3, 2016 at 4:20
  • 3
    You could always just delete all your accounts
    – Mokubai
    Commented Jul 3, 2016 at 10:42
  • 2
    You're trying to solve a people problem with technology. Generally that does not work well.
    – Bob
    Commented Jul 3, 2016 at 12:05

2 Answers 2

8

First, an aside, spending time here on stackexchange is hardly wasting time. Either you are getting answers to questions you ask, or helping out a fellow user. Neither educating yourself nor helping your fellow man/woman is considered time wasted by anyone I know.

Second, with a reputation of 121, I doubt you have spent a faction of the time on here as I have with a repuation of 5000 and counting.

Whois reveals this so block this range and you won't get it. If your firewall supports CIDR notation a single line below will block it all.

NetRange:       151.101.0.0 - 151.101.255.255
CIDR:           151.101.0.0/16

Command to block access to this IP range:

iptables -I OUTPUT 1 -d 151.101.0.0/16 -j DROP

You will have to save the iptables configuation, otherwise when you reboot it is lost. I don't know if Ubuntu has an automatic facility for that.

iptables-save ><somewhere>/iptables.save
iptables-restore <<somewhere>/iptables.save

if using systemd create a file named iptables.service in /etc/systemd/system/

[Unit]
Description=IPtables load rules
DefaultDependencies=no
After=ipset.service network-pre.target
Before=network-online.target network.target

[Service]
Type=oneshot
ExecStartPre=-/bin/echo 'Starting iptables'
ExecStart=/usr/sbin/iptables-restore <somewhere>/iptables.save
ExecReload=/usr/sbin/iptables-restore <somewhere>/iptables.save
ExecStop=/usr/lib/systemd/scripts/iptables -flush
RemainAfterExit=yes
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_RAW

[Install]
WantedBy=basic.target

then systemctl enable iptables

11
  • Even after executing iptables -I INPUT 1 -d 151.101.0.0/16 -j DROP, I am still able to access StackOverflow. Commented Jul 4, 2016 at 0:51
  • By wasting time, I meant checking out random questions from the Hot Network Questions feed without any intention of answering them. And I spend most of time on StackOverflow rather than SuperUser. Commented Jul 4, 2016 at 0:53
  • You probably need this also: iptables -I FORWARD 1 -d 151.101.0.0/16 -J DROP and change INPUT to OUTPUT, in the previous rule.
    – cybernard
    Commented Jul 4, 2016 at 0:54
  • It's working with OUTPUT; the FORWARDone is redundant. Commented Jul 4, 2016 at 1:00
  • Also, can you please explain exactly how did you find the ip range 151.101.0.0/16? Commented Jul 4, 2016 at 1:07
0

As a softer solution, that you can easily configure to block stackexchange sites only for a limited time, you may consider the Chrome extension StayFocusd.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .