dhclient ant policy based routing

richard lucassen mailinglists at lucassen.org
Thu Jan 23 19:25:30 UTC 2014


Hello list,

I have a linuxbox (Debian) with a fixed routed subnet on eth0. The eth0
is the default gateway in the default route table.

On eth2 I have a dynamic (non-rfc1918) address docsis router. I want
the following things to be realized:

1) run dhclient on eth2
2) dhclient on eth2 must NOT set default gw on default route table
3) dhclient must fill a user defined route table
4) dhclient must set def gw on that user defined route table
5) dhclient must set policy based routing
6) dhclient must clear all of the above on stop

Ok, I managed this. It works perfectly well. I just would like to have
some feedback on the "case" statement like BOUND|RENEW|REBIND|REBOOT
for activating the rules and FAIL|NBI|STOP|TIMEOUT|RELEASE|EXPIRE to
clear the rules.

Did I do this right or wrong?

R.


cat /etc/dhcp3/dhclient-enter-hooks.d/no-default-route
#####################################################################
# enter hooks script:

case $reason in

BOUND|RENEW|REBIND|REBOOT)
  # Do not set default gw, but create a copy to use it in exit hooks
  # scripts:
  export new_routers_copy=$new_routers
  # Avoid gw in default route table, but preserve copy for
  # policy based routing:
  unset new_routers
;;

FAIL|NBI|STOP|TIMEOUT|RELEASE|EXPIRE)
  ip route del $old_network_number/$old_subnet_mask \
    dev $interface table 12
  ip route del default via $old_routers table 12
  ip rule del from $old_network_number/$old_subnet_mask lookup 12
;;

esac
#####################################################################

cat /etc/dhcp3/dhclient-exit-hooks.d/no-default-route

#####################################################################
# exit hooks script:

case $reason in

BOUND|RENEW|REBIND|REBOOT)
  ip route add $new_network_number/$new_subnet_mask \
    dev $interface table 12
  ip route add default via $new_routers_copy table 12
  ip rule add from $new_network_number/$new_subnet_mask lookup 12
;;

esac

#####################################################################



-- 
___________________________________________________________________
It is better to remain silent and be thought a fool, than to speak
aloud and remove all doubt.

+------------------------------------------------------------------+
| Richard Lucassen, Utrecht                                        |
+------------------------------------------------------------------+


More information about the dhcp-users mailing list