[ Team LiB ] Previous Section Next Section

11.3 Setting Up a DHCP Server

Managing the network configurations of the hosts on even a small network can be tedious. Administrators of large networks, including ISPs, have long used the DHCP service to centrally manage network configurations. Red Hat Linux includes a DHCP server that you can install in order to facilitate the management of your network. Hosts configured with DHCP clients can load their network configurations from the DHCP server at boot time, including such configuration items as:

  • Hostname

  • Domain name

  • IP address

  • Netmask

  • Broadcast IP address

  • Gateway IP address

  • DNS server address

11.3.1 Installing the DHCP Server

Before installing the DHCP server, you should check whether your system's network adapter is properly configured to support DHCP. To do so, issue the ifconfig command as root:

# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:A0:CC:25:8A:EC  
          inet addr:192.168.0.5  Bcast:192.168.255.255  
            Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:71910 errors:0 dropped:0 overruns:0 
            frame:0
          TX packets:108334 errors:0 dropped:0 overruns:0 
            carrier:0
          collisions:89 txqueuelen:100 
          Interrupt:11 Base address:0x6000

If your system's network adapter is properly configured to support DHCP, the output of the ifconfig command will indicate that the adapter supports BROADCAST. If the output doesn't include this specifications, you must reconfigure or replace the network adapter. Fortunately, it's rare that an adapter lacks these capabilities.

To set up a DHCP server, use the Package Management Tool to install the dhcp package, which is part of the Network Servers package group. In doing so, be sure to disable the checkboxes associated with any unwanted services. Then, configure the service as explained in the following section.

11.3.2 Configuring the DHCP Service

To configure the DHCP service, you must create the DHCP configuration file, /etc/ dhcpd.conf. Here's a simple configuration that you can use as a starting point:

ddns-update-style ad-hoc;
default-lease-time 64800;
max-lease-time     64800;
option domain-name-servers 192.168.0.1;
option domain-name         "oreilly.com";
subnet 192.168.0.0 netmask 255.255.255.0
{
  option subnet-mask         255.255.255.0;
  option broadcast-address   192.168.0.255;
  option routers             192.168.0.1;
  server-identifier 192.168.0.5;
  host sara 
  {
    hardware ethernet  00:50:04:d2:3f:15;
    fixed-address      192.168.0.33;
    default-lease-time 86400;
  }
  range 192.168.0.50 192.168.0.254;
}

When a DHCP client obtains a network configuration from the server, it doesn't generally obtain the configuration permanently. Instead, a DHCP client is said to lease a configuration. The two lines at the top of the configuration file specify the default and maximum lease duration, in seconds. The figure 64800 (seconds) is equivalent to 18 hours. By choosing a relatively long lease time, a client will not generally need to renew its leased network configuration during a workday. You can choose a shorter or longer duration, as you prefer.

The next two lines specify information transmitted to clients as part of their network configurations:

domain-name-servers

The DNS server IP address. More than one server can be specified. Each server is separated from its neighbor by a comma.

domain-name

The domain name.

Next comes a group of lines�delimited with paired curly braces�that define a network or subnetwork. In this case, the network defined has the IP address 192.168.0.0 with a netmask of 255.255.255.0. This means that the range of network addresses is from 192.168.0.0 to 192.168.0.255.

Hosts in this network share three parameters:

subnet-mask

The network mask, which indicates by 1-bits the bit positions of the IP address associated with the network, rather than the host. Often, the network mask has the value 255.255.255.0.

broadcast-address

The IP address of the network, with all 1-bits in the bit positions associated with the host address. Often, this means that the first three members of the dotted quad IP address appear, followed by the value 255.

routers

The default gateway IP address.

The next set of lines define the network configuration for a particular host, named sara:

host sara 
  {
    hardware ethernet  00:50:04:d2:3f:15;
    fixed-address      192.168.0.33;
    default-lease-time 86400;
  }

The host's network adapter has an Ethernet MAC address of 00:50:04:d2:3f: 15. The Ethernet address is a unique code, assigned by the adapter's manufacturer, that serves to identify the adapter. When it queries the DHCP server, this adapter will be leased the IP address 192.168.0.33; the lease will have a duration of 24 hours (86400 seconds). This adapter will always receive this IP address, which is also known as a static IP address.

The next line defines a range of IP addresses:

range 192.168.0.50 192.168.0.254;

Hosts not assigned a static IP address will be leased an address within the specified range. Such an IP address is termed a dynamic IP address.

For more information about the dhcpd.conf file, see the associated manpage.

11.3.3 Starting the DHCP Service

To start the DHCP service, launch the Service Configuration Tool by choosing Server Settings Services from the GNOME or KDE menu. Select the list entry associated the DHCP service, named dhcpd, and click Start.

To verify that the DHCP service has started, issue the following command to view recent system log entries:

$ tail -40 /var/log/messages

You should see something like the following:

Nov  3 11:35:39 localhost dhcpd: Internet Software Consortium DHCP Server V3.0pl1
Nov  3 11:35:39 localhost dhcpd: Copyright 1995-2001 Internet Software Consortium.
Nov  3 11:35:39 localhost dhcpd: All rights reserved.
Nov  3 11:35:39 localhost dhcpd: For info, please visit http://www.isc.org/products/DHCP
Nov  3 11:35:39 localhost dhcpd: Wrote 0 deleted host decls to leases file.
Nov  3 11:35:39 localhost dhcpd: Wrote 0 new dynamic host decls to leases file.
Nov  3 11:35:39 localhost dhcpd: Wrote 0 leases to leases file.
Nov  3 11:35:39 localhost dhcpd: 
Nov  3 11:35:39 localhost dhcpd: Listening on LPF/eth0/00:50:da:76:59:fd/192.168.0.0/24
Nov  3 11:35:39 localhost dhcpd: Sending on   LPF/eth0/00:50:da:76:59:fd/192.168.0.0/24
Nov  3 11:35:39 localhost dhcpd: Sending on   Socket/fallback/fallback-net
Nov  3 11:35:39 localhost dhcpd: dhcpd startup succeeded

Now, boot a client configured to obtain its network configuration via DHCP. If you need help configuring a client to use DHCP, consult the next section. If the DHCP client and server are working, you should see system log messages that resemble the following:

Nov  3 11:59:40 localhost dhcpd: DHCPREQUEST for 
  192.168.0.4 from 00:50:04:d2:3f:15 via eth0
Nov  3 11:59:40 localhost dhcpd: DHCPACK on 192.168.0.4 to 
  00:50:04:d2:3f:15 via eth0

If you find that the DHCP server is not working, consult the file /usr/share/doc/dhcp- */README.

What often appears to be a problem with a DHCP server is most likely a problem with the DHCP client. If you have difficulty getting the DHCP service to work properly, configure the client as explained in the next section. Another common problem is configuring multiple DHCP servers on the same network. In order to avoid conflicts between servers, you should generally operate only a single DHCP server on your network.

If you want the DHCP service to start automatically when you boot your system, use the Service Configuration Tool to associate the service with the desired runlevel or runlevels.

11.3.4 Configuring DHCP Clients

To configure a Windows 9x client to use DHCP, select Start Settings Control Panel Network Configuration to open the TCP/IP Properties dialog box. Select the TCP/IP network component associated with the network adapter you want to configure and click Properties. Select the IP Address tab and choose Obtain an IP address automatically. Then select the DNS tab and choose Disable DNS. This setting does not actually disable DNS; it merely configures the system to rely on DHCP to provide the IP address of the DNS server.

Next, select the Gateway tab and remove any installed gateways. Click OK to dismiss the TCP/IP Properties dialog box, and click OK again to dismiss the Network Properties dialog box. You can use a similar procedure to configure Windows NT/ 2000 clients.

Windows 9x lets you view leased network configuration information. To do so, run the program winipcfg and select the proper adapter. The program shows the Ethernet address, IP address, subnet mask, and default gateway associated with the client, if any. Click More to view additional information, such as hostname, DNS server IP address, and the lease expiration time. You can manually release or renew a lease by clicking Release or Renew.

Under Windows 2000 and XP, you can view similar information describing the network configuration by issuing the command:

$ ipconfig /all

To configure a Linux client to use DHCP, launch the Network Administration Tool. Select the Devices tab and click the interface you want to configure. Click Edit to view the Ethernet Device dialog box. Finally, enable the checkbox labelled Automatically obtain IP address settings with, choose DHCP from the drop-down box, and click OK. To determine the status of a DHCP lease held by a Linux client, you can search the system log for relevant messages.

    [ Team LiB ] Previous Section Next Section