default.script (1623B)
1 #!/bin/sh 2 # udhcpc script edited by Tim Riker <Tim@Rikers.org> 3 4 RESOLV_CONF="/etc/resolv.conf" 5 6 [ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; } 7 8 NETMASK="" 9 [ -n "$subnet" ] && NETMASK="netmask $subnet" 10 BROADCAST="broadcast +" 11 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast" 12 13 case "$1" in 14 deconfig) 15 echo "Setting IP address 0.0.0.0 on $interface" 16 ifconfig $interface 0.0.0.0 17 ;; 18 19 renew|bound) 20 echo "Setting IP address $ip on $interface" 21 ifconfig $interface $ip $NETMASK $BROADCAST 22 23 if [ -n "$router" ] ; then 24 echo "Deleting routers" 25 while route del default gw 0.0.0.0 dev $interface ; do 26 : 27 done 28 29 metric=0 30 for i in $router ; do 31 echo "Adding router $i" 32 if [ "$subnet" = "255.255.255.255" ]; then 33 # special case for /32 subnets: 34 # /32 instructs kernel to always use routing for all outgoing packets 35 # (they can never be sent to local subnet - there is no local subnet for /32). 36 # Used in datacenters, avoids the need for private ip-addresses between two hops. 37 ip route add $i dev $interface 38 fi 39 route add default gw $i dev $interface metric $((metric++)) 40 done 41 fi 42 43 echo "Recreating $RESOLV_CONF" 44 # If the file is a symlink somewhere (like /etc/resolv.conf 45 # pointing to /run/resolv.conf), make sure things work. 46 realconf=$(readlink -f "$RESOLV_CONF" 2>/dev/null || echo "$RESOLV_CONF") 47 tmpfile="$realconf-$$" 48 > "$tmpfile" 49 [ -n "$domain" ] && echo "search $domain" >> "$tmpfile" 50 for i in $dns ; do 51 echo " Adding DNS server $i" 52 echo "nameserver $i" >> "$tmpfile" 53 done 54 mv "$tmpfile" "$realconf" 55 ;; 56 esac 57 58 exit 0