route in busybox

Hans-Werner Hilse hilse at
Thu Dec 8 13:36:05 UTC 2005


> if I do route -n, I'll get
>       IP_address

This is easy to parse:

DEFAULT_GATEWAY=$( /sbin/route -n | awk '/^ { print $2; }' )

(obviously I'm using awk here... You might substitute this by grep/sed.

> In my school environment, once I get an IP with udhcpc, I'll get an
> internal IP, with default route to an internal gw.....

If using DHCP, make shure your client doesn't reset the routes after you
maipulated them.

> now I'll run vpnc (with universal tunneling device), and set up the
> default gw to the IP I got from vpnc...
> however, before I set up the new default gw, I need the IP of the old
> gw, so that I can add a -host rule to the routing table for the VPN
> server....

See above for my suggestion.
You'd set up a second line like

/sbin/route add -host $VPN_GATEWAY gw $DEFAULT_GATEWAY

to actually set that route.


More information about the busybox mailing list