Debian tip

I was getting tired of having my machine not DHCP on the ethernet when I boot. I have eth0's auto up disabled because it's usually not connected to a network when it boots. But sometimes it is, and logging in on a shell and ifup'ing it was getting old. So I came up with a cheap trick.

(I'd use the daemons that detect link beat and bring the interface up and down based on it, but for much of what I do, that's unsuitable for various reasons as well, so I just want to assume that the interface should only act automatically if it's plugged into a network on boot.)

(in /etc/network/interfaces)

auto eth0
iface eth0 inet dhcp
        pre-up /sbin/mii-tool eth0|grep ok > /dev/null

This takes the output of mii-tool's report on eth0. Since grep returns an error code if the string is not found (mii-tool reports "eth0: no link" if not connected, and "eth0: negotiated 100baseTx-FD, link ok" (or similar) when it's connected), the interface going up will fail if mii-tool doesn't have an "ok" in the return. So if it's not connected on boot, it won't go up automatically, but if it is, it'll DHCP it on boot.

It's something quasi-obvious but neat.

And to all my friends back in MI, I just want to point out that I have only been wearing a coat during the evenings. 😛