How to Configure DHCP Server in Linux

The Dynamic Host Configuration Protocol (DHCP) is a standardized network protocol used on Internet Protocol (IP) networks for dynamically distributing network configuration parameters, such as IP addresses for interfaces and services. With DHCP, computers request IP addresses and networking parameters automatically from a DHCP server, reducing the need for a network administrator or a user to configure these settings manually.

By default Port # 67,68

Step 1: Installation

For RedHat/Fedora:

# yum install dhcp

For Debian/Ubuntu:

# apt-get install dhcp3-server

Step 2: Configuration

Make a copy of sample dhcpd.conf file from /usr/share/doc/dhcp-3.X/dhcp.conf.sample and modify the /etc/dhcpd.conf file.
Note: In RHEL 5 the configuration file location is /etc/dhcpd.conf

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

For RedHat/Fedora:

# vi /etc/dhcpd.conf

For Debian/Ubuntu:

# vi /etc/default/dhcp3-server
ddns-update-style interim;

ignore client-updates;
subnet 192.168.1.0 netmask 255.255.255.0 {
 
        range 192.168.1.128 192.168.1.254;                   # Range of IP addresses to be issued to DHCP clients
           
           option broadcast-address        192.168.1.255;    # Default broadcastaddress to be used by DHCP clients
           option routers                  192.168.0.254;      # Default gateway to be used by DHCP clients
		   option subnet-mask              255.255.255.0;    # Default subnet mask to be used by DHCP clients
           option domain-name              "tecdistro.com";
           option domain-name-servers      40.175.42.254, 40.175.42.253;           # Default DNS to be used by DHCP clients
           option netbios-name-servers     192.168.1.100;    # Specify a WINS server for MS/Windows clients.
                                                             # (Optional. Specify if used on your network)
#         DHCP requests are not forwarded. Applies when there is more than one ethernet device and forwarding is configured.
#       option ipforwarding off;
        default-lease-time 21600;                            # Amount of time in seconds that a client may keep the IP address
        max-lease-time 43200;
        option time-offset              -18000;              # Eastern Standard Time
#       option ntp-servers              192.168.1.1;         # Default NTP server to be used by DHCP clients
#       option netbios-name-servers     192.168.1.1;
# --- Selects point-to-point node (default is hybrid). Don't change this unless you understand Netbios very well
#       option netbios-node-type 2;
        # We want the nameserver "ns2" to appear at a fixed address.
        # Name server with this specified MAC address will recieve this IP.
        host ns2 {
                next-server ns2.tecdistro.com;
                hardware ethernet 16:bd:68:b5:4f:8e;
                fixed-address 40.175.42.254;
        }
}

Step 3: Test Configuration

Test the configuration by using the following command.

# service dhcpd configtest

Step 4: Restart Service

In the end, restart the DHCP server.

# service dhcpd restart

Also configure dhcpd service to start on system start.

# chkconfig dhcpd on
# cat /var/lib/dhcp/dhcpd.leases
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

eighteen + one =