[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Stop dhclient from adding a default gateway

David A. Parker wrote:
> 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.
> ...
> Any help would be greatly appreciated.

By coincidence I have been hacking on these scripts today too...

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

Turn on the debug variable script


by setting RUN="yes" and then look in /tmp/dhclient-script.debug to
see what variables are available.

  less /tmp/dhclient-script.debug

Then create a new script at


and in that script put something similar to this:

  case $reason in
      unset new_routers

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

Note that the script is sourced into the dhclient-script and that the
dhclient-script is a bash script.


Attachment: signature.asc
Description: Digital signature

Reply to: