Typo
[linux_from_scratch_hints.git] / OLD / dhcp_client.txt
blobfae9c54e3ac1dfbeee5bd06e51a5bffc6298759f
1 TITLE:          DHCP client daemon
2 LFS VERSION:    2.x-3.1 (all???)
3 AUTHOR:         D.J. Lucas <dj_me@swbell.net>
5 SYNOPSIS:       How to setup a DHCP client daemon. This is used with most 
6                 networking gateways for cable modems and xDSL modems.  Also
7                 used, nowadays, on almost all corporate networks to set up
8                 non mission critical servers and most workstations.
10 HINT:  After reading the dhcpd hints by Simon Perreault <nomis80@videotron.ca>
11 and Thinus Pollard <thinusp@olienhout.org.za>, I had an excelent grasp on the
12 configuration and use of dhcpcd.  I, however, felt the need to expand on their 
13 ideas and incorporate the use of the DHCP client into the ethnet init script.
14 This will both reduce the amount of scripts in the /etc/init.d directory and 
15 symlinks in /etc/init.d/rc?.d, and also allow for easy change back to a static
16 network should the need arise.  
18 NOTE:  Just a basic reminder....because this works on my system, dosen't mean
19 that it will work on yours, tho it should.  Even though these are just script 
20 changes, IT IS ALWAYS A GOOD IDEA TO BACKUP any existing files that will be 
21 changed, deleted, modified, moved, etc....  Also if you used the hint for
22 shadow passwords http://hints.linuxfromscratch.org/hints/shadowpasswd_plus.txt,
23 you'll want to run the configure script below without the --prefix and change
24 the ethnet script below to point to the correct install location.
25 ie: /sbin/dhcpcd as opposed to /usr/sbin/dhcpcd
28 How to install and configure the DHCP client daemon according to the LFS
29 standards.
31 1. Get the current version of dhcpcd at ftp://ftp.phystech.com/pub/ 
32 2. Unpack the archive and install. 
33 ------------------------------------------------------------------------------
34 tar -zxf dhcpcd-1.?.?.pl?  (maybe overstating the obvious...replace the "?"s)
35 cd dhcpcd-1.?.?.pl?
36 ./configure --prefix=/usr
37 make
38 make install
39 ------------------------------------------------------------------------------
40 NOTE:  Although not recomended, if you are using a version older than 
41 dhcpcd-1.3.21-pl1, see the previous dhcp hints (dhcpd.txt and dhcpd2.txt) at: 
42 http://hints.linuxfromscratch.org/hints/old/
44 3. Move the old ethnet script and create the new one.  As you can see I 
45 have included the new variable explanations for the nic-config files 
46 in the script itself for easier administration after the initial setup. 
47 These can be omitted if you like.
48 Run the following commands to backup the old file and create the new one.
49 ______________________________________________________________________________
50 mv /etc/init.d/ethnet /etc/init.d/ethnet.predhcpcd
51 cat > /etc/init.d/ethnet << "EOF"
52 #!/bin/sh
53 # Begin /etc/init.d/ethnet
55 # Main script by Gerard Beekmans - gerard@linuxfromscratch.org
56 # GATEWAY check by Jean-François Le Ray - jfleray@club-internet.fr
57 # "Specify which IF to use to reach default GATEWAY" by
58 # Graham Cantin - gcantin@pacbell.net
59 # DHCP sections added by D.J. Lucas - dj_me@swbell.net
61 # This file has been updated from it's original version to include the use
62 # of dhcpcd to autoconfigure network cards.  Therefore, the structure of the
63 # $DEVICE-config and sysconfig/network files has changed slightly.
64 # The new variable set now uses the following variables:
66 # /etc/$DEVICE-config:
67 # ONBOOT - yes,no - wether to set up the interface at boot
68 # DHCP - yes,no - wether or not to use dhcp
69 # DEVICE - device name (eth0,eth1...etc.) - the device name
70 # IP - IP address of the interface - not used with DHCP
71 # NETMASK - subnet mask of the interface - not used with DHCP
72 # BROADCAST - broadcast address of the interface - not used with DHCP
74 # /etc/sysconfig/network:
75 # HOSTNAME - host name of the machine - must be set
76 # GATEWAY - default gateway of the interface - not used with DHCP
77 # GATEWAY_IF - Interface - sets interface as default gateway for the system
78 #                          not used with DHCP
80 # Hope this makes things a bit more clear as my if/then/else statments are a
81 # little hard to follow.  Note:  the script will fail if both the GATEWAY_IF
82 # and the GW variables are set, or if both the GATEWAY and the GW variables
83 # are set.
85 # End of my additions...send any questions to DJ_Me@swbell.net.
87 # Include the functions declared in the /etc/init.d/functions file
88 # and the variables from the /etc/sysconfig/network file.
91 source /etc/init.d/functions
92 source /etc/sysconfig/network
94 case "$1" in
95         start)
98 # Obtain all the network card configuration files
101         for interface in $(/bin/ls /etc/sysconfig/nic-config/ifcfg* | \
102             grep -v ifcfg-lo)
103         do
105 # Load the variables from that file
108             source $interface
110 # If the ONBOOT variable is set to yes, process this file and bring the
111 # interface up.
113 # Added for DHCP using dhcpcd:
114 # If the DHCP variable is set to yes, the if/then/else statements below
115 # will force the use of dhcpcd instead of ifconfig.
116 # End Addition
119             if [ "$ONBOOT" == yes ]
120             then
121                if [ "$DHCP" == yes ]
122                then
123                   echo -n "Bringing up the $DEVICE interface using DHCP..."
124                   /usr/sbin/dhcpcd $DEVICE
125                   evaluate_retval
126                else
127                    echo -n "Bringing up the $DEVICE interface..."
128                    /sbin/ifconfig $DEVICE $IP broadcast $BROADCAST \
129                        netmask $NETMASK
130                    evaluate_retval
131                fi
132             fi
133         done
136 # If the /etc/sysconfig/network file contains a GATEWAY variable, set
137 # the default gateway and the interface through which the default
138 # gateway can be reached.
140 # Added for DHCP using dhcpcd:
141 # If the default gateway device is to be set up using DHCP, then the
142 # GATEWAY and GATEWAY_IF variables should not be used as dhcpcd takes care
143 # of setting up the default route.
144 # End Addition
147             if [ "$GATEWAY" != "" ]
148             then
149                    echo -n "Setting up routing for $GATEWAY_IF interface..."
150                    /sbin/route add default gateway $GATEWAY \
151                            metric 1 dev $GATEWAY_IF
152                    evaluate_retval
153             fi
154                 ;;
156         stop)
159 # Obtain all the network card configuration files
162         for interface in $(/bin/ls /etc/sysconfig/nic-config/ifcfg* | \
163             grep -v ifcfg-lo)
164         do
166 # Load the variables from that file
169             source $interface
171 # If the ONBOOT variable is set, process the file and bring the
172 # interface down
173 # If the DHCP variable is set to yes, then use dhcpcd to bring the
174 # interface down instead of ifconfig.
176             if [ $ONBOOT == yes ]
177             then
178                 if [ $DHCP == yes ]
179                 then
180                     echo -n "Bringing down the $DEVICE interface..."
181                     /usr/sbin/dhcpcd -k $DEVICE
182                     evaluate_retval
183                 else
184                     echo -n "Bringing down the $DEVICE interface..."
185                     /sbin/ifconfig $DEVICE down
186                     evaluate_retval
187                 fi
188             fi
189         done
190                 ;;
192         restart)
193                 $0 stop
194                 sleep 1
195                 $0 start
196                 ;;
197         *)
198                 echo "Usage: $0 {start|stop|restart}"
199                 exit 1
200                 ;;
201 esac
203 # End /etc/init.d/ethnet
205 chmod +x /etc/init.d/ethnet
206 ______________________________________________________________________________
208 4.  Create the updated nic-config files.  Decide which interface(s) will now
209 use DHCP and create the files.  On devices that will use static information,
210 you will use the old config files as created in the LFS book.  
211 MAKE BACKUP COPIES of the config files that are going to be replaced.
212 In the new files there will only be 3 variables set.  Here is a copy of my 
213 /etc/sysconfig/nic-config/ifcfg-eth0 file.
214 ______________________________________________________________________________
215 ONBOOT=yes
216 DEVICE=eth0
217 DHCP=yes
218 ______________________________________________________________________________
219 The ONBOOT variale tells the ethnet script wether or not to set up the card 
220 (at boot time).  The options for this variable are "yes" or "no"
222 The DEVICE variable tells the ethnet script the device name.  This should be
223 the same as whatever is after "ifcfg-" in the filename.
225 The DHCP variable tells the ethnet script to run the DCHP client.
226 The options for this variable are "yes" or "no"
228 IF the interface that provides the default route for your system is now set
229 up by DHCP, then you will need to edit the /etc/sysconfig/network file and
230 remove the GATEWAY and GATEWAY_IF variables.  dhcpcd, by default, will assign
231 the default route to any adapter that is givin a default gateway by a DHCP
232 server.  It is worth noting that there is no way to disable this behavior.
235 5.  What to do with your hostname and the /etc/hosts file. 
237 On most systems it should not be necessary to do the following, but I have
238 recieved questions reguarding specific aplications.
239 THE FOLLOWING IS NOT RECOMENDED UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING.
240 I'll leave it up to the reader to edit/create the scripts to do this.
241 You can source the variables in the /etc/dhcpc/dhcpcd-$1.info file after the
242 interface is set up, and then dynamicly write (appended) to the hosts file.
243 If you have the need to do this, create an additional script that runs only on
244 startup (in the same runlevels as network) that deletes the hosts file, gets
245 the necessary info from the dhcpcd-$1.info file's variables, creates a new
246 hosts file, and writes to that hosts file (appended) from a static copy of the
247 permanent entries.  I may edit this how-to in the future to include info on
248 this process, but not untill I've had a chance to test ALL of the failsafes.
249 This is currently out of the scope of this document, however, feedback on this
250 idea would be much appreciated.
252 6.  Before you reboot you need to test the system.  Start by running ifconfig
253 with no options to see which devices are enabled.  Disable all devices except
254 lo by running ifconfig <device name> down.  Now run the ethnet script using 
255 the following command:  /etc/init.d/ethnet start
256 Look for any failures and try to track them down.  If you have no failures,
257 run ifconfig and make sure everything looks okay.  Also check that your 
258 routing is set up correctly by running route with no argurments.  If 
259 everything looks good, then stop ethnet.  /etc/init.d/ethnet stop
260 Again look for any failures and track them down.  Again run route and ifconfig,
261 and look for any interfaces that aren't supposed to be there.  If there are no
262 interfaces, besides lo, returned by ifconfig and there are no routes set,
263 congratulations.  Reboot your system and continue on your path with LFS.
264 If you do have failures that you cannot track down.  Please feel free to
265 e-mail me <dj_me@swbell.net>  be sure to include the full problem description
266 (as much as you understand), the exact error message, and the text of all
267 your config files.  If you have problems, you've made a backup of everything, 
268 so put the backups back where you got them from.
270 Another issue has come to surface with the way LFS handles shutdowns and
271 restarts.  If the sendsignal script is run in runlevels 0 and 6 prior to
272 ethnet, this is a problem because dhcpcd is exacly as it's name implies, a 
273 daemon and will receive the kill signal prior to stoping the card correctly.
274 In both of these runlevels, sendsignals should be set to run after the ethnet
275 script.  This problem might exist on some versions of LFS.  If so.......
276 I don't know if this is a good idea or not, but it works for what little I 
277 have on my system.  It seems to me that a lot of network services that
278 will possibly be installed will be daemons, and that sendsignals should be run 
279 after the network is properly shut down. Rename the K???ethnet to a number 
280 smaller than K???sendsignals in both /etc/init.d/rc0.d and /etc/init.d/rc6.d.
281 I'd appreciate any feedback that anybody could give on this method.
284 7.  Conclusion:  "I hope this helps somebody out there ;)" -- Thinus Pollard
285 I'd like to thank Thinus Pollard and Simon Perreault for their versions of
286 this hint....which had my LFS system up and running in under an hour.  I'd
287 also like to thank the following dedicated LFS users who took the time to track
288 down the problems in my previous versions of this hint.
290 Special thanks to: Robert Smol, Rich Jones, Phil Gendreau, Cli - corrected
291 dhcpcd -k $Device, Markku Tikkanen, Tijmen Stam - provided cable modem info,
292 Steve Hayashi, Wolfgang Scheicher - provided dhcpcd default gateway and 
293 routing info, and Carl Spelkens - corrected the runlevels.   
295 As always, please send any tips, suggestions, flames...etc, to dj_me@swbell.net
296 or just edit this hint yourself.
298 -- D.J. Lucas <dj_me@swbell.net>