Subject: Re: simple-minded configuration for rc?
To: Marshall Rose <mrose+mtr.netnews@dbc.mtview.ca.us>
From: Richard Rauch <rauch@rice.edu>
List: netbsd-users
Date: 12/14/2002 12:50:34
Re. http://mail-index.netbsd.org/netbsd-users/2002/12/13/0012.html
I faced a similar problem with my laptop. What I did was write an
rc.d/networkprobe script that uses ping to check for known combinations of
hardwired network environments. (Actually, I only had 2 such
environments, and no DHCP normally.) What I came up with was:
/~~~ /etc/rc.d/networkprobe
#!/bin/sh
#
# $$
#
# PROVIDE: networkprobe
# REQUIRE: network
/etc/rc.subr
name="networkprobe"
start_cmd="networkprobe_start"
stop_cmd="networkprobe_stop"
networkprobe_start()
{
# This really should walk through a set of alternative config.
# files, rather than being hard-coded in a shell function as
# I currently do.
#
old_host=`hostname`
echo "Probing network."
if /sbin/ping -h ricegate -qQ -w 1 -c 1 >/dev/null; then
# nothing to do; we are rauch.math.rice.edu
echo " (office)"
else
/bin/hostname odysseus
/sbin/ifconfig ne0 inet odysseus netmask 255.255.255.248 >/dev/null
/sbin/route change default prodigy-gate
if /sbin/ping -h prometheus -qQ -w 1 -c 1 >/dev/null; then
echo " (home)"
else
echo " (unknown)"
fi
fi
}
networkprobe_stop()
{
# Nothing to do, really.
}
load_rc_config $name
run_rc_command "$1"
\___ /etc/rc.d/networkprobe
Where "ricegate", "odysseus" and "prodigy-gate" are in my /etc/hosts.
The "office" environment's nameservers worked from other locations, so I
kept just one resolv.conf.
The system was basically hardwired for my office as the first default
(using standard config. mechanisms) and then would *check* if that was
correct; if not, it would retarget, using the above script.
The up side is that this would automatically configure itself. Of course,
it would only do that at boot time, and each failed ping-probe, above,
adds about 1 second. I found it very convenient.
``I probably don't know what I'm talking about.'' --rauch@math.rice.edu