Dynamic Host Configuration Protocol


As its name implies, Dynamic Host Configuration Protocol (DHCP) configures hosts for connection to your network. DHCP allows a network administrator to configure all TCP/IP parameters for each host as he connects to the network after activation of a NIC. These parameters include automatically assigning an IP address to a NIC, setting name server entries in /etc/resolv.conf, and configuring default routing and gateway information for a host. This section first describes how to use DHCP to obtain IP address assignment for your NIC, and then how to quickly set up and start a DHCP server using Ubuntu.

Note

You can learn more about DHCP by reading RFC2131 "Dynamic Host Configuration Protocol." Browse to http://www.ietf.org/rfc/rfc2131.txt.


How DHCP Works

DHCP provides persistent storage of network parameters by holding identifying information for each network client that might connect to the network. The three most common pairs of identifying information are

  • Network subnet/host address Used by hosts to connect to the network at will

  • Subnet/hostname Enables the specified host to connect to the subnet

  • Subnet/hardware address Enables a specific client to connect to the network after getting the hostname from DHCP

DHCP also allocates to clients temporary or permanent network (IP) addresses. When a temporary assignment, known as a lease, elapses, the client can request to have the lease extended, or, if the address is no longer needed, the client can relinquish the address. For hosts that will be permanently connected to a network with adequate addresses available, DHCP allocates infinite leases.

DHCP offers your network some advantages. First, it shifts responsibility for assigning IP addresses from the network administrator (who can accidentally assign duplicate IP addresses) to the DHCP server. Second, DHCP makes better use of limited IP addresses. If a user is away from the office for whatever reason, the user's host can release its IP address for use by other hosts.

Like most things in life, DHCP is not perfect. Servers cannot be configured through DHCP alone because DNS does not know what addresses that DHCP assigns to a host. This means that DNS lookups are not possible on machines configured through DHCP alone; therefore, services cannot be provided. However, DHCP can make assignments based on DNS entries when using subnet/hostname or subnet/hardware address identifiers.

Note

The problem of using DHCP to configure servers using registered hostnames is being addressed by Dynamic DNS which, when fully developed, will enable DHCP to register IP addresses with DNS. This will allow you, for example, to register a domain name (such as imalinuxuser.com) and be able to easily access that domain's web server without needing to use static IP addressing of a specific host. The largest hurdle to overcome is the security implication of enabling each host connecting to the system to update DNS. A few companies, such as http://www.dyndns.org/, are already offering Dynamic DNS services and have clients for Linux.


Activating DHCP at Installation and Boot Time

Ubuntu automatically defaults your network interfaces to using DHCP, as it is the simplest way of setting up a network interface. With dynamic, or DHCP-assigned IP addressing schemes for your NIC, the broadcast address is set at 255.255.255.255 because dhclient, the DHCP client used for IP configuration, is initially unaware of where the DHCP server is located, so the request must travel every network until a server replies.

DHCP-specific information is simply saved as a BOOTPROTO=dhcp entry for your NIC under the /etc/sysconfig/network directory (in settings and scripts for a specific device, such as eth0).

Other settings specific to obtaining DHCP settings are saved in the file named dhclient.conf under the /etc/dhcp3/dhclient.conf directory and are documented in the dhclient.conf man page. More than 100 options are also documented in the dhcpoptions man page.

However, using DHCP is not that complicated. If you want to use DHCP and know that there is a server on your network, you can quickly configure your NIC by using the dhclient like so:

# dhclient Internet Systems Consortium DHCP Client V3.0.3 Copyright 2004-2005 Internet Systems Consortium. All rights reserved. For info, please visit http://www.isc.org/products/DHCP Listening on LPF/eth0/00:0f:ea:b2:53:85 Sending on   LPF/eth0/00:0f:ea:b2:53:85 Sending on   Socket/fallback DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 6 DHCPOFFER from 192.168.2.1 DHCPREQUEST on eth0 to 255.255.255.255 port 67 DHCPACK from 192.168.2.1 bound to 192.168.2.5 -- renewal in 71889 seconds. 


In this example, the first ethernet device, eth0, has been assigned an IP address of 192.168.2.5 from a DHCP server at 192.168.2.1. The renewal will take place in about twenty hours.

DHCP Software Installation and Configuration

Installation of the DHCP client and server is fairly straightforward, mainly because Ubuntu already includes dhclient in a default installation, but also because installing software is easy using synaptic or apt-get.

DHCP dhclient

As previously mentioned, DHCP use for an installed NIC is easily accomplished when installing Ubuntu on your host (read more about installation in Chapter 3, "Installing Ubuntu"), and during the network step of installation, you can choose to have DHCP initiated at boot time. If you choose to do this (and choose to install the DHCP client package), the DHCP client, dhclient, sends a broadcast message that the DHCP server replies to with networking information for your host. That is it; you're done.

If you choose to install from source, you will have to (as root) download and install the server packages that include dhclient. Unpack the source file, run ./configure from the root of the source directory, run make, and then run make install. This should put the DHCP client binaries where they will start at the correct time in the boot process.

You can however, fine-tune how dhclient works, and where and how it obtains or looks for DHCP information. You probably will not need to take this additional effort; but if you do, you can create and edit a file named dhclient.conf, and save it in the /etc directory with your settings. A few of the dhclient.conf options include

  • timeout time ; How long to wait before giving up trying (60 seconds is the default)

  • retry time ; How long to wait before retrying (five minutes is the default)

  • select-timeout time ; How long to wait before selecting a DHCP offer (zero seconds is the default)

  • reboot time ; How long to wait before trying to get a previously set IP (10 seconds is the default)

  • renew date ; When to renew an IP lease, where date is in the form of <weekday> <year>/<month>/<day> <hour>:<minute>:<second>, such as 4 2004/1/1 22:01:01 for Thursday, January 4, 2004 at 10:01 p.m.

See the dhclient.conf man page for more information on additional settings.

DHCP Server

Again, the easiest way to install the DHCP server on your computer is to use either synaptic or apt-get to retrieve the dchp3-server package. If you are so inclined, you can go to the Internet Software Consortium (ISC) website and download and build the source code yourself (http://www.isc.org/).

If you decide to install from a source downloaded from the ISC website, the installation is very straightforward. Just unpack your tar file, run ./configure from the root of the source directory, run make, and finally, if there are no errors, run make install. This puts all the files used by the DHCP daemon in the correct places. If you have the disk space, it is best to leave the source files in place until you are sure that DHCP is running correctly; otherwise, you can delete the source tree.

Note

For whichever installation method you choose, be sure that a file called /etc/dhcp3/dhcpd.leases is created. The file can be empty, but it does need to exist in order for dhcpd to start properly.


Using DHCP to Configure Network Hosts

Configuring your network with DHCP can look difficult, but is actually easy if your needs are simple. The server configuration can take a bit more work if your network is more complex and depending on how much you want DHCP to do.

DHCP Server Configuration

Configuring the server takes some thought and a little bit of work. Luckily, the work involves editing only a single configuration file, /etc/dhcp3/dhcpd.conf. To start the server at boot time, use the service, ntsysv, or bum commands.

The /etc/dhcp3/dhcpd.conf file contains all the information needed to run dhcpd. Ubuntu includes a sample dhcpd.conf in /usr/share/doc/dhcp*/dhcpd.conf.sample. The DHCP server source files also contain a sample dhcpd.conf file.

The /etc/dhcp3/dhcpd.conf file can be looked at as a three-part file. The first part contains configurations for DHCP itself. The configurations include

  • Setting the domain name option domain-name "example.org".

  • Setting DNS servers option domain-name-servers ns1.example.org, ns2.example.org (IP addresses can be substituted.)

  • Setting the default and maximum lease times default-lease-time 3600 and max-lease-time 14400.

Other settings in the first part include whether the server is the primary (authoritative) server and what type of logging DHCP should use. These settings are considered defaults and can be overridden by the subnet and host portion of the configuration in more complex situations.

Note

The dhcpd.conf file requires semicolons (;) after each command statement. If your configuration file has errors or runs improperly, check for this.


The next part of the dhcpd.conf deals with the different subnets that your DHCP server serves; this section is quite straightforward. Each subnet is defined separately and can look like this:

subnet 10.5.5.0 netmask 255.255.255.224 {  range 10.5.5.26 10.5.5.30;  option domain-name-servers ns1.internal.example.org;  option domain-name "internal.example.org";  option routers 10.5.5.1;  option broadcast-address 10.5.5.31;  default-lease-time 600;  max-lease-time 7200; } 


This defines the IP addressing for the 10.5.5.0 subnet. It defines the IP address ranging from 10.5.5.26 tHRough 10.5.5.30 to be dynamically assigned to hosts that reside on that subnet. This example shows that any TCP/IP option can be set from the subnet portion of the configuration file. It shows which DNS server the subnet will connect to, which can be good for DNS server load balancing, or which can be used to limit the hosts that can be reached through DNS. It defines the domain name, so you can have more than one domain on your network. It can also change the default and maximum lease time.

If you want your server to ignore a specific subnet, the following entry can be used to accomplish this:

subnet 10.152.187.0 netmask 255.255.255.0 { } 


This defines no options for the 10.152.187.0 subnet; therefore, the DHCP server ignores it.

The last part of your dhcp.conf is for defining hosts. This can be good if you want a computer on your network to have a specific IP address or other information specific to that host. The key to completing the host section is to know the hardware address of the host. As you learned in "Hardware Devices for Networking," earlier in this chapter, the hardware address is used to differentiate the host for configuration. Your hardware address can be obtained by using the ifconfig command as described previously. The hardware address is on the eth0 line labeled "Hwaddr".

host fantasia {   hardware ethernet 08:00:07:26:c0:a5;   fixed-address fantasia.fugue.com; } 


This example takes the host with the hardware address 08:00:07:26:c0:a5 and does a DNS lookup to assign the IP address for fantasia.fugue.com to the host.

DHCP can also define and configure booting for diskless clients like this:

host passacaglia {   hardware ethernet 0:0:c0:5d:bd:95;   filename "vmunix.passacaglia";   server-name "toccata.fugue.com"; } 


The diskless host passacaglia will get its boot information from server toccata.fugue.com and use vmunix.passacaglia kernel. All other TCP/IP configuration can also be included.

Caution

Remember, only one DHCP server should exist on a local network to avoid problems. Your DHCP might not work correctly on a LAN with hosts running outdated legacy operating systems. Often Windows NT servers will have the Windows DHCP server installed by default. Because there is no configuration file for NT to sort through, that DHCP server configures your host before the Linux server if both machines are on the same LAN. Check your NT servers for this situation and disable DHCP on the NT server; afterward, your other DHCP-enabled hosts should configure correctly. Also, check to make sure that there are no conflicts if you use a cable or DSL modem, wireless access point (WAP), or other intelligent router on your LAN that can provide DHCP.


Other Uses for DHCP

A whole host of options can be used in dhcpd.conf: Entire books are dedicated to DHCP. The most comprehensive book is The DHCP Handbook, available at http://www.dhcp-handbook.com/. You can define NIS domains, configure NETBIOS, set subnet masks, and define time servers, or many other types of serversto name a few of the DHCP options you can use. The preceding example will get your DHCP server and client up and running.

The DHCP server distribution contains an example of the dhcpd.conf file that you can use as a template for your network. The file shows a basic configuration that can get you started with explanations for the options used.



Ubuntu Unleashed
Ubuntu Unleashed 2011 Edition: Covering 10.10 and 11.04 (6th Edition)
ISBN: 0672333449
EAN: 2147483647
Year: 2006
Pages: 318

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net