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

  • your vcs sucks

    I've been hacking on some Haskell stuff lately that's all managed in darcs and it's reminded me of an observation I made over two years ago now (see…

  • 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…

  • found my bug!

    Not too interesting, but this has been bugging me for a week. Been working on a toy program that proxies a TCP connection. It was working fine for…

  • 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.