2 # dhclient-script for Linux. Dan Halbert, March, 1997.
3 # Updated for Linux 2.[12] by Brian J. Murrell, January 1999.
7 # 0. This script is based on the netbsd script supplied with dhcp-970306.
9 # 1. This script was modified to work with iproute2
11 if [ -n "$dhc_dbus" -a -x /usr/bin/dbus-send ]; then
14 --dest=com.redhat.dhcp \
16 /com/redhat/dhcp/$interface \
18 'string:'"$(unset PATH SHLVL _ PWD dhc_dbus ; env)"
20 if [ $(($dhc_dbus & 31)) -eq 31 ]; then
29 local netmask=$(echo $1)
34 for n in $netmask ; do
35 for i in 128 64 32 16 8 4 2 1 ; do
36 if [ $(($n & $i)) -ne 0 ]; then
37 if [ $endp -eq 0 ]; then
52 if [ -n "$new_domain_name_servers" ]; then
53 :> /etc/resolv.conf.dhclient
54 chmod 644 /etc/resolv.conf.dhclient
55 if [ -n "$new_domain_search" ]; then
56 echo search $new_domain_search >> /etc/resolv.conf.dhclient
57 elif [ -n "$new_domain_name" ]; then
58 # Note that the DHCP 'Domain Name Option' is really just a domain
59 # name, and that this practice of using the domain name option as
60 # a search path is both nonstandard and deprecated.
61 echo search $new_domain_name >> /etc/resolv.conf.dhclient
63 for nameserver in $new_domain_name_servers; do
64 echo nameserver $nameserver >>/etc/resolv.conf.dhclient
66 mv /etc/resolv.conf.dhclient /etc/resolv.conf
67 elif [ -n "${new_dhcp6_name_servers}" ] ; then
68 :> /etc/resolv.conf.dhclient6
69 chmod 644 /etc/resolv.conf.dhclient6
71 if [ "x${new_dhcp6_domain_search}" != x ] ; then
72 echo search ${new_dhcp6_domain_search} >> /etc/resolv.conf.dhclient6
74 for nameserver in ${new_dhcp6_name_servers} ; do
75 echo nameserver ${nameserver} >> /etc/resolv.conf.dhclient6
77 mv /etc/resolv.conf.dhclient6 /etc/resolv.conf
81 # Must be used on exit.
82 # Invokes the local dhcp client exit hooks, if any.
85 if [ -f /etc/dhclient-exit-hooks ]; then
86 . /etc/dhclient-exit-hooks
88 # probably should do something with exit status of the local script
93 # Invoke the local dhcp client enter hooks, if they exist.
94 if [ -f /etc/dhclient-enter-hooks ]; then
96 . /etc/dhclient-enter-hooks
97 # allow the local script to abort processing of this state
98 # local script must set exit_status variable to nonzero.
99 if [ $exit_status -ne 0 ]; then
108 if [ -n "$new_broadcast_address" ]; then
109 new_broadcast_arg="broadcast $new_broadcast_address"
111 if [ -n "$old_broadcast_address" ]; then
112 old_broadcast_arg="broadcast $old_broadcast_address"
114 if [ -n "$new_subnet_mask" ]; then
115 new_subnet_arg="$(calc_prefix $new_subnet_mask)"
117 if [ -n "$old_subnet_mask" ]; then
118 old_subnet_arg="$(calc_prefix $old_subnet_mask)"
120 if [ -n "$alias_subnet_mask" ]; then
121 alias_subnet_arg="$(calc_prefix $alias_subnet_mask)"
123 [ -z "new_subnet_arg" ] && $new_subnet_arg="32"
124 [ -z "old_subnet_arg" ] && $old_subnet_arg="32"
125 [ -z "alias_subnet_arg" ] && $alias_subnet_arg="32"
129 # Linux doesn't do mediums (ok, ok, media).
133 if [ -n "$alias_ip_address" ]; then
134 /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
136 /sbin/ip link set $interface up
138 # We need to give the kernel some time to get the interface up.
142 BOUND|RENEW|REBIND|REBOOT)
143 current_hostname=`hostname`
144 if [ -z "$current_hostname" ]; then
145 hostname $new_host_name
146 elif [ "$current_hostname" = "$old_host_name" -a \
147 "$new_host_name" != "$old_host_name" ]; then
148 hostname $new_host_name
151 if [ -n "$old_ip_address" -a -n "$alias_ip_address" -a \
152 "$alias_ip_address" != "$old_ip_address" ]; then
153 # Possible new alias. Remove old alias.
154 /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
156 if [ -n "$old_ip_address" -a "$old_ip_address" != "$new_ip_address" ]; then
157 # IP address changed.
158 /sbin/ip addr del $old_ip_address/$old_subnet_arg dev $interface
159 for router in $old_routers; do
160 /sbin/ip route del default via $router
162 if [ -n "$old_static_routes" ]; then
163 set -- $old_static_routes
164 while [ $# -gt 1 ]; do
165 /sbin/ip route del $1 via $2
170 if [ -z "$old_ip_address" -o "$old_ip_address" != "$new_ip_address" -o \
171 "$reason" = "BOUND" -o "$reason" = "REBOOT" ]; then
172 /sbin/ip addr add $new_ip_address/$new_subnet_arg $new_broadcast_arg dev $interface
173 # Add a network route to the computed network address.
174 for router in $new_routers; do
175 /sbin/ip route add default via $router
177 if [ -n "$new_static_routes" ]; then
178 set -- $new_static_routes
179 while [ $# -gt 1 ]; do
180 /sbin/ip route add $1 via $2
185 if [ -n "$alias_ip_address" -a "$new_ip_address" != "$alias_ip_address" ]; then
186 /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
191 EXPIRE|FAIL|RELEASE|STOP)
192 if [ -n "$alias_ip_address" ]; then
193 # Turn off alias interface.
194 /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
196 if [ -n "$old_ip_address" ]; then
197 /sbin/ip addr del $old_ip_address/$old_subnet_arg dev $interface
198 for router in $old_routers; do
199 /sbin/ip route del default via $router
201 if [ -n "$old_static_routes" ]; then
202 set -- $old_static_routes
203 while [ $# -gt 1 ]; do
204 /sbin/ip route del $1 via $2
209 if [ -n "$alias_ip_address" ]; then
210 /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
215 if [ -n "$alias_ip_address" ]; then
216 /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
218 /sbin/ip addr add $new_ip_address/$new_subnet_arg $new_broadcast_arg dev $interface
221 if ping -q -c 1 $1; then
222 if [ "$new_ip_address" != "$alias_ip_address" ] && \
223 [ -n "$alias_ip_address" ]; then
224 /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
226 for router in $new_routers; do
227 /sbin/ip route add default via $router
229 if [ -n "$new_static_routes" ]; then
230 set -- $new_static_routes
231 while [ $# -gt 1 ]; do
232 /sbin/ip route add $1 via $2
240 /sbin/ip addr del $new_ip_address/$new_subnet_arg dev $interface
241 for router in $old_routers; do
242 /sbin/ip route del default via $router
244 if [ -n "$old_static_routes" ]; then
245 set -- $old_static_routes
246 while [ $# -gt 1 ]; do
247 /sbin/ip route del $1 via $2
255 # Ensure interface is up.
256 /sbin/ip link set ${interface} up
258 # Remove any stale addresses from aborted clients.
259 /sbin/ip -f inet6 addr flush dev ${interface} scope global permanent
264 if [ x${new_ip6_address} = x ] || [ x${new_ip6_prefixlen} = x ] ; then
268 /sbin/ip -f inet6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \
269 dev ${interface} scope global
271 # Check for nameserver options.
278 # Make sure nothing has moved around on us.
280 # Nameservers/domains/etc.
281 if [ "x${new_dhcp6_name_servers}" != "x${old_dhcp6_name_servers}" ] ||
282 [ "x${new_dhcp6_domain_search}" != "x${old_dhcp6_domain_search}" ] ; then
290 if [ x${new_ip6_prefixlen} = x ] ; then
294 # There doesn't appear to be a way to update an addr to indicate
296 # /sbin/ip -f inet6 addr ??? ${new_ip6_address}/${new_ip6_prefixlen} \
297 # dev ${interface} scope global deprecated?
302 EXPIRE6|RELEASE6|STOP6)
303 if [ x${old_ip6_address} = x ] || [ x${old_ip6_prefixlen} = x ] ; then
307 /sbin/ip -f inet6 addr del ${old_ip6_address}/${old_ip6_prefixlen} \