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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
#!/bin/sh
set -e
# reduced dhclient-script for the Debian installer
# changes by Joshua Kwan <joshk@triplehelix.org>,
# Bastian Blank <waldi@debian.org>
# dhclient-script for Linux. Dan Halbert, March, 1997.
# Updated for Linux 2.[12] by Brian J. Murrell, January 1999.
# Modified for Debian. Matt Zimmerman and Eloy Paris, December 2003
make_resolv_conf() {
if [ -n "$new_domain_name" ] || [ -n "$new_domain_name_servers" ]; then
local new_resolv_conf=/etc/resolv.conf.dhclient-new
rm -f $new_resolv_conf
if [ -n "$new_domain_name" ]; then
echo "search $new_domain_name" >>$new_resolv_conf
fi
for nameserver in $new_domain_name_servers; do
echo "nameserver $nameserver" >>$new_resolv_conf
done
mv $new_resolv_conf /etc/resolv.conf
fi
}
set_hostname() {
local current_hostname=$(cat /proc/sys/kernel/hostname)
if [ -z "$current_hostname" ] || [ "$current_hostname" = "(none)" ]; then
echo "$new_host_name" > /proc/sys/kernel/hostname
fi
}
if [ -n "$new_subnet_mask" ]; then
new_mask="/$(ptom $new_subnet_mask)"
fi
if [ -n "$old_subnet_mask" ]; then
old_mask="/$(ptom $old_subnet_mask)"
fi
if [ -n "$new_broadcast_address" ]; then
new_broadcast_arg="broadcast $new_broadcast_address"
fi
if [ -n "$old_broadcast_address" ]; then
old_broadcast_arg="broadcast $old_broadcast_address"
fi
# Execute the operation
case "$reason" in
MEDIUM|ARPCHECK|ARPSEND)
# Do nothing
;;
PREINIT)
ip link set $interface up
# We need to give the kernel some time to get the interface up.
sleep 1
;;
BOUND|RENEW|REBIND|REBOOT)
set_hostname
if [ -n "$old_ip_address" ] && \
[ "$old_ip_address" != "$new_ip_address" ]; then
# IP address changed. Bringing down the interface will delete all routes,
# and clear the ARP cache.
ip addr del $old_ip_address$old_mask $old_broadcast_arg dev $interface
ip link set $interface down
fi
if [ -n "$new_interface_mtu" ]; then
ip link set $interface mtu $new_interface_mtu || true
fi
if [ -z "$old_ip_address" ] || [ "$old_ip_address" != "$new_ip_address" ] || \
[ "$reason" = "BOUND" ] || [ "$reason" = "REBOOT" ]; then
ip link set $interface up
ip addr flush dev $interface
ip addr add $new_ip_address$new_mask $new_broadcast_arg dev $interface
for router in $new_routers; do
ip route add default via $router
done
fi
make_resolv_conf
# Get the domain name into a file suitable for netcfg to read.
echo -n "$new_domain_name" > /tmp/domain_name
;;
EXPIRE|FAIL|RELEASE|STOP)
if [ -n "$old_ip_address" ]; then
# Shut down interface, which will delete routes and clear arp cache.
ip addr flush dev $interface
ip link set $interface down
fi
;;
TIMEOUT)
ip link set $interface down
;;
esac
exit 0
|