#6 choose active interface by default

open
nobody
None
5
2010-02-12
2010-02-12
fudgeboy
No

Currently nethogs defaults to eth0. This is OK but it would be better if it defaulted to the default interface in the routing table. It's a bit tedious on laptops, for instance, where the wireless interface is often eth1 or wlan0 and you have to check which it is.

Running

route | grep "^default"

gives you the default interface, though there is probably a better way of picking it up from somewhere in /proc. In fact, it looks as though it's in /proc/net/route, and you'd want the line where Mask=0.

Failing that, using the first interface that's up would be a better choice than always plumping for eth0.

Thanks!

James

Discussion

  • Ethan

    Ethan - 2013-02-06

    Please don't hurt me:

    nethogs `cat /proc/net/route | grep -m1 00000000 | sed 's/\([a-z0-9]*\).*/\1/'`

    I know it can be done without the grep, but I'm terrible at sed... feel free to clean up. Anyway, this is what I've taken to using since I switch between eth0 and wlan0. What I'd really like is an option for nethogs to operate on all active interfaces, or at least to ignore inactive ones gracefully. Today if you specify a device that isn't active you get this:

    ioctl failed while establishing local IP for selected device