Installing DHCP in Linux

Before starting with anything I would like to give a brief about the DHCP:

Dynamic Host Configuration Protocol (DHCP) is a protocol used by networked devices (clients) to obtain various parameters necessary for the clients to operate in an Internet Protocol (IP) network. By using this protocol, system administration workload greatly decreases, and devices can be added to the network with minimal or no manual configurations.

Dynamic Host Configuration Protocol is a way to administer network parameter assignment at a single DHCP server, or a group of such servers arranged in a fault-tolerant manner. Even in a network which has a few machines, Dynamic Host Configuration Protocol is useful, because a machine can be added to the local network with little effort.

Even for servers whose addresses rarely change, DHCP is recommended for setting their addresses, so if the servers need to be readdressed (RFC2071), the changes need to be made in as few places as possible. For devices, such as routers and firewalls, that should not use DHCP, it can be useful to put Trivial File Transfer Protocol (TFTP) or SSH servers on the same machine that runs DHCP, again to centralize administration.

DHCP is also useful for directly assigning addresses to servers and desktop machines, and, through a Point-to-Point Protocol (PPP) proxy, for dialup and broadband on-demand hosts, as well as for residential Network address translation (NAT) gateways and routers. DHCP is usually not appropriate for infrastructure such as non-edge routers and DNS servers

Basic Protocol Operation:

The Dynamic Host Configuration Protocol (DHCP) automates the assignment of IP addresses, subnet masks, default gateway, and other IP parameters.

When a DHCP-configured client (be it a computer or any other network aware device) connects to a network, its DHCP client sends a broadcast query requesting necessary information from a DHCP server. The DHCP server manages a pool of IP addresses and information about client configuration parameters such as the default gateway, the domain name, the DNS servers, other servers such as time servers, and so forth. Upon receipt of a valid request the server will assign the computer an IP address, a lease (the length of time for which the allocation is valid), and other TCP/IP configuration parameters, such as the subnet mask and the default gateway. The query is typically initiated immediately after booting and must be completed before the client can initiate IP-based communication with other hosts.

DHCP provides three modes for allocating IP addresses. The best-known mode is dynamic, in which the client is provided a "lease" on an IP address for a period of time. Depending on the stability of the network, this could range from hours (a wireless network at an airport) to months (for desktops in a wired lab). At any time before the lease expires, the DHCP client can request renewal of the lease on the current IP address. A properly-functioning client will use the renewal mechanism to maintain the same IP address throughout its connection to a single network, otherwise it may risk losing its lease while still connected, thus disrupting network connectivity while it renegotiates with the server for its original or a new IP address.

The two other modes for allocation of IP addresses are automatic (also known as DHCP Reservation), in which the address is permanently assigned to a client, and manual, in which the address is selected by the client (manually by the user 1 required (typical of tight firewall setups), although typically a firewall will allow access to the range of IP addresses that can be dynamically allocated by the DHCP server.


To know more about DHCP in detail, check Wikipedia.

Installation:

Before installing DHCP make sure, rather than use the default DHCP server included with your Red Hat / Fedora Linux System, I recommend that you pop over to the Internet Software Consortium and Download the latest version of the DHCP Server. As I write this, it's at version 4.1.0a1.

Why is it important to have the latest version? In a word, security. As with any software that you're going to run on your server, it's critically important that you have the very latest version of this 'daemon' (as we Linux geeks call programs that run on the server without intervention) on your system. It's also very important to shut off any services you aren't using.

So once you've downloaded the latest version of the software, you'll want to unpack it with:

$ tar xzf ./dhcp-303-tar.gz

Now, move to the new directory that contains all the source and type in the following commands (the tons of output these commands have has been deleted to save our sanity here):

$ ./configure
$ make

Assuming all has gone well, switch to root by using the sudo command and install the new server:

$ sudo make install

you'll be prompted for the root password, then, if you typed it in correctly, the new DHCP server will be installed onto your system.

Good. Now you have the latest DHCP server it's time to configure it properly for your environment. This is best done by copying the file server/dhcp.conf from the installation directory into your /etc directory, like this:

$ sudo cp server/dhcp.conf /etc

This time, since you just did a sudo command a few seconds ago, you won't be prompted for your password (an exceedingly slick feature of sudo, actually!)

Now, again using sudo, it's time to edit the configuration file to match your system configuration. Here's what the dhcp.conf file looks like:

ddns-update-style interim # Redhat Version 8.0+

subnet 192.168.1.0 netmask 255.255.255.0 {

# The range of IP addresses the server will issue to
# DHCP enabled PC clients booting up on the network

range 192.168.1.201 192.168.1.220;

# Set the amount of time in seconds that
# a client may keep the IP address

default-lease-time 86400;
max-lease-time 86400;

# Set the default gateway to be used by
# the PC clients

option routers 192.168.1.1;

# Don't forward DHCP requests from this NIC interface
# to any other NIC interfaces

option ip-forwarding off;

# Set the broadcast address and subnet mask
# to be used by the DHCP clients

option broadcast-address 192.168.1.255;
option subnet-mask 255.255.255.0;

# Set the DNS server to be used by the
# DHCP clients

option domain-name-servers 192.168.1.100;

# Set the NTP server to be used by the
# DHCP clients

option nntp-server 192.168.1.100;

# If you specify a WINS server for your Windows clients,
# you need to include the following option in the dhcpd.conf file:

option netbios-name-servers 192.168.1.100;

}

# List an unused interface here
#
subnet 192.168.2.0 netmask 255.255.255.0 {
}

# You can also assign specific IP addresses based on the clients'
# ethernet MAC address as follows (Host's name is "smallfry":

host smallfry {
hardware ethernet 08:00:2b:4c:59:23;
fixed-address 192.168.1.222;
}

As with many Linux configuration files, this is actually fairly well documented, especially since you should be able to type man dhcp-options to get an exhaustive explanation of each and every configuration option.

In particular, make sure you set the domain name properly, identify your set of DNS servers by name, and define the subnet range for which you want to provide services via DHCP.

Once that's all configured to your liking, a little bit more tweaking is required to get everything checked and started properly:

$ sudo touch /var/lib/dhcp/dhcp.leases

Will make sure that you have a 'leases' file, a critical part of how the DHCP server tracks what systems it's seen and serviced.

$ sudo chkconfig --level 35 dhcpd on

This will check your configuration and make sure it will be added to the list of daemons to start up at boot time from now on. Very useful if you don't want to remember to restart it each time!

$ /etc/init.d/dhcp restart

Now you should be running a DHCP server on your system. Check to make sure it's running by using ps aux | grep dhcp !


1 comments:

Anonymous said...
This comment has been removed by a blog administrator.

GosuBlogger