I always put my squeezebox servers on a static ip address at x.x.x.222.
I have a series of scripts that I use to configure eth0, the firewall
and samba for the static ip. I'd like to come up with a way for
rc.local to figure out if a server has been moved to a new subnet and
then automagically reconfigure the network interface, etc. This is what
I've come up with thus far. I'm sure it can be improved upon. Anyone
have any ideas?
Code:
--------------------
#!/bin/sh
# script to reconfigure network if the subnet changes..
DEFAULTIP='192.168.0.222'
IPADDR=`ifconfig eth0 | sed -rn 's/.*r:([^ ]+) .*/\1/p'`
ROUTER=`echo $IPADDR | sed -n
's/\(.\{1,3\}\)\.\(.\{1,3\}\)\.\(.\{1,3\}\)\..*/\1\.\2\.\3\.1/p'`
echo "Attempting to ping ${ROUTER}.."
/bin/ping -c 1 $ROUTER > /dev/null 2>&1
#if ping -c 1 $ROUTER > /dev/null 2>&1
if [ $? -gt 0 ]; then
echo "${ROUTER} does not respond to ping.."
DHCPINFO='/tmp/dhcpinfo.txt'
dhclient -1 -d -nw eth0 &>$DHCPINFO &
sleep 30
pkill -n -f 'dhclient -1 -d -nw eth0'
DHCPSERVER=`cat $DHCPINFO | sed -n -e 's/^DHCPOFFER.* from\(.*\)$/\1/p'`
echo "dhcpserver == ${DHCPSERVER}"
if [ -z "$DHCPSERVER" ]; then
NEWIP="$DEFAULTIP"
else
NEWIP=`echo $DHCPSERVER | sed -n
's/\(.\{1,3\}\)\.\(.\{1,3\}\)\.\(.\{1,3\}\)\..*/\1\.\2\.\3\.222/p'`
fi
echo "Reconfiguring network for ${NEWIP}.."
. /usr/local/sbin/config-network.sh
else
echo "${ROUTER} responds to ping, so network is OK.."
fi
--------------------
------------------------------------------------------------------------
gharris999's Profile: http://forums.slimdevices.com/member.php?userid=115
View this thread: http://forums.slimdevices.com/showthread.php?t=95037
_______________________________________________
unix mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/unix