Evan Martin (evan) wrote in evan_tech,
Evan Martin


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.
Tags: project

  • dremel

    They published a paper on Dremel, my favorite previously-unpublished tool from the Google toolchest. Greg Linden discusses it: "[...] it is capable…

  • google ime

    Japanophiles might be interested to learn that Google released a Japanese IME. IME is the sort of NLP problem that Google is nearly uniquely…

  • ghc llvm

    I read this thesis on an LLVM backend for GHC, primarily because I was curious to learn more about GHC internals. The thesis serves well as an…

  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.