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

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 follows:

[root@localhost]# 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 and MULTICAST. If the output doesn’t include these 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 GnoRPM to install the dhcp package. Then, configure the service as explained in the following section.

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:

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 appearing in column 1—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.

Starting the DHCP Service

Before starting the DHCP service for the first time, you must create the file that DHCP uses to store information on current leases. The file need not have any particular content; an empty file will do. To create the file, issue the following command:

               touch /var/lib/dhcp/dhcpd.leases

Now, the DHCP service can be started. To do so, issue the command:

               service dhcpd 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:

May  5 11:57:39 localhost dhcpd: Internet Software Consortium 
  DHCP Server 2.0pl5
May  5 11:57:39 localhost dhcpd: Copyright 1995, 1996, 1997, 
  1998, 1999 The Internet Software Consortium.
May  5 11:57:39 localhost dhcpd: All rights reserved.
May  5 11:57:39 localhost dhcpd: 
May  5 11:57:39 localhost dhcpd: Please contribute if you find 
  this software useful.
My  5 11:57:39 localhost dhcpd: For info, please visit 
  http://www.isc.org/dhcp-contrib.html
May  5 11:57:39 localhost dhcpd: 
May  5 11:57:39 localhost dhcpd: Listening on 
  Socket/eth0/192.168.0.0
May  5 11:57:39 localhost dhcpd: Sending on   
  Socket/eth0/192.168.0.0
May  5 11:57: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:

May  5 11:59:40 localhost dhcpd: DHCPREQUEST for 
  192.168.0.4 from 00:50:04:d2:3f:15 via eth0
May  5 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. Due to an error, this HTML file lacks the file extension .html. To view the file, first rename it, like so:

               cd /usr/share/doc/dhcp-*
               mv README README.html

Then view it with Links, Netscape Navigator, Konqueror, or some other web browser.

Tip

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 subsection. 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.

You can use the service command to control the DHCP service. To stop the server, issue this command:

               service dhcpd stop

To stop and restart the DHCP service, issue this command:

               service dhcpd restart

This command reports the current status of the server:

               service dhcpd status

If you want the DHCP service to start automatically when you boot your system, issue the command:

               chkconfig --level 345 dhcpd on

Or use Neat to configure the service to start automatically.

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 winipcfgand 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, you can view similar information describing the network configuration by issuing the command:

ipconfig /all

To configure a Linux client to use DHCP, launch Neat: select Config Networking Client Tasks Basic Host Information, and set the following options for the adapter:

  • Enabled

  • Config Mode DHCP

You can view the status of a DHCP lease on a Linux client by issuing the command:

               /sbin/pump -s

To release and renew a lease, issue the command:

               /sbin/pump -i eth0 -R

If the lease is associated with an adapter other than eth0, revise the command accordingly.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset