Dynamic Host Configuration Protocol (DHCP) is used to assign IP addresses, gateway and DNS details automatically to the clients.
we need to configure DHCP server to offering ipaddress details to the clients when it is required.
DHCP Server:
server.local, IP address: 192.168.1.5
DHCP Client:
client.local, IP address: 192.168.1.6
Step 1: DHCP Installation
Run the below command to install dhcp server and client.
[root@server.local ~]#yum install dhcp
Step 2: Assign static ip address to dhcp server
[root@server.local ~]#vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
HWADDR="00:10:5A:44:12:C5"
NM_CONTROLLED="yes"
ONBOOT="yes"
BOOTPROTO="none"
IPADDR=192.168.1.5
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
Step 3: Interface configuration
If you have more than one network interface card in your server then we need to specify on which interface our server will be listen for dhcp request.
By default eth0 interface is listen to dhcp.
[root@server.local ~]#vi /etc/sysconfig/dhcpd
Add the below line;
DHCPDARGS=eth0
Step 4: DHCP Configuration
[root@server.local ~]#cp /usr/share/doc/dhcp-*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
[root@server.local ~]#vi /etc/dhcp/dhcpd.conf
Make the changes according to your environment setup. Below is the sample configuration for my linux setup.
#specify domain name
option domain-name "example.com";
#specify DNS server ip and additional DNS server ip
option domain-name-servers 192.168.1.100, 192.168.1.200;
#specify default lease time
default-lease-time 600;
#specify Max lease time
max-lease-time 7200;
#specify log method
log-facility local7;
#Configuring subnet and iprange
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.1 192.168.1.254;
option broadcast-address 192.168.1.255;
#Default gateway ip
option routers 192.168.1.1;
}
#Fixed ip address based on MAC id
host laserjet
{
hardware ethernet 00:10:5A:44:15:Z5;
fixed-address 192.168.1.50;
}
Step 5: Start the DHCP service
[root@server.local ~]#/etc/init.d/dhcpd start
[root@server.local ~]#chkconfig dhcpd on
Step 6: Configuring a DHCP Client
Log in to client machine (client.local/192.168.1.6) and perform the below steps on linux terminal.
[root@client.local ~]#vi /etc/sysconfig/network
NETWORKING=yes
[root@client.local ~]#vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
Restart the network services
[root@client.local ~]#/etc/init.d/network restart
Check your ip address and network details.
[root@client.local ~]#ifconfig -a
[root@client.local ~]#cat /etc/resolv.conf
Below command is used to view your current DHCP leases machines.( from DHCP Server)
[root@server.local ~]#cat /var/lib/dhcpd/dhcpd.leases
That’s it!