2002-10-15 03:11:28 +05:30
|
|
|
#!/bin/sh
|
|
|
|
# udhcpc script edited by Tim Riker <Tim@Rikers.org>
|
|
|
|
|
|
|
|
RESOLV_CONF="/etc/resolv.conf"
|
2009-04-21 05:47:00 +05:30
|
|
|
|
2009-05-11 02:57:43 +05:30
|
|
|
[ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; }
|
2009-04-21 05:47:00 +05:30
|
|
|
|
2009-04-17 01:34:09 +05:30
|
|
|
NETMASK=""
|
2018-10-04 12:32:27 +05:30
|
|
|
if command -v ip >/dev/null; then
|
|
|
|
[ -n "$subnet" ] && NETMASK="/$subnet"
|
|
|
|
else
|
|
|
|
[ -n "$subnet" ] && NETMASK="netmask $subnet"
|
|
|
|
fi
|
2009-04-17 01:34:09 +05:30
|
|
|
BROADCAST="broadcast +"
|
|
|
|
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
|
2002-10-15 03:11:28 +05:30
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
deconfig)
|
2019-09-05 18:28:08 +05:30
|
|
|
echo "Clearing IP addresses on $interface, upping it"
|
2018-10-04 12:32:27 +05:30
|
|
|
if command -v ip >/dev/null; then
|
|
|
|
ip addr flush dev $interface
|
2019-09-05 18:28:08 +05:30
|
|
|
ip link set dev $interface up
|
2018-10-04 12:32:27 +05:30
|
|
|
else
|
|
|
|
ifconfig $interface 0.0.0.0
|
|
|
|
fi
|
2002-10-15 03:11:28 +05:30
|
|
|
;;
|
|
|
|
|
|
|
|
renew|bound)
|
2009-04-17 01:34:09 +05:30
|
|
|
echo "Setting IP address $ip on $interface"
|
2018-10-04 12:32:27 +05:30
|
|
|
if command -v ip >/dev/null; then
|
|
|
|
ip addr add $ip$NETMASK $BROADCAST dev $interface
|
|
|
|
else
|
|
|
|
ifconfig $interface $ip $NETMASK $BROADCAST
|
|
|
|
fi
|
2002-10-15 03:11:28 +05:30
|
|
|
|
|
|
|
if [ -n "$router" ] ; then
|
2009-04-17 01:34:09 +05:30
|
|
|
echo "Deleting routers"
|
2002-10-15 03:11:28 +05:30
|
|
|
while route del default gw 0.0.0.0 dev $interface ; do
|
|
|
|
:
|
|
|
|
done
|
|
|
|
|
2004-10-13 12:48:05 +05:30
|
|
|
metric=0
|
2002-10-15 03:11:28 +05:30
|
|
|
for i in $router ; do
|
2009-04-17 01:34:09 +05:30
|
|
|
echo "Adding router $i"
|
2017-04-06 04:23:43 +05:30
|
|
|
if [ "$subnet" = "255.255.255.255" ]; then
|
|
|
|
# special case for /32 subnets:
|
|
|
|
# /32 instructs kernel to always use routing for all outgoing packets
|
|
|
|
# (they can never be sent to local subnet - there is no local subnet for /32).
|
|
|
|
# Used in datacenters, avoids the need for private ip-addresses between two hops.
|
|
|
|
ip route add $i dev $interface
|
|
|
|
fi
|
|
|
|
route add default gw $i dev $interface metric $((metric++))
|
2002-10-15 03:11:28 +05:30
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2013-02-27 11:31:43 +05:30
|
|
|
# If the file is a symlink somewhere (like /etc/resolv.conf
|
|
|
|
# pointing to /run/resolv.conf), make sure things work.
|
2019-03-28 19:59:29 +05:30
|
|
|
if test -L "$RESOLV_CONF"; then
|
|
|
|
# If it's a dangling symlink, try to create the target.
|
|
|
|
test -e "$RESOLV_CONF" || touch "$RESOLV_CONF"
|
|
|
|
fi
|
2013-03-12 20:18:09 +05:30
|
|
|
realconf=$(readlink -f "$RESOLV_CONF" 2>/dev/null || echo "$RESOLV_CONF")
|
2019-08-13 21:11:56 +05:30
|
|
|
echo "Recreating $realconf"
|
2013-02-27 11:31:43 +05:30
|
|
|
tmpfile="$realconf-$$"
|
|
|
|
> "$tmpfile"
|
|
|
|
[ -n "$domain" ] && echo "search $domain" >> "$tmpfile"
|
2002-10-15 03:11:28 +05:30
|
|
|
for i in $dns ; do
|
2009-04-17 01:34:09 +05:30
|
|
|
echo " Adding DNS server $i"
|
2013-02-27 11:31:43 +05:30
|
|
|
echo "nameserver $i" >> "$tmpfile"
|
2002-10-15 03:11:28 +05:30
|
|
|
done
|
2013-02-27 11:31:43 +05:30
|
|
|
mv "$tmpfile" "$realconf"
|
2002-10-15 03:11:28 +05:30
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|