View previous topic :: View next topic |
Author |
Message |
babudro n00b
Joined: 30 Sep 2005 Posts: 35 Location: Canada
|
Posted: Wed Aug 30, 2006 11:43 pm Post subject: Fix for DHCLIENT setting multiple default gateways |
|
|
Overall I have had better luck with DHCLIENT than DHCPCD, but I keep running into the problem of it setting multiple default gateways without listening to the "nogateway" option and I have to manually delete those routes any time I reboot or restart a network interface.
For example, in /etc/conf.d/net I might have this:
Code: | modules=( "dhclient" )
config_eth0=( "dhcp" )
dhcp_eth0="nogateway nodns"
config_eth1=( "dhcp" )
dhcp_eth1="nodns"
config_eth2=( "dhcp" )
dhcp_eth2="nogateway"
|
So what I want is for all three interfaces to get their IP address etc. from DHCP, eth1 (e.g., the WAN interface) will receive the default gateway, and eth2 will receive the settings for /etc/resolv.conf.
The "nodns" and other settings like "nontp" work fine, but even though I see "PEER_ROUTERS=no" in the process list (ps aux | grep dhclient) I end up with three default routes, something like this (from "ip route show"):
Code: | default via 10.0.0.1 dev eth0
default via 24.69.1.1 dev eth1
default via 192.168.1.1 dev eth2
|
As you can imagine, this is not good. Having three default routes causes packets to disappear into oblivion and makes you very frustrated until you discover the reason and manually remove the extra gateway settings.
To fix this problem I dug into the /sbin/dhclient-script file and located where the default route is being set, which is here:
Code: | for router in $new_routers; do
route add default gw $router $metric_arg dev $interface
done
|
and I added a simple if..then test to properly handle the "nogateway" option like so:
Code: |
if [ "$PEER_ROUTERS" == "yes" ]; then
for router in $new_routers; do
route add default gw $router $metric_arg dev $interface
done
fi
|
Now it works.
There are two places in the /sbin/dhclient-script where this needs to be done, near line 175 and near line 230.
Hope this is helpful. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|