BSD/OS Networking -- Waiting for Default Router

What is an easy way to make BSD/OS 4.x or 5.x wait for the router during a reboot?

By default, BSD/OS configures all its networking interfaces while it it running the /etc/netstart file, during the reboot process. Right after this script finishes, the network is assumed to be configured and accessible. The network is almost certainly configured, but is often not quite accessible -- auto-negotiation by ethernet switches often takes tens of seconds to complete. This presents a problem for the programs that want to access the network and run immediately after /etc/netstart.

A small change to /etc/netstart will delay the script from finishing until the default router is reachable over the network. The downside of the change is that if the default router never becomes reachable, the machine never finishes rebooting, either!

# BEGIN LOCAL ADDITIONS
# Wait to make sure the ethernet switch has sync'ed up with us...
if [ "X${defroute}" != X ]; then
        router=${defroute%% *}
        echo -n 'Waiting for default router ('${router}') '
        while ! ping -n -c 1 $router >/dev/null 2>&1; do
                echo -n '.'
        done
        echo ' done!'
fi

The above code fragment, when inserted into /etc/netstart will delay the machine until the default router becomes available.

Back to the page of Not So Frequently Asked Questions.

Valid HTML 4.01! Kurt J. Lidl
lidl at pix dot net
Last Updated: $Date: 2004/02/16 20:30:13 $