[Home] [Credit Search] [Category Browser] [Staff Roll Call] | The LINUX.COM Article Archive |
Originally Published: Tuesday, 21 November 2000 | Author: Elmo Recio |
Published to: enhance_articles_sysadmin/Sysadmin | Page: 1/1 - [Printable] |
DHCP Daemon Made Easy
Got friends coming over, and they all want to share your internet connection? Running low on IP addresses? DHCP might be just your bag. Sysadmin rogue Elmo Recio takes you on a trip through the wonderful world of DHCP.
|
Page 1 of 1 | |
When my friends visited with their laptops, they plugged into the local area network and would have to muck about with their network settings. I got tired of reconfiguring everything from Solaris to Windows 98 when they came over, so I bit the bullet and installed the DHCP daemon. It was actually easier than I expected. The reader should have previous knowledge of networks, subnets, routers, syslog, and TCP/IP.
First Things First: Downloading The first step is downloading and configuring the DHCP daemon. The particular DHCPD we will be using is the Internet Software Consortium's Daemon Version Two. The ISC's DHCPD homepage is http://www.isc.org/products/DHCP/dhcp-v2.html. The particular version we'll be using is DHCP 2.0 Patch Level 5 and can be downloaded from the following location: ftp://ftp.isc.org/isc/dhcp/dhcp-2.0pl5.tar.gz This version is a well tested and compatible daemon which is included in many distributions. Furthermore, it's like getting the news straight from the horse's mouth, so-to-speak. Installing The next step is the installation, which is pretty much straight forward. su rootYou should not run into any compile problems on the more modern distributions like Caldera, Debian, SuSE. One thing to note is that if you are upgrading from a previous version of DHCPD there's a change in the location of the lease files. Nothing to worry about if you are reading this to install it for the first time. What you should have now are a set of binaries the one that interests us is the dhcpd. Configuration For the purposes of this demonstration we will assume that your LAN is set up so that it fully utilizes the 192.168 subnet. Furthermore, that the server which you are running the DHCP client has the IP of 192.168.1.1. Still logged in as root, the first thing that you have to do is edit the /etc/dhcpd.conf file and setup your subnets. Global Declarations One of the first things that you ought to do (even if you only have one network card or modem in your machine) is to set the interface device. server-identifier 192.168.1.1 This tells the DHCP daemon which interface card to bind to. For example, on my LAN at home, I have the DHCP server running on the same machine as the router, which has a modem in it. On that system, then, there are two interface cards, the modem, and the NIC. This line is crucial because it tells the DHCP server to use the NIC card for servicing DHCP requests from clients. It's also good practice to hand over a domain name to the client, as well as the ip addresses of the DNS Servers; there are several ways to do this:
option domain-name "thesmiths.net"
Or
option domain-name "thesmiths.net"
It really does not matter to the client if you send over the hostname or the ip address of the nameserver. If it's done the second way there are some advantages. The DHCP server will look up and send the ip address translation of the nameserver's hostname to the client. This is advantageous in that if the host name of the nameserver has several ip addresses associated with it, all of those ip addresses will be sent to the DHCP client. In other words, if ns1.thesmiths.net has 192.168.1.10, .11, .12, and 13, all of those ip addresses will be given to the client. This is much nicer than hardcoding the nameserver's ip address in your DHCP configuration file (especially in larger network installations) because it decreases the number of possible points of failure. Subnet Declarations Now let's declare our subnet. There are many ways to design the network topology. I am going to discuss the most common case in production enviornments: several subnets on one physical network. The discussion, however, is also applicable to those networks which have only one subnet on a physical network. It is possible, and most often the case that one physical network is shared by multiple subnets. For example, there might be a Class B network which utilizes an 8-bit subnet mask. While there are less than 254 network appliances installed, there's no problem. However, if they expand their network beyond the 254 devices, they will need to implement a second 8-bit subnet on the same physical network. To this end, we will alter the DHCP daemon configuration file with one subnet. However we will provide the structure in the configuration file to have multiple subnets on one physical network, should we need it later.
Your lease times can vary depending on your individual preference. The first line states that we are declaring a shared physical network [arbitrarily] named net-thesmiths-1. Before we declare any other subnets, we put in some network wide parameters. First we declare the option called subnet mask and set it to 255.255.255.0. Then we declare the default lease time in seconds. I set it to 10 minutes, because I noticed that my laptop kept wanting to use its lease from my home network at work. The default lease time is about one day. It's pretty smart to specify a max lease time, because many clients like to grab as long a lease as possible on IP addresses. Not setting this could cause inefficient usage of IP addresses. The next declaration is the subnet. Using the simplest case possible, we use the 192.168.1.0 subnet (or network address under windows) and an optional netmask of 255.255.255.0. The next is a range of IP addresses that are valid for this network. In this case, I am allocating 192.168.1.2 through 192.168.1.239 to be given up in the pool as possible IP addresses to clients. The next declarations are options that are sent to the client. The DHCP daemon will send 192.168.1.255 as the broadcast address to the client. It will also tell the client that the router (gateway) will be the hostname moz.thesmiths.net. [Once again, it's a good idea to use hostnames as much as possible so that if the IP changes, or for some reason you must use a different machine, you will only need to change one thing, the entry in the nameserver.] Test Run Before we continue, you should have a simple DHCP configuration file. Go into the directory which contains the DHCP daemon; invoke the daemon in the following way: ./dhcpd -q -cf /etc/dhpcd.conf -lf /var/state/dhpcd.leases eth0The command line syntax is easy:
Start -> Settings -> Control Panel -> Network
Under UNIX, if it's not already installed, you will have to download the above package and run the client from ISC's DHCP package known as dhclient. Or you can download and run an alternate client known as dhcpcd. DHCPd Notes Ok, so if everything went smoothly, you will have had an ip address automagically assigned to your client machine. Here are some tips to help you with your DHCP server. Static Hosts If you have a particular machine on the network to which you would like to assign an IP address, it's very simple. Consider the following: You have a laptop whose hostname is GANNON, and you would like the IP address of the machine to always be 192.168.1.25. In the global section of your configuration file:
host gannon {
You want to tell the DHCP daemon that if it encounters a client whose hostname is gannon with the hardware ethernet address (aka: MAC address) of 00:60:09:C5:9C:DB assign it the IP address that resolves as gannon.thesmiths.net. Note that the nameserver must have an entry for the hostname (gannon.thesmiths.net) to point to 192.168.1.25. If you are not running a nameserver, you can place this translation in the server's /etc/hosts file. Otherwise, you can just type in 192.168.1.25 in place of gannon.thesmiths.net. Also note that the IP address 192.168.1.25 is now used. So it should not be in the pool of dynamic addresses to be distributed. Other options You can specify a plethora of options for sending to the client. Some of the more interesting ones are as follows (from dhcp-options(5) man page)
option ntp-servers 192.168.1.1; # Time server
All together now Putting it all together we now have a really nice DHCP daemon and LAN. Our configuration file (based on this article) should look like:
# The configuration file for the network.
polywog@philtered.net
| |
Page 1 of 1 |