HOW TO CONFIGURE DHCP IN LINUX

0
568

Installing a DHCP Server

Strangely, the DHCP server package is called dhcp, while the service is called dhcpd.

Step 1. Start by installing the dhcp package:

# yum install -y dhcp

Step 2. Verify that the package is installed correctly:

# rpm -qa | grep dhcp

dhcp-4.1.1-12.P1.el6.x86_64

Step 3. With the package installed, make sure that the dhcpd service starts when the system boots as well:

# chkconfig dhcpd on

Configuring the DHCP Server

To start the configuration, let’s look at the important files that handle the options for the DHCP service:

/etc/dhcp/dhcpd.conf                  Main config file for the DHCP service using IPv4 addresses

/etc/dhcp/dhcpd6.conf                Main config file for the DHCP service using IPv6 addresses

/var/lib/dhcpd/dhcpd.leases        IPv4 client lease file

/var/lib/dhcpd/dhcpd6.leases      IPv6 client lease file

The main config file is usually empty aside from a comment or two. The good news is that the package does provide a sample config file for you to use. This sample file provides examples and comments on how you can configure options for your DHCP server.

To copy the sample file, use the following command:

# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

If you are new to working with DHCP servers, this sample file will prove helpful in that the comments included in the file explain the different options. The following sample config file gives you the basics to get started. It is less cluttered than the sample, so it is easier to explain.
Here is the sample DHCP server config file:

# Global Options
ddns-update-style none;
authoritative;
# Subnet definition
/etc/dhcp/dhcpd.conf Main config file for the DHCP service using IPv4 addresses
subnet 172.168.1.0 netmask 255.255.255.0 {
# Parameters for the local subnet
option routers 172.168.1.1;
option subnet-mask 255.255.255.0;
option domain-name “example.com”;
option domain-name-servers 172.168.1.1;
default-lease-time 21600;
max-lease-time 43200;
# Client IP range
range dynamic-bootp 172.168.1.100 172.168.1.200;
}

ddns-update-style: none
This means that the DHCP server won’t update client DNS records.

authoritative
This informs the client that the DHCP server contains legitimate information.

The next section defines a subnet. Any options that you list in a subnet section are specific to the subnet for which you define them. If you want to set global options (such as authoritative), you need to define them outside the subnet section. In this section, the following options are used:

option routers- Defines the default gateway to the subnet

option subnet-mask Defines the subnet mask for the subnet

option domain-name Defines the name of the domain

option domainname-servers Defines the DNS server for the subnet

default-lease-time Specifies how long each client keeps its lease until a renewal is requested (in seconds)
max-lease-time Specifies the maximum amount of time a client can keep a lease (in seconds)
range dynamic-bootp Specifies the range of IP addresses that can be given out to clients

HOW TO START DHCP SERVICE

# service dhcpd start

Starting dhcpd: [ OK ]

Verify that the service is running:

# service dhcpd status

dhcpd (pid 3366) is running...

HOW TO STOP DHCP SERVICE

# service dhcpd stop

Stopingg dhcpd: .....................................................[ OK ]

Comments

comments