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.
86 for i in /etc/dhclient-exit-hooks.d/*[!~,] ; do
87 [ -f "$i" ] || continue
88 # Don't run *.{rpmsave,rpmorig,rpmnew,swp} scripts
89 [ "${i%.rpmsave}" != "${i}" ] && continue
90 [ "${i%.rpmorig}" != "${i}" ] && continue
91 [ "${i%.rpmnew}" != "${i}" ] && continue
92 [ "${i%.swp}" != "${i}" ] && continue
93 [ "${i%,v}" != "${i}" ] && continue
97 # probably should do something with exit status of the local script
102 for i in /etc/dhclient-enter-hooks.d/*[!~,] ; do
103 [ -f "$i" ] || continue
104 # Don't run *.{rpmsave,rpmorig,rpmnew,swp} scripts
105 [ "${i%.rpmsave}" != "${i}" ] && continue
106 [ "${i%.rpmorig}" != "${i}" ] && continue
107 [ "${i%.rpmnew}" != "${i}" ] && continue
108 [ "${i%.swp}" != "${i}" ] && continue
109 [ "${i%,v}" != "${i}" ] && continue
113 if [ $exit_status -ne 0 ]; then
122 if [ -n "$new_broadcast_address" ]; then
123 new_broadcast_arg="broadcast $new_broadcast_address"
125 if [ -n "$old_broadcast_address" ]; then
126 old_broadcast_arg="broadcast $old_broadcast_address"
128 if [ -n "$new_subnet_mask" ]; then
129 new_subnet_arg="$(calc_prefix $new_subnet_mask)"
131 if [ -n "$old_subnet_mask" ]; then
132 old_subnet_arg="$(calc_prefix $old_subnet_mask)"
134 if [ -n "$alias_subnet_mask" ]; then
135 alias_subnet_arg="$(calc_prefix $alias_subnet_mask)"
137 [ -z "new_subnet_arg" ] && $new_subnet_arg="32"
138 [ -z "old_subnet_arg" ] && $old_subnet_arg="32"
139 [ -z "alias_subnet_arg" ] && $alias_subnet_arg="32"
143 # Linux doesn't do mediums (ok, ok, media).
147 if [ -n "$alias_ip_address" ]; then
148 /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
150 /sbin/ip link set $interface up
152 # We need to give the kernel some time to get the interface up.
156 BOUND|RENEW|REBIND|REBOOT)
157 current_hostname=`hostname`
158 if [ -z "$current_hostname" ]; then
159 hostname $new_host_name
160 elif [ "$current_hostname" = "$old_host_name" -a \
161 "$new_host_name" != "$old_host_name" ]; then
162 hostname $new_host_name
165 if [ -n "$old_ip_address" -a -n "$alias_ip_address" -a \
166 "$alias_ip_address" != "$old_ip_address" ]; then
167 # Possible new alias. Remove old alias.
168 /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
170 if [ -n "$old_ip_address" -a "$old_ip_address" != "$new_ip_address" ]; then
171 # IP address changed.
172 /sbin/ip addr del $old_ip_address/$old_subnet_arg dev $interface
173 for router in $old_routers; do
174 /sbin/ip route del default via $router
176 if [ -n "$old_static_routes" ]; then
177 set -- $old_static_routes
178 while [ $# -gt 1 ]; do
179 /sbin/ip route del $1 via $2
184 if [ -z "$old_ip_address" -o "$old_ip_address" != "$new_ip_address" -o \
185 "$reason" = "BOUND" -o "$reason" = "REBOOT" ]; then
186 /sbin/ip addr add $new_ip_address/$new_subnet_arg $new_broadcast_arg dev $interface
187 # Add a network route to the computed network address.
188 for router in $new_routers; do
189 /sbin/ip route add default via $router
191 if [ -n "$new_static_routes" ]; then
192 set -- $new_static_routes
193 while [ $# -gt 1 ]; do
194 /sbin/ip route add $1 via $2
199 if [ -n "$alias_ip_address" -a "$new_ip_address" != "$alias_ip_address" ]; then
200 /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
205 EXPIRE|FAIL|RELEASE|STOP)
206 if [ -n "$alias_ip_address" ]; then
207 # Turn off alias interface.
208 /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
210 if [ -n "$old_ip_address" ]; then
211 /sbin/ip addr del $old_ip_address/$old_subnet_arg dev $interface
212 for router in $old_routers; do
213 /sbin/ip route del default via $router
215 if [ -n "$old_static_routes" ]; then
216 set -- $old_static_routes
217 while [ $# -gt 1 ]; do
218 /sbin/ip route del $1 via $2
223 if [ -n "$alias_ip_address" ]; then
224 /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
229 if [ -n "$alias_ip_address" ]; then
230 /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
232 /sbin/ip addr add $new_ip_address/$new_subnet_arg $new_broadcast_arg dev $interface
235 if ping -q -c 1 $1; then
236 if [ "$new_ip_address" != "$alias_ip_address" ] && \
237 [ -n "$alias_ip_address" ]; then
238 /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
240 for router in $new_routers; do
241 /sbin/ip route add default via $router
243 if [ -n "$new_static_routes" ]; then
244 set -- $new_static_routes
245 while [ $# -gt 1 ]; do
246 /sbin/ip route add $1 via $2
254 /sbin/ip addr del $new_ip_address/$new_subnet_arg dev $interface
255 for router in $old_routers; do
256 /sbin/ip route del default via $router
258 if [ -n "$old_static_routes" ]; then
259 set -- $old_static_routes
260 while [ $# -gt 1 ]; do
261 /sbin/ip route del $1 via $2
269 # Ensure interface is up.
270 /sbin/ip link set ${interface} up
272 # Remove any stale addresses from aborted clients.
273 /sbin/ip -f inet6 addr flush dev ${interface} scope global permanent
278 if [ x${new_ip6_address} = x ] || [ x${new_ip6_prefixlen} = x ] ; then
282 /sbin/ip -f inet6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \
283 dev ${interface} scope global
285 # Check for nameserver options.
292 # Make sure nothing has moved around on us.
294 # Nameservers/domains/etc.
295 if [ "x${new_dhcp6_name_servers}" != "x${old_dhcp6_name_servers}" ] ||
296 [ "x${new_dhcp6_domain_search}" != "x${old_dhcp6_domain_search}" ] ; then
304 if [ x${new_ip6_prefixlen} = x ] ; then
308 # There doesn't appear to be a way to update an addr to indicate
310 # /sbin/ip -f inet6 addr ??? ${new_ip6_address}/${new_ip6_prefixlen} \
311 # dev ${interface} scope global deprecated?
316 EXPIRE6|RELEASE6|STOP6)
317 if [ x${old_ip6_address} = x ] || [ x${old_ip6_prefixlen} = x ] ; then
321 /sbin/ip -f inet6 addr del ${old_ip6_address}/${old_ip6_prefixlen} \