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