how to keep udhcpc from setting the default route?

Alexander Griesser alexander.griesser at lkh-vil.or.at
Wed Feb 18 14:08:55 UTC 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Robert P. J. Day wrote:
>> As you can see, if a router option is given, it tries to set the
>> default route to this option.
> 
>   potentially a dumb question but where is the "router" variable set
> such that the udhcpc default script will be passed that value?

That's udhcpc magic.
udhcpc executs the given script (-s parameter, default location can be
configured in busybox so that you can omit -s) with only one parameter
and that is the current DHCP action (bound, renew, deconfig, etc.).

So in your case, the udhcpc.sh script will be called twice, once for
eth0 and once for eth1 when both interfaces get a lease.
The variables like router, domain, etc. are placed into the shell
scripts environment by udhcpc itself so that it is easier for the
script to refer to these values.

The router variable ($router) is only set, if your DHCP lease contains
a router option, so if you're getting two IP addresses on the same
subnet on two different physical interfaces (for whatever reasons)
you need to manually mark one interface as the primary interface and
this can be done with a one-line hack in udhcpc.sh.

If you get IP addresses of two different subnets from two different
DHCP scopes you should think about removing the gateway from one
of the scope options if possible, that would get rid of this issue
automatically.

> as it is, i would like eth0 to add a default route entry, but not eth1.

OK, so go and find you udhcpc.sh script and search for the line where
it sets the default route (it probably looks similar to what I posted
before).

Now change this line from

route add default gw $router

to

[ "$interface" = "eth0" ] && route add default gw $router

and you should be good.
You could also use different scripts for the interfaces, so that the
udhcpc.sh script for eth0 sets the default router and the one for eth1
doesn't, etc.

There are several ways to achieve this goal.

ciao,
- --
Alexander Griesser (Netzwerkadministration)
E-Mail: alexander.griesser at lkh-vil.or.at | Web: http://www.lkh-vil.or.at
KABEG LKH Villach | Nikolaigasse 43 | 9500 Villach
Tel.:   +43 4242 208 3061 | Fax.:   +43 4242 208 971 2061
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmcFncACgkQ66HVD6KUm1oFiACfbVjLvwd2x7AYEroZ+Tx7/1J6
+dcAnA5l6IZoZS7mlwmPLqWzq6QPPq0R
=FHzv
-----END PGP SIGNATURE-----


More information about the busybox mailing list