Section 39.1. Objective 1: DHCP Configuration


39.1. Objective 1: DHCP Configuration

DHCP is a superset of bootp and a replacement for that earlier protocol; both are used to assign IP addresses to clients on a network. DHCP is used for dynamic hosts that can move, connect, and disconnect from networks. DHCP can dynamically assign IP addresses from preassigned IP ranges in /etc/dhcpd.config and set up static IP addresses based on the network interface card's Media Access Controller (MAC) address. DHCP can even restrict access by accepting requests only from specified MAC addresses.

39.1.1. Setting Up a DHCP Server

To set up a DHCP server, first ensure you have your DHCP package installed. Also read the README file, because it's full of useful information. Next, follow these steps:

  1. Configure your /etc/dhcpd.conf file (an example for setting random IPs for clients is in the next section).

  2. Start the DHCP server in debug mode (/usr/sbin/dhcpd -d -f) to verify that DHCP is working properly.

  3. To start the server for actual use, enter /etc/init.d/dhcpd start or just /usr/bin/dhcpd, sending it into the background as a daemon.

39.1.1.1. Configuring DHCP options

The DHCP protocol has a vast number of options that it can pass to clients to configure them correctly. Some of the most important are shown in the following example:

 default-lease-time 21600; max-lease-time 43200; option subnet-mask 255.255.255.0; option broadcast-address 192.168.1.255; option routers 192.168.1.254; option domain-name-servers 192.168.1.1, 192.168.1.2; option domain-name "example.com"; option ntp-servers 192.168.1.1; 

Most of these should be self-explanatory. The lease times are how long the client can hold on to the IP address it is given without reconfirming with the server, in seconds. With the default-lease-time set to 21600, the client is instructed to contact the DHCP server at least every 6 hours. If it has not been in touch within 43,200 seconds, 12 hours, it should consider itself to be out of a lease.

39.1.1.2. Configuring dhcpd for random IP assignment

To set up DHCP to assign random IP addresses to DHCP clients on the network, you will need to configure the /etc/dhcpd.conf file, which is the main configuration file for DHCP. The following listing contains sample settings for the /etc/dhcpd.conf that will allow DHCP to randomly assign IP addresses on your network between 192.168.1.10 and 192.168.1.100, as well as in the range 192.168.1.150 through 192.168.1.200:

 subnet 192.168.1.0 netmask 255.255.255.0 {             range 192.168.1.10 192.168.1.100;             range 192.168.1.150 192.168.1.200; } 

If you want to change the options for one subnet while leaving the global options unchanged for other subnetsfor example, because one subnet is served by a different routersimply supply the options inside the subnet stanza.

With the options and subnet declarations shown, you have a working DHCP configuration. Remember to reload dhcpd, such as by running /etc/init.d/dhcp reload (or restart, depending on the distribution).

39.1.1.3. Fixed addresses in dhcpd

Sometimes you want hosts to get the same address all the time. One trick to accomplish this is to set the lease time in the dynamic range very high (a month, perhaps). That way, a host needs to be off the net more than a month to not receive the same address.

A surer way to keep a host at a desired fixed address is to use static address assignment. This is done based on the Ethernet NIC's MAC address. In dhcpd.conf, insert something like this:

 host roke {         hardware ethernet 00:60:1D:1f:1e:ef;         fixed-address 192.168.1.9; } 

When a client comes along that has an Ethernet address matching this, it will receive a lease on the 192.168.1.9 address. The address must be outside the dynamic ranges.

This host stanza is also how options are set for single hosts. Simply supply options for the host within the stanza.

39.1.1.4. bootp support

As noted earlier, bootp is the predecessor of DHCP. The ISC DHCP server can also support bootp, which is handy to support some Unix machines and network components. Each host that needs bootp must be listed explicitly. A declaration might look like the following.

 host bootproke {     hardware ethernet 08:00:2b:4c:59:23;     fixed-address 192.168.1.105;     filename "/tftpboot/bootproke.boot"; } 

39.1.1.5. dhcpd.leases

This file is a log of all the leases the dhcpd server has given out. It includes only addresses in the dynamic ranges, and every time a dynamic lease is given, details about it are written to the end of this file. The most likely location for this file is /var/lib/dhcp/dhcpd.leases. If you're installing DHCP service for the first time on this server, you need to make the initial lease database by just creating an empty file like this: touch /var/lib/dhcp/dhcpd.leases. An example entry is shown here:

 lease 192.168.1.17 {         starts 5 2004/01/02 10:53:18;         ends 5 2004/01/02 20:13:57;         hardware ethernet 00:02:2d:5e:74:8c;         client-hostname "lookfar.langfeldt.net"; } 

39.1.2. Using DHCP Clients

On Linux there are three DHCP clients , but dhclient and pump are the most common. Both are available on Debian and Red Hat systems. People are not in agreement about which of them works best, but this author has never been failed by pump. Both distributions' scripts should work with both clients. Using the DHCP client directly can be quite helpful in troubleshooting.

39.1.2.1. Using pump

The pump package comes with a usable default configuration that you will seldom want to override. The most likely reasons to change it are to stop it from modifying your DNS setup or overriding the settings given by the DHCP server. The standard configuration is in /etc/pump.conf and looks like this:

 domainsearch "example.com" script /sbin/pump.script device eth0 {         nodns } 

The first line just overrides the domain list that pump would use to update /etc/resolv.conf. The nodns keyword for eth0 stops pump from changing the resolv.conf at allat least based on DHCP answers received on eth0. Answers to eth1 can still do it.

To get a DHCP lease for eth0, issue dhcp -i eth0. To check the status of your DHCP lease, enter:

 # pump --status Device eth0         IP: 172.22.12.88         Netmask: 255.255.252.0         Broadcast: 172.22.15.255         Network: 172.22.12.0         Boot server 172.22.12.10         Next server 172.22.12.10         Gateway: 127.22.12.1         Domain: example.com         Nameservers: 172.22.12.5 172.22.12.1         Renewal time: Tue Jan 15 04:53:49 2004         Expiration time: Wed Jan 16 01:53:49 2004 

Other important operations are -r (release lease) and -R (renew lease).

39.1.2.2. Using dhclient

dhclient can act pretty much on its own, but it is extremely configurable, and it may have more functions than you ever dreamed ofcertainly too many for us to get into here. If it is started without a configuration, it finds all your network interfaces and sends out DHCP requests on all of them. Once it has received a lease and configured an interface, it goes into the background. In the background it will maintain your leases and keep your interface configured. Depending on the packager, it may or may not update your DNS configuration and configure your network based on options in the DHCP protocol. To release your lease, run the client again with -r. The background dhclient process will exit.

As with pump, you will most likely not need a configuration file. But if you do, you can set up something like the preceding pump configuration very simply as shown here:

 supersede domain-name "example.com"; prepend domain-name-servers 127.0.0.1; 

39.1.2.3. Configuring Red Hat as a DHCP client

To configure your Red Hat host to be a DHCP client, use the intuitive neat command. Red Hat works with either dhclient or pump.

To make sure you are connected to the DHCP server, run ifconfig. The eth0 section of the output should have an inet addr: entry with your DHCP-assigned network address.

Alternatively, change your interface network script /etc/sysconfig/network-scripts/ifcfg-eth0 from:

 DEVICE=eth1 ONBOOT=yes BOOTPROTO=none HWADDR=00:0B:6A:10:49:5A NETMASK=255.255.255.0 USERCTL=no PEERDNS=yes GATEWAY=10.163.45.254 TYPE=Ethernet IPADDR=10.163.45.210 

to the following, editing it to fit your needs:

 DEVICE=eth1 ONBOOT=yes BOOTPROTO=dhcp HWADDR=00:0B:6A:10:49:5A 

After that you need to reload your configuration to validate the modifications using the script provided: /etc/init.d/network reload.

39.1.2.4. Configuring Debian as a DHCP client

You can configure a Debian host's networking during installation. After installation, the simplest way to do it is to edit /etc/network/interfaces directly. If you want eth0 to be managed by a DHCP client, simply make sure that the iface line, shown in the following example, is in the configuration. The auto line makes sure that the card is taken up when booting.

 auto eth0 iface eth0 inet dhcp 

39.1.3. DHCP Relay

Since DHCP uses Ethernet broadcast to get in touch with the DHCP server, it cannot get in touch with a server on another subnet, because broadcasts are not routed. In a large network, it's not very practical to put a DHCP server on each subnet, so instead you can use DHCP relay . This is most often done by routers. Cisco routers, for example, offer ip helper-address to set the address to relay DHCP requests to. If your routers do not support relaying, any Unix or Linux host can do the job. To relay all requests seen on eth0 to the DHCP server at 192.168.1.5, relaying can be started as follows. It will then catch all requests and relay them to the server, the server will answer back to the relay agent, and the relay agent will send the answer back to the requester.

 # dhcrelay -i eth0 192.168.1.5 Internet Software Consortium DHCP Relay Agent V3.0pl2 Copyright 1997-2000 Internet Software Consortium. All rights reserved. For info, please visit http://www.isc.org/products/DHCP Listening on LPF/eth0/00:03:93:ce:2f:c0 Sending on   LPF/eth0/00:03:93:ce:2f:c0 Sending on   Socket/fallback 



LPI Linux Certification in a Nutshell
LPI Linux Certification in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596005288
EAN: 2147483647
Year: 2004
Pages: 257

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