can I pick anyone's brains?

Christopher Barry christopher.barry at rackwareinc.com
Wed Jan 26 16:24:35 UTC 2011


On Wed, 2011-01-26 at 17:15 +0100, Harald Becker wrote:
> Hallo David!
> 
> Here we are again ... :-)
> > If I have an IP address... 10.12.15.7 or something, is there a simple
> > command I can issue from a script which will examine all the routing
> > tables for me and return
> >
> > "eth0"  "local"
> > or 
> > "eth1"  "gateway"
> > or
> > "tun0"  "gateway" 
> >
> > or something similar?
> Can you please tell a bit more, what you want to achieve? The routing is
> normally done by the kernel, so not required to be done in user space
> programs or shell scripts.
> 
> There is one command, that allows to dump the routing table, that is the
> command "route". With an awk script it would be possible to filter the
> table output and select an appropriate routing entry. That way an awk
> script could be used to build a command with your requirements ... else
> I don't know any standard command for your purpose.
> 
> --
> Harald

I like 'ip r'. parse it however you like.

outputs like below:
# ip r
172.16.1.0/28 dev wlan0  proto kernel  scope link  src 172.16.1.2
metric 2 
192.168.68.0/24 dev vmnet8  proto kernel  scope link  src 192.168.68.1 
192.168.112.0/24 dev eth1  proto kernel  scope link  src 192.168.112.10 
192.168.111.0/24 dev eth0  proto kernel  scope link  src 192.168.111.10 
192.168.122.0/24 dev virbr0  proto kernel  scope link  src
192.168.122.1 
169.254.0.0/16 dev wlan0  scope link  metric 1000 
default via 172.16.1.1 dev wlan0  proto static



More information about the busybox mailing list