2 # udhcpc script edited by Tim Riker <Tim@Rikers.org>
4 RESOLV_CONF
="/etc/resolv.conf"
6 [ -n "$1" ] ||
{ echo "Error: should be called from udhcpc"; exit 1; }
9 if command -v ip
>/dev
/null
; then
10 [ -n "$subnet" ] && NETMASK
="/$subnet"
12 [ -n "$subnet" ] && NETMASK
="netmask $subnet"
14 BROADCAST
="broadcast +"
15 [ -n "$broadcast" ] && BROADCAST
="broadcast $broadcast"
19 echo "Clearing IP addresses on $interface, upping it"
20 if command -v ip
>/dev
/null
; then
21 ip
-4 addr flush dev
$interface
22 ip link
set dev
$interface up
24 ifconfig
$interface 0.0.0.0
29 echo "Setting IP address $ip on $interface"
30 if command -v ip
>/dev
/null
; then
31 ip addr add
$ip$NETMASK $BROADCAST dev
$interface
33 ifconfig
$interface $ip $NETMASK $BROADCAST
36 if [ -n "$router" ] ; then
37 echo "Deleting routers"
38 while route del default gw
0.0.0.0 dev
$interface ; do
44 echo "Adding router $i"
45 if [ "$subnet" = "255.255.255.255" ]; then
46 # special case for /32 subnets:
47 # /32 instructs kernel to always use routing for all outgoing packets
48 # (they can never be sent to local subnet - there is no local subnet for /32).
49 # Used in datacenters, avoids the need for private ip-addresses between two hops.
50 ip route add
$i dev
$interface
52 route add default gw
$i dev
$interface metric $
((metric
++))
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"
62 realconf
=$
(readlink
-f "$RESOLV_CONF" 2>/dev
/null ||
echo "$RESOLV_CONF")
63 echo "Recreating $realconf"
64 tmpfile
="$realconf-$$"
66 [ -n "$domain" ] && echo "search $domain" >> "$tmpfile"
68 echo " Adding DNS server $i"
69 echo "nameserver $i" >> "$tmpfile"
71 mv "$tmpfile" "$realconf"