]>
git.ipfire.org Git - thirdparty/dhcp.git/blob - client/scripts/linux
2 # dhclient-script for Linux. Dan Halbert, March, 1997.
3 # Updated for Linux 2.[12] by Brian J. Murrell, January 1999.
4 # No guarantees about this. I'm a novice at the details of Linux
9 # 0. This script is based on the netbsd script supplied with dhcp-970306.
11 # 1. ifconfig down apparently deletes all relevant routes and flushes
12 # the arp cache, so this doesn't need to be done explicitly.
14 # 2. The alias address handling here has not been tested AT ALL.
15 # I'm just going by the doc of modern Linux ip aliasing, which uses
16 # notations like eth0:0, eth0:1, for each alias.
18 # 3. I have to calculate the network address, and calculate the broadcast
19 # address if it is not supplied. This might be much more easily done
20 # by the dhclient C code, and passed on.
22 # 4. TIMEOUT not tested. ping has a flag I don't know, and I'm suspicious
23 # of the $1 in its args.
26 if [ x
"$new_domain_name_servers" != x
]; then
27 cat /dev
/null
> /etc
/resolv.conf.dhclient
28 chmod 644 /etc
/resolv.conf.dhclient
29 if [ x
"$new_domain_search" != x
]; then
30 echo search
$new_domain_search >> /etc
/resolv.conf.dhclient
31 elif [ x
"$new_domain_name" != x
]; then
32 # Note that the DHCP 'Domain Name Option' is really just a domain
33 # name, and that this practice of using the domain name option as
34 # a search path is both nonstandard and deprecated.
35 echo search
$new_domain_name >> /etc
/resolv.conf.dhclient
37 for nameserver
in $new_domain_name_servers; do
38 echo nameserver
$nameserver >>/etc
/resolv.conf.dhclient
41 mv /etc
/resolv.conf.dhclient
/etc
/resolv.conf
45 # Must be used on exit. Invokes the local dhcp client exit hooks, if any.
48 if [ -f /etc
/dhclient-exit-hooks
]; then
49 .
/etc
/dhclient-exit-hooks
51 # probably should do something with exit status of the local script
55 # Invoke the local dhcp client enter hooks, if they exist.
56 if [ -f /etc
/dhclient-enter-hooks
]; then
58 .
/etc
/dhclient-enter-hooks
59 # allow the local script to abort processing of this state
60 # local script must set exit_status variable to nonzero.
61 if [ $exit_status -ne 0 ]; then
67 release
=`expr $release : '\(.*\)\..*'`
68 relminor
=`echo $release |sed -e 's/[0-9]*\.\([0-9][0-9]*\)\(\..*\)*$/\1/'`
69 relmajor
=`echo $release |sed -e 's/\([0-9][0-9]*\)\..*$/\1/'`
71 if [ x
$new_broadcast_address != x
]; then
72 new_broadcast_arg
="broadcast $new_broadcast_address"
74 if [ x
$old_broadcast_address != x
]; then
75 old_broadcast_arg
="broadcast $old_broadcast_address"
77 if [ x
$new_subnet_mask != x
]; then
78 new_subnet_arg
="netmask $new_subnet_mask"
80 if [ x
$old_subnet_mask != x
]; then
81 old_subnet_arg
="netmask $old_subnet_mask"
83 if [ x
$alias_subnet_mask != x
]; then
84 alias_subnet_arg
="netmask $alias_subnet_mask"
87 if [ x
$reason = xMEDIUM
]; then
88 # Linux doesn't do mediums (ok, ok, media).
92 if [ x
$reason = xPREINIT
]; then
93 if [ x
$alias_ip_address != x
]; then
94 # Bring down alias interface. Its routes will disappear too.
95 ifconfig
$interface:0- inet
0
97 if [ $relmajor -lt 2 ] ||
( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] )
99 ifconfig
$interface inet
0.0.0.0 netmask
0.0.0.0 \
100 broadcast
255.255.255.255 up
101 # Add route to make broadcast work. Do not omit netmask.
102 route add default dev
$interface netmask
0.0.0.0
104 ifconfig
$interface 0 up
107 # We need to give the kernel some time to get the interface up.
113 if [ x
$reason = xARPCHECK
] ||
[ x
$reason = xARPSEND
]; then
117 if [ x
$reason = xBOUND
] ||
[ x
$reason = xRENEW
] || \
118 [ x
$reason = xREBIND
] ||
[ x
$reason = xREBOOT
]; then
119 current_hostname
=`hostname`
120 if [ x
$current_hostname = x
] || \
121 [ x
$current_hostname = x
$old_host_name ]; then
122 if [ x
$current_hostname = x
] || \
123 [ x
$new_host_name != x
$old_host_name ]; then
124 hostname
$new_host_name
128 if [ x
$old_ip_address != x
] && [ x
$alias_ip_address != x
] && \
129 [ x
$alias_ip_address != x
$old_ip_address ]; then
130 # Possible new alias. Remove old alias.
131 ifconfig
$interface:0- inet
0
133 if [ x
$old_ip_address != x
] && [ x
$old_ip_address != x
$new_ip_address ]; then
134 # IP address changed. Bringing down the interface will delete all routes,
135 # and clear the ARP cache.
136 ifconfig
$interface inet
0 down
139 if [ x
$old_ip_address = x
] ||
[ x
$old_ip_address != x
$new_ip_address ] || \
140 [ x
$reason = xBOUND
] ||
[ x
$reason = xREBOOT
]; then
142 ifconfig
$interface inet
$new_ip_address $new_subnet_arg \
144 # Add a network route to the computed network address.
145 if [ $relmajor -lt 2 ] || \
146 ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
147 route add
-net $new_network_number $new_subnet_arg dev
$interface
149 for router
in $new_routers; do
150 route add default gw
$router
153 if [ x
$new_ip_address != x
$alias_ip_address ] && [ x
$alias_ip_address != x
];
155 ifconfig
$interface:0- inet
0
156 ifconfig
$interface:0 inet
$alias_ip_address $alias_subnet_arg
157 route add
-host $alias_ip_address $interface:0
163 if [ x
$reason = xEXPIRE
] ||
[ x
$reason = xFAIL
] ||
[ x
$reason = xRELEASE
] \
164 ||
[ x
$reason = xSTOP
]; then
165 if [ x
$alias_ip_address != x
]; then
166 # Turn off alias interface.
167 ifconfig
$interface:0- inet
0
169 if [ x
$old_ip_address != x
]; then
170 # Shut down interface, which will delete routes and clear arp cache.
171 ifconfig
$interface inet
0 down
173 if [ x
$alias_ip_address != x
]; then
174 ifconfig
$interface:0 inet
$alias_ip_address $alias_subnet_arg
175 route add
-host $alias_ip_address $interface:0
180 if [ x
$reason = xTIMEOUT
]; then
181 if [ x
$alias_ip_address != x
]; then
182 ifconfig
$interface:0- inet
0
184 ifconfig
$interface inet
$new_ip_address $new_subnet_arg \
187 ############## what is -w in ping?
188 if ping -q -c 1 $1; then
189 if [ x
$new_ip_address != x
$alias_ip_address ] && \
190 [ x
$alias_ip_address != x
]; then
191 ifconfig
$interface:0 inet
$alias_ip_address $alias_subnet_arg
192 route add
-host $alias_ip_address dev
$interface:0
194 if [ $relmajor -lt 2 ] || \
195 ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
196 route add
-net $new_network_number
198 for router
in $new_routers; do
199 route add default gw
$router
204 ifconfig
$interface inet
0 down