Red Hat Linux 7 Unleashed

Red Hat Linux 7 Unleashed

By William Ball

Automatically Configuring Clients with DHCP

DHCP stands for Dynamic Host Configuration Protocol. It's a protocol to configure hosts (computers) dynamically, meaning that unconfigured client computers can be plugged into a DHCP served LAN, and will be given an IP address, a DNS server address, a WINS server address, and many other configuration items that would otherwise need to be manually configured by the network administrator. The administrator's sole network configuration task is to make sure each client has a unique hostname.

Obviously, this can save many weeks of configuration over the lifetime of a medium-sized LAN. It also makes renumbering a cinch when the LAN's network address or netmask is changed. DHCP can be used to automatically reconfigure LAN clients to accommodate changes in DNS and WINS server addresses.

Configuring a DHCP Server

The first step is to see whether DHCP is already in service. Use the following command:


   # ps ax | grep dhcpd

If you see an instance of dhcpd running, you know it's already configured and running. Otherwise, you'll need to configure dhcpd. It's an easy task.

The first step is to try running dhcpd in the foreground, and observe the error messages (if any):


   # dhcpd -f
Internet Software Consortium DHCP Server 2.0
Copyright 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium.
All rights reserved.

Please contribute if you find this software useful.
For info, please visit http://www.isc.org/dhcp-contrib.html

Can't open /etc/dhcpd.conf: No such file or directory
exiting.
#

In the preceding example, notice the error stating it can't find /etc/dhcpd.conf. If you get this error, the next step is to create the file. The following is a simple example dhcpd.conf for a server at 192.168.100.1:

subnet 192.168.100.0 netmask 255.255.255.0 {
     range 192.168.100.200 192.168.100.240;
         option subnet-mask 255.255.255.0;
         option broadcast-address 192.168.100.255;
         option routers 192.168.100.1;
         option domain-name-servers 192.168.100.1;
         option domain-name "domain.cxm";
         option ip-forwarding on;
         option netbios-node-type 8;
     }

The preceding specifies that any client in the 192.168.100.0/24 subnet will be given an IP address in the 192.168.100.200-240 range, broadcast address 192.168.100.255, default route 192.168.100.1, DNS (equivalent of resolv.conf) at 192.168.100.1, domain name domain.cxm, ip forwarding is on. The netbios-node-type 8 refers to a client netbios node type H, which instructs the client to attempt netbios resolution first through unicast, and then on failure by broadcast. This is the widely preferred method.

Note that the preceding is an extremely simple dhcpd.conf. They can get much more complex. Several subnets can be served, either on separate physical networks or sharing a network. Groups of subnets can share properties. Individual hosts can be configured centrally, using only their MAC addresses as identification, and they can, if desired, be allocated hostnames centrally. DHCP can even be configured to reject requests from hosts not already listed in dhcpd.conf, although that eliminates some of the "plug and connect" functionality.

DHCP is incredibly powerful and flexible. To learn more about it, consult the following man pages:

After /etc/dhcpd.conf has been created, once again try running the daemon in the foreground:


   # dhcpd -f
Internet Software Consortium DHCP Server 2.0
Copyright 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium.
All rights reserved.

Please contribute if you find this software useful.
For info, please visit http://www.isc.org/dhcp-contrib.html

Can't open lease database /var/lib/dhcp/dhcpd.leases: No such file or director
y -- check for failed database rewrite attempt!
Please read the dhcpd.leases manual page if you.
don't know what to do about this.
exiting.
#

In the preceding example, notice the error stating it can't open lease database /var/lib/dhcp/dhcpd.leases. You must create the directory, mode 755 all the way down the tree. Then, create an empty dhcpd.leases with the following command:


   # touch /var/lib/dhcp/dhcpd.leases

Now dhcpd should run, as shown in the following example:


   # dhcpd -f
Internet Software Consortium DHCP Server 2.0
Copyright 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium.
All rights reserved.

Please contribute if you find this software useful.
For info, please visit http://www.isc.org/dhcp-contrib.html

Listening on LPF/eth0/00:a0:c9:e8:20:3c/192.168.100.0
Sending on   LPF/eth0/00:a0:c9:e8:20:3c/192.168.100.0
Sending on   Socket/fallback/fallback-net

Notice in the preceding that this time dhcpd listens and sends on sockets, and runs continuously. You can run DHCP server with the dhcpd -f command whenever you need to troubleshoot. However, you'll typically run it in the background. Press Ctrl+C to terminate dhcpd, and then run it as a daemon with the following command:


   # /etc/rc.d/init.d/dhcpd restart
Shutting down dhcpd: [FAILED]
Starting dhcpd: [  OK  ]
#

The failure on shutdown is due to the fact that it wasn't running in the first place. The final step is to configure the server to run dhcpd on reboot. That's accomplished with linuxconf, Control Panel, Control Service Activity, dhcpd. Press Enter to obtain the Service dhcpd screen. Check the Automatic check box on the Startup line, check the check boxes for Level 3 and Level 5, then click the Accept button, and quit all the way out of linuxconf. The next time you reboot, dhcpd will run automatically.

Once the dhcp server is up and running, clients must be told to use the server's information. The next section describes how to set up a client to use the server's information.

Configuring a Linux-Based DHCP Client

Setting a Linux client as a DHCP client requires addition or modification of one line in one file. The file is /etc/sysconfig/network-scripts/ifcfg-eth0. The line you change looks like this:

BOOTPROTO=static

If that line exists, it specifies that the eth0 interface's IP address is a static address, specified by other lines in the file. To make the client a DHCP client, change the line as follows, or if it doesn't exist, add the following line:

BOOTPROTO=dhcp

Then restart the client's network interface with the following command:


   # /etc/rc.d/init.d/network restart

If you execute the ifconfig command on the client, you'll see that the client's IP address is now an address from the range specified by the server's dhcpd.conf file. To switch back to static addressing, change back to BOOTPROTO=static and restart the network.

You can also use linuxconf to switch between static and DHCP addressing. The menu sequence is Networking, Basic Host Information, look for the Config Mode radio buttons, and enable the one saying Dhcp. Unfortunately, linuxconf needlessly changes several other lines in the ifcfg-eth0 and several other files. The least invasive method of switching between static and DHCP boot protocols is to manually edit ifcfg-eth0.

Tracking DHCP Server Changes

As mentioned earlier, a prime benefit of DHCP is central administration of client network properties. Imagine your organization decides they need the subnet of your current LAN somewhere else, so you have to renumber the LAN. With statically configured clients, you'd need to walk to every client and change several parameters. But if they receive their network parameters via DHCP, the clients change automatically. Almost.

Each client must be told to release and renew its current DHCP lease. The renewal transfers the new information.

One way of releasing and renewing is simply rebooting the client. In the Linux world rebooting is considered bad form, so you can simply restart the network to release and renew your DHCP lease. The following command, run on the client, restarts the client's network interface on the client:


   # /etc/rc.d/init.d/network restart

Configuring a Windows-Based DHCP Client

Configuring a Windows-based DHCP client is almost as easy as configuring a Linux-based DHCP client. First, pull up the Network dialog box by right-clicking any Network Neighborhood icon and choosing Properties. In the list box on the Configuration tab, choose TCP/IP->Ethernet adapter (exact wording depends on the adapter) and then click the Properties button. You're then brought to the TCP/IP Properties dialog box.

On the IP Address tab, check the Obtain an IP Address Automatically radio button. Then, on the WINS Configuration tab, check the Use DHCP for WINS Resolution radio button. Click OK all the way out, and answer "yes" when asked if you want to reboot. When the computer reboots, its IP address will be assigned by the DHCP server. All parameters set in dhcpd.conf on the DHCP server will likewise override those set on the Windows client. Thus, parameters like the DNS configuration can be set up centrally.

Releasing and Renewing Your DHCP Lease

Unlike Linux, Windows does not release and renew on reboot. This means that even after the DHCP server has its IP address range modified, the Windows client continues on with the old address until the DHCP lease expires. This is clearly a problem.

Windows offers a way to release and renew the DHCP lease through a program called winipcfg.exe, located in the C:\windows\system directory. Simply run winipcfg.exe, select the ethernet adapter from the drop-down list, click the Release button, and then click Renew.

Share ThisShare This

Informit Network