Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 1 | #!/bin/sh |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 2 | # udhcpc script edited by Tim Riker <Tim@Rikers.org> |
| 3 | |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 4 | RESOLV_CONF="/etc/resolv.conf" |
Denis Vlasenko | 1b47bbd | 2009-04-21 00:17:00 +0000 | [diff] [blame] | 5 | |
Denys Vlasenko | c8ab67c | 2009-05-10 23:27:43 +0200 | [diff] [blame] | 6 | [ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; } |
Denis Vlasenko | 1b47bbd | 2009-04-21 00:17:00 +0000 | [diff] [blame] | 7 | |
Denis Vlasenko | ea4f084 | 2009-04-16 20:04:09 +0000 | [diff] [blame] | 8 | NETMASK="" |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 9 | [ -n "$subnet" ] && NETMASK="netmask $subnet" |
Denis Vlasenko | ea4f084 | 2009-04-16 20:04:09 +0000 | [diff] [blame] | 10 | BROADCAST="broadcast +" |
| 11 | [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast" |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 12 | |
| 13 | case "$1" in |
| 14 | deconfig) |
Denis Vlasenko | ea4f084 | 2009-04-16 20:04:09 +0000 | [diff] [blame] | 15 | echo "Setting IP address 0.0.0.0 on $interface" |
| 16 | ifconfig $interface 0.0.0.0 |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 17 | ;; |
| 18 | |
| 19 | renew|bound) |
Denis Vlasenko | ea4f084 | 2009-04-16 20:04:09 +0000 | [diff] [blame] | 20 | echo "Setting IP address $ip on $interface" |
| 21 | ifconfig $interface $ip $NETMASK $BROADCAST |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 22 | |
| 23 | if [ -n "$router" ] ; then |
Denis Vlasenko | ea4f084 | 2009-04-16 20:04:09 +0000 | [diff] [blame] | 24 | echo "Deleting routers" |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 25 | while route del default gw 0.0.0.0 dev $interface ; do |
| 26 | : |
| 27 | done |
| 28 | |
Eric Andersen | 1aee3ff | 2004-10-13 07:18:05 +0000 | [diff] [blame] | 29 | metric=0 |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 30 | for i in $router ; do |
Denis Vlasenko | ea4f084 | 2009-04-16 20:04:09 +0000 | [diff] [blame] | 31 | echo "Adding router $i" |
Denys Vlasenko | 9c192e7 | 2017-04-06 00:53:43 +0200 | [diff] [blame^] | 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++)) |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 40 | done |
| 41 | fi |
| 42 | |
Denis Vlasenko | ea4f084 | 2009-04-16 20:04:09 +0000 | [diff] [blame] | 43 | echo "Recreating $RESOLV_CONF" |
Mike Frysinger | 39b8fb4 | 2013-02-27 01:01:43 -0500 | [diff] [blame] | 44 | # If the file is a symlink somewhere (like /etc/resolv.conf |
| 45 | # pointing to /run/resolv.conf), make sure things work. |
Mike Frysinger | bca5c55 | 2013-03-12 10:48:09 -0400 | [diff] [blame] | 46 | realconf=$(readlink -f "$RESOLV_CONF" 2>/dev/null || echo "$RESOLV_CONF") |
Mike Frysinger | 39b8fb4 | 2013-02-27 01:01:43 -0500 | [diff] [blame] | 47 | tmpfile="$realconf-$$" |
| 48 | > "$tmpfile" |
| 49 | [ -n "$domain" ] && echo "search $domain" >> "$tmpfile" |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 50 | for i in $dns ; do |
Denis Vlasenko | ea4f084 | 2009-04-16 20:04:09 +0000 | [diff] [blame] | 51 | echo " Adding DNS server $i" |
Mike Frysinger | 39b8fb4 | 2013-02-27 01:01:43 -0500 | [diff] [blame] | 52 | echo "nameserver $i" >> "$tmpfile" |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 53 | done |
Mike Frysinger | 39b8fb4 | 2013-02-27 01:01:43 -0500 | [diff] [blame] | 54 | mv "$tmpfile" "$realconf" |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 55 | ;; |
| 56 | esac |
| 57 | |
| 58 | exit 0 |