How to configure DHCP server in Linux

Dynamic Host Configuration protocol (DHCP)This server is very useful if you are running a company with multiple clients where it becomes hard to manually assign the IP address manually so you redirect the client to take the IP from the server which is done using a DHCP server.

Prerequisites:

Make sure the required packge is installed in the machine.
# rpm -qa | grep dhcp
dhcp-4.1.1-31.P1.el6.i686
dhcp-common-4.1.1-31.P1.el6.i686
If the packages are not installed then follow these command for installation and configuration of the same
# yum -y install dhcp
Once the package is installed
# cd /etc/dhcp/

# vi dhcpd.conf
option domain-name “example.com”;
option domain-name-servers server.example.com;
default-lease-time 600;
max-lease-time 7200;
authoritative;

subnet 10.10.10.0 netmask 255.255.255.0 {
range dynamic-bootp 10.10.10.220 10.10.10.230;
option broadcast-address 10.10.10.255;
option routers 10.10.10.235;

(Use these lines if you want to assign a fix IP to a particular client, mention client’s IP with his/her MAC Address)

host ns {
hardware ethernet 08:00:07:26:c0:a5;
fixed-address 10.10.10.223;
}
}
Just save and restart your dhcp server services
# service dhcpd restart
Go to the client machine and make the following changes in ifcfg-eth0 file
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0c:29:6d:55:dd
NM_CONTROLLED=no
ONBOOT=yes
USERCTL=yes
TYPE=Ethernet
BOOTPROTO=dhcp
IPV6INIT=no
Restart your network services
# service network restart
and check the new IP of the your client machine

# ifconfig
 eth0      Link encap:Ethernet  HWaddr 00:0C:29:6D:55:DD
          inet addr:10.10.10.221  Bcast:10.10.10.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe6d:55dd/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:19730475 errors:81 dropped:12 overruns:0 frame:0
          TX packets:6731135 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2544186474 (2.3 GiB)  TX bytes:2956734996 (2.7 GiB)
          Interrupt:18 Base address:0x2000

As you can see the new IP assigned to this machine as assigned by my DHCP server

If you face any issues in doing the same kindly leave back your comments with the error.

Follow the below links for more tutorials:

Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to configure Samba 4 Secondary Domain Controller
How to secure Apache web server in Linux using password (.htaccess)
How to register Red Hat Linux with RHN (Red Hat Network )
Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
What is the difference between “su” and “su -” in Linux?
What is kernel-PAE in Linux?
What is swappiness and how do we change its value?
How to log iptables messages in different log file
What are the s and k scripts in the etc rcx.d directories
How to check all the currently running services in Linux
How to auto start service after reboot in Linux
What is virtual memory, paging and swap space?

Leave a Comment

close button