On Wed Apr 02, 2003 at 01:41:24PM +0200, Martin Sjögren wrote: > mån 2003-03-31 klockan 04.04 skrev Erik Andersen: > > > udhcpc works, but it needs a script to operate correctly. > > > > It works great. Just drop this in as your > > /usr/share/udhcpc/default.script file and you are good to go: > > ... > > And what would it be using the ip command instead? I don't know enough > about this... :/ I just did a bit of testing, and the script actually works this time. :) -Erik -- Erik B. Andersen http://codepoet-consulting.com/ --This message was written using 73% post-consumer electrons--
#!/bin/sh
# udhcpc script using iproute by Erik Andersen <andersee@debian.org>
# Remove annoying white space
IPADDR=`echo $ip|sed -e s/\ //g`
count_bits () {
case $1 in
0.0.0.0) echo "$IPADDR/0" ;;
128.0.0.0) echo "$IPADDR/1" ;;
192.0.0.0) echo "$IPADDR/2" ;;
224.0.0.0) echo "$IPADDR/3" ;;
240.0.0.0) echo "$IPADDR/4" ;;
248.0.0.0) echo "$IPADDR/5" ;;
252.0.0.0) echo "$IPADDR/6" ;;
254.0.0.0) echo "$IPADDR/7" ;;
255.0.0.0) echo "$IPADDR/8" ;;
255.128.0.0) echo "$IPADDR/9" ;;
255.192.0.0) echo "$IPADDR/10" ;;
255.224.0.0) echo "$IPADDR/11" ;;
255.240.0.0) echo "$IPADDR/12" ;;
255.248.0.0) echo "$IPADDR/13" ;;
255.252.0.0) echo "$IPADDR/14" ;;
255.254.0.0) echo "$IPADDR/15" ;;
255.255.0.0) echo "$IPADDR/16" ;;
255.255.128.0) echo "$IPADDR/17" ;;
255.255.192.0) echo "$IPADDR/18" ;;
255.255.224.0) echo "$IPADDR/19" ;;
255.255.240.0) echo "$IPADDR/20" ;;
255.255.248.0) echo "$IPADDR/21" ;;
255.255.252.0) echo "$IPADDR/22" ;;
255.255.254.0) echo "$IPADDR/23" ;;
255.255.255.0) echo "$IPADDR/24" ;;
255.255.255.128) echo "$IPADDR/25" ;;
255.255.255.192) echo "$IPADDR/26" ;;
255.255.255.224) echo "$IPADDR/27" ;;
255.255.255.240) echo "$IPADDR/28" ;;
255.255.255.248) echo "$IPADDR/29" ;;
255.255.255.252) echo "$IPADDR/30" ;;
255.255.255.254) echo "$IPADDR/31" ;;
255.255.255.255) echo "$IPADDR/32" ;;
*) echo "$IPADDR/32" ;;
esac
}
[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1
RESOLV_CONF="/etc/resolv.conf"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && IPADDR=`count_bits $subnet`
case "$1" in
deconfig)
/bin/ip link set $interface up
;;
renew|bound)
/bin/ip addr flush dev $interface
/bin/ip addr add $IPADDR dev $interface $BROADCAST
if [ -n "$router" ] ; then
for i in $router ; do
/bin/ip route add default via $i dev $interface
done
fi
if [ -n "$hostname" ]; then
hostname $hostname
fi
echo "# Generated automatically by udhcpc" > $RESOLV_CONF
echo "" >> $RESOLV_CONF
if [ -n "$domain" ] ; then
echo search $domain >> $RESOLV_CONF
fi
for i in $dns ; do
echo nameserver $i >> $RESOLV_CONF
done
;;
esac
exit 0
Attachment:
pgpsLz4r9BHsD.pgp
Description: PGP signature