Subject: default route deleted incorrectly with dhclient
To: None <>
From: Steven M. Bellovin <>
List: tech-net
Date: 07/19/2006 22:51:29
A while back, I posted a note about the wrong default route being deleted
with dhclient.  Specifically, if I have a lease on int0, suspend my
laptop, and get a lease on int1 instead, when int0's lease expires the
default route -- via int1 -- will be deleted.

Here's a patch that's currently in my /etc/dhclient-enter-hooks, but could
(or should) go into /sbin/dhclient-script instead.  How does it look?  (It
would replace the current text of the delete_old_routes() function.)

delete_default() {
        route show -inet | sed 1,4d | \
        while read dest gw flags
                if [ "$dest" = default -a "$gw" = "$1" ]
                        route delete -inet $dest $gw
                        echo route delete -inet $dest $gw >&2

delete_old_routes() {
        for router in $old_routers; do
                delete_default "$router"
        done >/dev/null 2>&1

        set -- $old_static_routes
        while [ $# -gt 1 ]; do
                route delete $1 $2
                shift; shift

        arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -n -d \1/p' | sh

		--Steven M. Bellovin,