Previous Entry Share Next Entry
11:38 pm, 5 Aug 06


I remember a few years ago that brad observed that he was much more productive when he unplugged his network connection. It's not only the distraction of IMs (I avoid IM) or email notifiers (I turned all mine off) or LJ posts (I broke LogJam's LJ friends-update notifier, but I think it might be broken on LJ's side too) -- it's also that I've trained myself to jam on my "friends page" link whenever I encounter the tiniest obstacle. I've even caught myself reloading my friends page while reading my friends page.

Tonight I had a flash of inspiration: iptables lets you do all sorts of packet-mangling trickery, including capturing TCP connections destined for a particular host. So I give you unplug: when you run it, it hijacks all connections to a list of hosts, making any attempt to load their pages instead serve you a page that says "FOCUS". When you kill it, it puts things back to normal.

In any case, the code is shorter than its description, so if you wanted to do something similar yourself, the only part that takes a bit of time to figure out is:
iptables -t nat -A OUTPUT --destination hostname --protocol tcp --jump REDIRECT --to-ports portnum
To list the rules, s/-A.*/-L/. To remove it, s/-A/-D/.
The REDIRECT target only works on the nat table. For more complicated redirecting there's also a DNAT target that'll let you redirect to a different host.