Glenn L McGrath | 419eed7 | 2002-08-21 14:24:38 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Sample udhcpc renew script |
| 3 | |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 4 | RESOLV_CONF="/etc/udhcpc/resolv.conf" |
Glenn L McGrath | 419eed7 | 2002-08-21 14:24:38 +0000 | [diff] [blame] | 5 | |
| 6 | [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast" |
| 7 | [ -n "$subnet" ] && NETMASK="netmask $subnet" |
| 8 | |
Denys Vlasenko | 1b367cb | 2020-12-13 21:35:26 +0100 | [diff] [blame] | 9 | ifconfig $interface $ip $BROADCAST $NETMASK |
Glenn L McGrath | 419eed7 | 2002-08-21 14:24:38 +0000 | [diff] [blame] | 10 | |
| 11 | if [ -n "$router" ] |
| 12 | then |
| 13 | echo "deleting routers" |
Denys Vlasenko | 1b367cb | 2020-12-13 21:35:26 +0100 | [diff] [blame] | 14 | while route del default gw 0.0.0.0 dev $interface |
Glenn L McGrath | 419eed7 | 2002-08-21 14:24:38 +0000 | [diff] [blame] | 15 | do : |
| 16 | done |
| 17 | |
Eric Andersen | 1aee3ff | 2004-10-13 07:18:05 +0000 | [diff] [blame] | 18 | metric=0 |
Glenn L McGrath | 419eed7 | 2002-08-21 14:24:38 +0000 | [diff] [blame] | 19 | for i in $router |
| 20 | do |
Denys Vlasenko | 9c192e7 | 2017-04-06 00:53:43 +0200 | [diff] [blame] | 21 | if [ "$subnet" = "255.255.255.255" ]; then |
| 22 | # special case for /32 subnets: |
| 23 | # /32 instructs kernel to always use routing for all outgoing packets |
| 24 | # (they can never be sent to local subnet - there is no local subnet for /32). |
| 25 | # Used in datacenters, avoids the need for private ip-addresses between two hops. |
Denys Vlasenko | 1b367cb | 2020-12-13 21:35:26 +0100 | [diff] [blame] | 26 | ip route add $i dev $interface |
Denys Vlasenko | 9c192e7 | 2017-04-06 00:53:43 +0200 | [diff] [blame] | 27 | fi |
Denys Vlasenko | 1b367cb | 2020-12-13 21:35:26 +0100 | [diff] [blame] | 28 | route add default gw $i dev $interface metric $((metric++)) |
Glenn L McGrath | 419eed7 | 2002-08-21 14:24:38 +0000 | [diff] [blame] | 29 | done |
| 30 | fi |
| 31 | |
Denys Vlasenko | 9c192e7 | 2017-04-06 00:53:43 +0200 | [diff] [blame] | 32 | # Only replace resolv.conf if we have at least one DNS server |
Denys Vlasenko | 2e66dac | 2014-01-13 13:38:53 +0100 | [diff] [blame] | 33 | if [ -n "$dns" ] |
| 34 | then |
| 35 | echo -n > $RESOLV_CONF |
| 36 | [ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF |
| 37 | for i in $dns |
| 38 | do |
| 39 | echo adding dns $i |
| 40 | echo nameserver $i >> $RESOLV_CONF |
| 41 | done |
| 42 | fi |