-
Notifications
You must be signed in to change notification settings - Fork 7
/
udhcpc.script
executable file
·62 lines (52 loc) · 1.59 KB
/
udhcpc.script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
# udhcpc script edited by Tim Riker <Tim@Rikers.org>
#
# IPv6 support added by Alexander Williams <license@unscramble.jp>
#
# GPL-V2 License
[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1
RESOLV_CONF="/etc/resolv.conf"
IP_COMMAND="/usr/local/sbin/ip"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"
case "$1" in
deconfig)
/sbin/ifconfig $interface 0.0.0.0
[ -f "$IP_COMMAND" ] && $IP_COMMAND -6 addr flush dev $interface
;;
renew|bound)
# flush routes first
if [ -n "$router" ] ; then
echo "deleting routers"
while route del default gw 0.0.0.0 dev $interface ; do
:
done
[ -n "$subnet_ipv6" ] && $IP_COMMAND -6 route flush dev $interface
fi
echo "adding ip $ip"
if [ -n "$subnet_ipv6" ]; then
$IP_COMMAND -6 addr add ${ip}${subnet_ipv6} dev $interface
else
/sbin/ifconfig $interface $ip $BROADCAST $NETMASK
fi
/sbin/ifconfig $interface | grep -q "inet addr"
if [ -n "$router" ] ; then
metric=0
for i in $router ; do
echo "adding routers $i"
if [ -n "$subnet_ipv6" ]; then
route -A inet6 add default gw $i dev $interface metric $((metric++))
else
route add default gw $i dev $interface metric $((metric++))
fi
done
fi
[ -n "$domain" ] || [ -n "$dns" ] && echo -n > $RESOLV_CONF
[ -n "$domain" ] && echo search $domain >> $RESOLV_CONF
for i in $dns ; do
echo "adding dns $i"
echo nameserver $i >> $RESOLV_CONF
done
;;
esac
exit 0