Digital Elephant

Removing Useless Host Entries from Route Table

My distribution (RedHat 7.1) came with this bug in its network initialization scripts. Strictly speaking, the UH entries do no harm, but they do clutter the landscape, and are actually useless. Each of them duplicates information already contained in the line describing each directly-connected subnet, and a machine lacking such host-specific entries will behave the same: it will consult its route table, matching the target address against each Destination after applying the Genmask; if they are equal, a route has been found, and the packet goes out on that interface.

The spurious entries are caused by a bug in the script /etc/sysconfig/network-scripts/ifup. About 110 lines down in this script, there is this fragment:

    # don't re-add subnet route on 2.2 kernels, but add a route
    # to a non-local subnet.
    # stupid hack, but it should work
    if [ "$ISALIAS" = no ] && [ -z "`route -n | sed "s/ .*//" | grep ${NETWORK}`" ]; then
	route add -net ${NETWORK} netmask ${NETMASK} dev ${DEVICE}
    else
	route add -host ${IPADDR} ${DEVICE}
    fi

Once, this attempted to supply routes to non-local hosts by faking up an interface entry for such hosts. That scheme has been supplanted by the introduction of static routes, specified in the file /etc/sysconfig/static-routes. Therefore, the else clause should be deleted from this script statement:

    # add subnet route on 2.2 kernels only once.
    # stupid hack, but it should work
    if [ "$ISALIAS" = no ] && [ -z "`route -n | sed "s/ .*//" | grep ${NETWORK}`" ]; then
	route add -net ${NETWORK} netmask ${NETMASK} dev ${DEVICE}
    fi

Last updated November 7, 2006 Webmaster