Issue : I have a Debian Lenny box with two NICs, eth0 and eth1. eht1 is a trunking interface and can be put onto any VLAN. Whenever eth1 is put onto a VLAN, I want it to get an address from DHCP but I do not want it to set a default gateway.
Solution : The dhclient-script sets the route. If you want to prevent it then you will have to either prevent dhclient-script from setting it or to remove it after it has been set.
$ man dhclient-script
Then browse through the script /sbin/dhclient-script and look at how it is setting routes.
$ less /sbin/dhclient-script
Step 1 : Turn on the debug variable script by setting RUN="yes" :
$ nano /etc/dhcp3/dhclient-enter-hooks.d/debug
Step 2 : then look in /tmp/dhclient-script.debug to see what variables are available.
less /tmp/dhclient-script.debug
Step 3 : create a new script at
/etc/dhcp3/dhclient-enter-hooks.d/no-default-route
Step 4 : in the above script put something similar to this :
case $reason in BOUND|RENEW|REBIND|REBOOT) unset new_routers ;; esac
The above disables the default route. You will probably want more specific control such as only doing that when certain conditions are met. Such as if the IP address matches your particular IP address or some such. But I think this is probably enough to get you going.
WARNING : Be very careful trying this if you are accessing the host over the network and your connection requires a default route. Because obviously removing the default route will break your connection to the host. Connections on the local subnet will be okay.
Note that the script is sourced into the dhclient-script and that the dhclient-script is a bash script.
This work by maniac.vardhan is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
0 comments :: how to restrict dhclient from adding a default gateway
Post a Comment