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 netmask {
        range;                   # Range of IP addresses to be issued to DHCP clients
           option broadcast-address;    # Default broadcastaddress to be used by DHCP clients
           option routers        ;      # Default gateway to be used by DHCP clients
		   option subnet-mask    ;    # Default subnet mask to be used by DHCP clients
           option domain-name              "";
           option domain-name-servers,;           # Default DNS to be used by DHCP clients
           option netbios-name-servers;    # 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    ;         # Default NTP server to be used by DHCP clients
#       option netbios-name-servers;
# --- 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 {
                hardware ethernet 16:bd:68:b5:4f:8e;

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

How to Change the IP address in LINUX

Method 1: Command Line

Step 1: Edit in /etc/sysconfig/network File

In order to change the IP address edit the following files:

# vim /etc/sysconfig/network

Step 2: Modify in Interface

To change the interface edit the following file:
# vim /etc/network/interfaces
Also change the network script file:

# vim /etc/sysconfig/network-scripts/ifcfg-eth0

Step 3: Restart Network

Now restart the network:

/etc/init.d/network restart

Method 2: GUI Environment

Step 1: Execute setup Command

# setup

Select Network Configuration Tab

Step 2: Select Device Configuration


Step 3: Select ethernet


Step 4: Modify Network Configurations

Once the changes have made, Select SAVE & QUIT and press ENTER key from keyboard.