UC Davis DHCP/Resnet mini-HOWTO (DHCPcd) Jessica Luedtke, jmluedtke@ucdavis.edu v1.2, 22 February 2000 Adapted from the DHCP mini-HOWTO (DHCPd/DHCPcd) This document attempts to answer basic questions on how to setup your Linux box to serve as a DHCP client on UC Davis's computer network. ______________________________________________________________________ Table of Contents 1. Introduction 1.1 Standard Disclaimer 1.2 New Versions of this Document 1.3 Feedback 1.4 Contributors 1.5 Copyright Information 1.6 Other Important Notes 2. Obtaining & Registering a NIC Address 3. DHCP protocol 4. Client Setup 4.1 Downloading Client Daemon 4.2 Slackware 4.3 RedHat 5.x,6.x and Mandrake 6.x 4.4 RedHat 4.x and Caldera OpenLinux 1.1/1.2 4.5 Debian 4.6 LinuxPPC and MkLinux 4.7 Tying it all together 4.8 Various notes 4.9 Troubleshooting 4.10 Alternative DHCP Client 5. Further Information ______________________________________________________________________ 1. Introduction 1.1. Standard Disclaimer *IMPORTANT* This document does not imply that University of California, Davis, or the University of Davis Division of Information Technology will provide support for questions related to this document or DHCP and linux. Don't email the author of this HOWTO with questions, either. She's a newbie herself and probably can't answer any questions that aren't already covered within this document! Questions should be sent to vox@lugod.org. No liability for the contents of this documents can be accepted. Use the concepts, examples and other content at your own risk. As this is a new edition of this document, there may be errors and inaccuracies, that may of course be damaging to your system. Proceed with caution, and although this is highly unlikely, I don't take any responsibility for that. Also bear in mind that this is NOT official information. Much content in this document are assumptions, which appear to work for people. Use the information at your own risk. 1.2. New Versions of this Document New versions of the UCD specific version of this document may be available periodically. Check at http://www.lugod.org/documents/ for updates. This document is based on revision v4.6 of the official DHCP mini-HOWTO. If you notice an update to the official DHCP mini-HOWTO that isn't included in this document, tell me about it, and I'll add it. The official home of the DHCP mini-HOWTO is the Open Source Writers Groups, located at: http://www.oswg.org/ Following translations of the DHCP mini-HOWTO are available: * Chinese - http://www.linux.org.tw/CLDP/mini/DHCP.html * Japanese - http://www.linux.or.jp/JF/JFdocs/DHCP.html * Spanish - ftp://cuates.pue.upaep.mx/pub/linux/LuCAS/DHCP-mini-Como/ In addition, you may be able to find the DHCP mini-HOWTO on the Linux Documentation Project page via: http://www.linuxdoc.org/ 1.3. Feedback Feedback is most certaintly welcome for this document. Without your submissions and input, this document wouldn't exist. So, please post your additions, comments and criticisms to jmluedtke@ucdavis.edu. Don't send questions to this address. Send them to vox@lugod.org instead. 1.4. Contributors This document has been modified from the original version by Jessica Luedtke. The following people have contributed to this mini-HOWTO. * Paul Makeev * Heiko Schlittermann * Jonathan Smith * Dan Khabaza * Hal Sadofsky * Henrik Stoerner * Paul Rossington * Beau Patrette * Numerous others 1.5. Copyright Information This document is copyrighted (c) 1998 Vladimir Vuksan and distributed under the terms of the OpenContent License (OPL). Full text of the license can be found at: http://www.opencontent.org/opl.shtml 1.6. Other Important Notes This document assumes that you have a network card installed and support for it compiled into your kernel. If you do, you should see something similar to the below on bootup or using the dmesg command: ______________________________________________________________________ eth0: 3c509 at 0x300 tag 1, 10baseT port, address 00 20 af ee 11 11, IRQ 10. 3c509.c:1.07 6/15/95 becker@cesdis.gsfc.nasa.gov ______________________________________________________________________ If you don't, or you get some sort of error message, check the kernel HOWTO, kernel documentation, or the troubleshooting section of this document (Section 4.9) to figure out how to get your network card working before attempting anything below this point. You will also need a patch cable to connect your network card to the ethernet port. This can be obtained at the UCD Bookstore. Version numbers throughout this document may contain x's (eg. kernel version 2.2.x). This is simply to show that the version you are using may not be the same version that was available at the time this HOWTO was written. Replace the x's with the correct version number. Otherwise it won't work. This information should be generally transferable to other universities and organizations with DHCP setups. I've checked out a few other colleges' web pages and most seem to have the same basic NIC address registration setup. Feel free to make modifications as necessary for your university or organization of choice! 2. Obtaining & Registering a NIC number Your NIC number (Ethernet address) identifies your computer and must be M registered to authorize you as a ResNet user. To find your NIC number, type: ifconfig | grep -i "hwaddr" at the command line (Note: you may need to specify the full pathname of the command for this to work correctly). You should see something like: eth0 Link encap:Ethernet HWaddr 00:11:5B:76:BE:83 The numbers after HWaddr are what you are looking for. Take this number to a computer with working internet access or your Learning Resource Center. Go to the NIC registration site [http://mothra.ucdavis.edu/services]. Select Register a Computer for DHCP, click [Continue] and follow the instructions. 3. DHCP protocol DHCP is Dynamic Host Configuration Protocol. It is used to control vital networking parameters of hosts (running clients) with the help of a server. DHCP is backward compatible with BOOTP. For more information see RFC 2131 (old RFC 1541) and other. (See Internet Resources section at the end of the document). You can also read DHCP FAQ (http://web.syr.edu/~jmwobus/comfaqs/dhcp.faq.html). 4. Client Setup Currently there are three different DHCP client programs for Linux, dhcpcd, pump and dhclient. This mini-HOWTO deals primarily with dhcpcd. 4.1. Downloading Client Daemon (dhcpcd) Depending on your distribution you might have to download the DHCP client daemon. If you want to compile it from the source the package you need is called dhcpcd and the current version is 1.3.18. It is maintained by Sergei Viznyuk and today it comes as a binary package with most distributions. dhcpcd source can be downloaded from following locations: ftp://ftp.phystech.com/pub/ (Primary site) ftp://metalab.unc.edu/pub/Linux/system/network/daemons http://www.cps.msu.edu/~dunham/out/ 4.2. Slackware You can download the latest copy of the DHCPcd from the sites mentioned above. Download the latest version of dhcpcd.tar.gz. Unpack it by typing: tar -zxvf dhcpcd-x.xx.xx.tar.gz cd into the directory and make dhcpcd by typing: cd dhcpcd-x.xx.xx make Install it (you have to run the following command while logged in as root): make install This will create the directory /etc/dhcpc where DHCPcd will store the DHCP information, and the dhcpcd file will be copied into /usr/sbin. In order to make the system initialize using DHCP during boot type: cd /etc/rc.d mv rc.inet1 rc.inet1.OLD This will move the old network initialization script into rc.inet1.OLD. You now need to create the new rc.inet1 script. Following code is all you need: ______________________________________________________________________ #!/bin/sh # # rc.inet1 This shell script boots up the base INET system. HOSTNAME=`cat /etc/HOSTNAME` #This is probably not necessary but I #will leave it in anyways # Attach the loopback device. /sbin/ifconfig lo 127.0.0.1 /sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo # IF YOU HAVE AN ETHERNET CONNECTION, use these lines below to configure the # eth0 interface. If you're only using loopback or SLIP, don't include the # rest of the lines in this file. /usr/sbin/dhcpcd ______________________________________________________________________ Save it and reboot your computer. When you are finished go to section 4.7 - Tying it all together. 4.3 RedHat 5.x and 6.x and Mandrake 6.x DHCPcd configuration under RedHat 6.0+ is really easy. All you need to do is start the Control Panel by typing control-panel. Select "Network Configuration" Click on Interfaces Click Add Select Ethernet In the Edit Ethernet/Bus Interface select "Activate interface at boot time", and select "DHCP" as "Interface configuration protocol" Please note that in RedHat 6.x the default DHCP client is pump instead of the above mentioned dhcpcd. The CD-ROM does include dhcpcd RPM, so if you have no luck with pump try with dhcpcd. After you install dhcpcd (e.g. rpm -i dhcpcd-1.3.17pl2-1.i386.rpm) you will have to make some changes. Additional notes from Alexander Stevenson : I had no luck with DHCPcd. What finally worked for me was "pump", which comes with Linux Mandrake 6.0 (and so I assume it is included with RedHat as well). The command I used was: pump -i eth0 -h hostname It didn't matter what "hostname" was, but without it the server would not respond. I then changed the line in my /sbin/ifup script to reflect the change; the default version does not have the -h switch, and so didn't work for me. Basically, if you're using linuxconf, and after setting the adapter to "DHCP" it still doesn't work, try adding a "-h hostname" to the pump line in the /sbin/ifup script. My script now looks like this: ______________________________________________________________________ ... if [ -n "$PUMP" ]; then echo -n "Determining IP information for $DEVICE..." if /sbin/pump -i $DEVICE -h hostname; then echo " done." else echo " failed." exit 1 fi else ... ______________________________________________________________________ That is it. Reboot your machine or type /sbin/ifup eth0 on the command line. 4.4. RedHat 4.x and Caldera OpenLinux 1.1/1.2 DHCPcd is included in the standard RedHat distribution as an RPM and you can find it on your distribution's CD-ROM in RPMS directory or you can download it from: ftp://ftp.redhat.com/pub/redhat/redhat-x.x/i386/RedHat/RPMS/ replacing the x.x with the correct version number and install it with: rpm -i dhcpcd-x.x.x.i386.rpm Alternatively you can compile your own version by following the steps outlined in the Slackware. This information was provided by nothing@cc.gatech.edu ______________________________________________________________________ Removed my static ip and name from /etc/resolv.conf. However, I did leave in the search line and my two nameserver lines (for some reason my dhcpcd never creates a /etc/dhcpc/resolv.conf, so I have to use a static /etc/resolv.conf). In /etc/sysconfig/network I removed the HOSTNAME and GATEWAY entries. I left the other entries as is (NETWORKING, DOMAINNAME, GATEWAYDEV). In /etc/sysconfig/network-scripts/ifcfg-eth0 I removed the IPADDR, NETMASK, NETWORK, and BROADCAST entries. I left DEVICE and ONBOOT as is. I changed the BOOTPROTO line to BOOTPROTO=dhcp. Save the file. Reboot your computer. ______________________________________________________________________ When you are finished go to section 4.7 - Tying it all together. 4.5. Debian There is a deb package of DHCPcd at ftp://ftp.debian.org/debian/dists/slink/main/binary-i386/net/ To unpack the deb package type: dpkg -i /where/ever/your/debian/packages/are/dhcpd*deb Alternativly, you can follow the Slackware installation instructions. It appears that there isn't a need for any DHCPcd configuration because: From: Heiko Schlittermann (heiko@os.inf.tu-dresden.de) The dhcpcd package installs it's startup script as usual for debian packages in /etc/init.d/, here as /etc/init.d/dhcpcd, and links this to the various /etc/rc?.d/ directories. The contents of the /etc/rc?.d/ dirs is then executed at boot time. If you don't reboot after installing you should consider starting the daemon manually by typing: /etc/init.d/dhcpcd start When you are finished go to section 4.7 - Tying it all together. 4.6. LinuxPPC and MkLinux Following section has been written by R. Shapiro As of the "1999" (R5) release, Linuxppc is now almost completely compatible with Redhat 6, with one caveat (see below). In general the instructions are exactly the same as for the current release of RedHat 6.x and Mandrake 6.x. The remaining problem is that Redhat 6 uses the 'pump' client for dhcp by default, and 'pump' doesn't work reliably in Linuxppc. To get around this, you should install the latest dhcpcd from Sergei Viznyuk, and then edit /sbin/ifup to use dhcpcd instead of pump. In /sbin/ifup, change: _______________________________________________________________________ if [ "$BOOTPROTO" = bootp -o "$BOOTPROTO" = dhcp ]; then PUMP=true fi if [ -n "$PUMP" ]; then _______________________________________________________________________ to _______________________________________________________________________ if [ "$BOOTPROTO" = bootp ]; then echo " done." else echo " failed." exit 1 fi elif [ "$BOOTPROTO" = dhcp ]; then echo -n "Determining IP information for $DEVICE..." if /sbin/dhcpcd -d $DEVICE ; then if [ -f /etc/dhcpc/dhcpcd-${DEVICE}.exe ]; then /etc/dhcpc/dhcpcd-${DEVICE}.exe fi _______________________________________________________________________ Next, you'll need to do a corresponding changes for ifdown. Change: ----------------------------------------------------------------------- if [ "$BOOTPROTO" = bootp -o "$BOOTPROTO" = dhcp ]; then .... fi ----------------------------------------------------------------------- to ----------------------------------------------------------------------- if [ "$BOOTPROTO" = bootp ]; then fi if [ "$BOOTPROTO" = dhcp ]; then if [ -f /var/run/dhcpcd-${DEVICE}.pid ]; then kill 'cat /var/run/dhcpcd-${DEVICE}.pid' rm -f /var/run/dhcpcd-${DEVICE}.pid fi fi _______________________________________________________________________ A working ppc rpm for dhcpcd is included on the Linuxppc 1999 cd; a slightly later rpm is available in the contrib directory on ftp://ftp.linuxppc.org/. Sources, which compile out of the box in Linuxppc 1999, are available from ftp://ftp.phystech.com/pub/dhcpcd-1.3.17-pl9.tar.gz. 4.7. Tying it all together After your machine reboots your network interface should be configured. Type: ifconfig You should get something like this ______________________________________________________________________ lo Link encap:Local Loopback inet addr:127.0.0.1 Bcast:127.255.255.255 Mask:255.0.0.0 UP BROADCAST LOOPBACK RUNNING MTU:3584 Metric:1 RX packets:302 errors:0 dropped:0 overruns:0 frame:0 TX packets:302 errors:0 dropped:0 overruns:0 carrier:0 coll:0 eth0 Link encap:Ethernet HWaddr 00:20:AF:EE:05:45 inet addr:24.128.53.102 Bcast:24.128.53.255 Mask:255.255.254.0 ^^^^^^^^^^^^^^^^^^^^^^^ UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1 RX packets:24783 errors:1 dropped:1 overruns:0 frame:1 TX packets:11598 errors:0 dropped:0 overruns:0 carrier:0 coll:96 Interrupt:10 Base address:0x300 ______________________________________________________________________ If you have some normal number under inet. addr you are set. If you see 0.0.0.0, don't despair - it is a temporary setting before dhcpcd acquires the IP address. If even after few minutes you are seeing 0.0.0.0 please check out Section 4.9 - Troubleshooting. DHCPcd is a daemon and will stay running as long as you have your machine on. Every three hours it will contact the DHCP server and try to renew the IP address lease. It will log all the messages in the syslog (on Slackware /var/adm/syslog, RedHat/Debian/OpenLinux /var/log/syslog). One final thing. You need to specify your nameservers. There are two ways to do it: you can either ask your provider to provide you with the addresses of your name server (169.237.250.250 and 169.237.1.250 at UC Davis) and then put those in the /etc/resolv.conf, or DHCPcd will obtain the list from the DHCP server and will build a resolv.conf in /etc/dhcpc. Use DHCPcds resolv.conf by doing the following: Back up your old /etc/resolv.conf by typing: mv /etc/resolv.conf /etc/resolv.conf.OLD If directory /etc/dhcpc doesn't exist create it by typing: mkdir /etc/dhcpc Make a link from /etc/dhcpc/resolv.conf to /etc/resolv.conf by typing: ln -s /etc/dhcpc/resolv.conf /etc/resolv.conf If that doesn't work try this: (fix suggested by nothing@cc.gatech.edu with a little amendment by Henrik Stoerner) This last step I had to perform only because my dhcpcd doesn't create an /etc/dhcpc/resolv.conf. In /etc/sysconfig/network-scripts/ifup I made the following changes (which are a very poor hack, but they work for me): _____________________________________________________________________ elif [ "$BOOTPROTO" = dhcp -a "$ISALIAS" = no ]; then echo -n "Using DHCP for ${DEVICE}... " /sbin/dhcpcd -c /etc/sysconfig/network-scripts/ifdhcpc-done ${DEVICE} echo "echo \$$ > /var/run/dhcp-wait-${DEVICE}.pid; exec sleep 30" | sh if [ -f /var/run/dhcp-wait-${DEVICE}.pid ]; then ^^^^ echo "failed." exit 1 ______________________________________________________________________ I changed to: ______________________________________________________________________ elif [ "$BOOTPROTO" = dhcp -a "$ISALIAS" = no ]; then echo -n "Using DHCP for ${DEVICE}... " /sbin/dhcpcd echo "echo \$$ > /var/run/dhcp-wait-${DEVICE}.pid; exec sleep 30" | sh if [ ! -f /var/run/dhcp-wait-${DEVICE}.pid ]; then ^^^^^^ echo "failed." exit 1 ______________________________________________________________________ Notice the ! (bang) in if [ ! -f /var/run/dhcp-wait-${DEVICE}.pid ]; 4.8. Various notes Following step(s) are not necessary but might be useful to some people a) If you need network connectivity only occasionally you can start dhcpcd from the command line (you have to be logged in as root to do this) with the command: /usr/sbin/dhcpcd When you need to down (turn off) the network type: /usr/sbin/dhcpcd -k (You probably don't want this if you're on resnet!) 4.9. Troubleshooting If you have followed the steps outlined above and you are unable to access the network there are several possible explanations: I. Your network card is not configured properly. During the boot up process your Linux will probe your network card and should say something along these lines: ______________________________________________________________________ eth0: 3c509 at 0x300 tag 1, 10baseT port, address 00 20 af ee 11 11, IRQ 10. 3c509.c:1.07 6/15/95 becker@cesdis.gsfc.nasa.gov ______________________________________________________________________ If a message like this doesn't appear your ethernet card might not be recognized by your Linux system. If you have a generic ethernet card (a NE2000 clone) you should have received a disk with DOS utilities that you can use to set up the card. Try playing with IRQs until Linux recognizes your card (IRQ 9,10,12 are usually good). II. Your DHCP server supports RFC 1541/My DHCP server is Windows NT Try running dhcpcd by typing: dhcpcd -r. Use the ifconfig command to check if your network interface is configured (wait few seconds for the configuration process, initally it will say Inet.addr=0.0.0.0) If this solves your problem add the "-r" flag to the boot up scripts, ie: instead of /sbin/dhcpcd you will have /sbin/dhcpcd -r. For example, under RedHat edit script /etc/sysconfig/network-scripts/ifup and change the following: -------------------------------------------------------------------- IFNAME=$[ {DEVICE} \ "/sbin/dhcpcd -r -c /etc/"- etc etc. -------------------------------------------------------------------- III. During bootup I get error message "Using DHCP for eth0 ... failed" but my system works fine. You are most likely using RedHat and you haven't followed instructions carefully :-). You are missing the ! (bang) in one of the if statements. Go to section 4.7 - Tying it all together, to see how to fix it. IV. My network works for few minutes and then stops responding There are some reports of gated (gateway daemon) screwing up routing on Linux boxes which results in problem described above. Check if gated is running by typing: ps -auxww | grep gate If it is, try removing it with RedHat's RPM manager or removing the entry in /etc/rc.d/ V. My ethernet card is recognized during boot up but I still get "NO DHCPOFFER" message in my logs. I also happen to have a PCMCIA ethernet card. You need to make sure that you have the 10BaseT port ("phone" plug) on your network card activated. Best way to verify it is to check what kind of connector your card is configured for during bootup (or using the dmsg command) e.g: ______________________________________________________________________ eth0: 3c509 at 0x300 tag 1, 10baseT port, address 00 20 af ee 11 11, IRQ 10. ^^^^^^^^^^^^ 3c509.c:1.07 6/15/95 becker@cesdis.gsfc.nasa.gov ______________________________________________________________________ I have received reports of laptop users having this kind of problems due to the PCMCIA utilities (specifically ifport) that would set the connector type to 10Base2 (thinnet). You have to make sure you use 10BaseT for your connection. If you are not reconfigure the card and restart the computer. VI. My DHCP client broadcasts requests but no one answers (Contributed by Peter Amstutz) On some systems, you need to include some hostname for your machine as part of the request. With dhcpcd, do this by typing: dhcpcd -h foohost (replacing the word foohost with your hostname). Probably the hostname wanted will be your account username on the network. 4.10. Alternative DHCP client (ISC dhclient) If you have not had success getting your Linux connection running with the dhcpcd you might want to try ISC dhclient. dhclient comes with the DHCP distribution from ISC which includes both a DHCP client and a DHCP server. Instructions on how to get and compile the DHCP distribution can be found at: ftp://ftp.isc.org/isc/dhcp/ The following information has been provided by Ted Lemon one of the authors of dhclient. With the current version of the DHCP client, you don't actually need a dhclient.conf. All you have to do is invoke dhclient e.g.: /sbin/dhclient. This will configure all broadcast interfaces. If this doesn't work or you want to specify only one interface create a /etc/dhclient.conf file with this example configuration. _________________________________________________________________ interface "eth0" { send dhcp-client-identifier 1:xx:xx:xx:xx:xx:xx; send dhcp-lease-time 86400; } _________________________________________________________________ Here we assume that the ethernet interface is eth0. If not change accordingly. Also replace xx:xx:xx:xx:xx with your ethernet address. This dhclient.conf makes the client look more like a Win95 client. 5. Further Information Newsgroups: alt.os.linux, comp.os.linux.questions and comp.os.linux.answers are good starting points. Try reading the newsgroup faq (available at ftp://rtfm.mit.edu) and searching DejaNews (http://www.deja.com/home_ps.shtml) before posting. You may find what you need in there. Email: Ask vox@lugod.org, or join the UCD Linux mailing list by emailing majordomo@math.ucdavis.edu with "subscribe linux" (without the quotes) as the body of the message. WWW: Go to your favorite search engine and do a search. Some popular search engines are Altavista (http://www.altavista.com) and Yahoo (http://www.yahoo.com). Also, check out http://www.lugod.org. In fact, do this even if you don't need further help :) HOWTOs: Various HOWTOs are referenced in this document. These (and more) are available at http://www.linuxdoc.org/. Please remember not to contact Information Technology about this HOWTO or problems involving Linux, as they do not support Linux at this time.