Configuring a DHCP Server in RHEL 6

DHCP- (Dynamc host configuration protocol)



Features:-


1- Dynamic Host Configuration Protocol (DHCP) is a network protocol that automatically assigns TCP/IP information to client machines.  
2-  Each DHCP client connects to the centrally located DHCP server, which returns the network configuration (including the IP address, gateway, and DNS servers) of that client. 
3- DHCP is also useful if you want to change the IP addresses of a large number of systems.
4- Includes all sorts of setting: IPv4, IPv6, DNS, NTP, NIS, Etc.
5- DHCP is an UDP application (UDP:67)


Package-       dhcp
Port-              67
Daemon-       dhcpd
Script-           /etc/init.d/dhcpd
Conf File-     /etc/dhcp/dhcpd.conf

Configure DHCP Server-

Step-1 Set Static IP address in dhcp server

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

IP Address- 192.168.0.254
NetMask-    255.255.255.0
Broadcast Address- 255.255.0.255

 # ifconfig eth0

Step-2 Install dhcp Package

 # yum install dhcp -y
  
Step-3 Check dhcp Documentation File

 # rpm -ql dhcp

/etc/dhcp                  (Container for DHCPD Configuration)
/etc/dhcp/dhcpd.conf            (IPv4 Config)
/etc/dhcp/dhcpd6.conf           (IPv4 Config)
/var/lib/dhcpd                        (Container for leases)
/var/lib/dhcpd/dhcpd.leases   (IPv4 leases)
/var/lib/dhcpd/dhcpd6.leases (IPv6 leases)

Step-4 Configure ‘/etc/dhcp/dhcpd.conf’ file

 # cd /etc/dhcp/
 # ls

dhclient.d  dhcpd6.conf  dhcpd.conf

 # vim /etc/dhcp/dhcpd.conf
__________________________________________________________
#
# DHCP server configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
# See ‘man 5 dhcpd.conf’

__________________________________________________________
Now Copy ‘/dhcpd.conf.sample’ file to ‘/etc/dhcp/dhcpd.conf’

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

Again open ‘/etc/dhcp/dhcpd.conf’ file

 # vim /etc/dhcp/dhcpd.conf            
__________________________________________________________
# option definitions common to all supported networks…
option domain-name “ashu.com”; ##–> Change Domain Name
option domain-name-servers  server.ashu.com;##–> Change Domain Name  Server

# define lease line
default-lease-time 600;
max-lease-time 7200;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;                ##—> Uncoment  this line

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
 
log-facility local6;                    

##–> Note- After DHCPD to log using a different Facility: i.e. ‘local6’ Because boot message are logged via: ‘local7’
##–> Checklog file’ # vim /etc/rssyslog.conf
##–> and mentation ‘local6.*   /var/log/dhcpd.log’
##–> Save boot messages also to boot.log
##–> local7.*           /var/log/boot.log
##–> local6.*           /var/log/dhcpd.log

#This is a very basic subnet declaration.

subnet 192.168.0.0 netmask 255.255.255.0 { ##—> Define Your Subnen mask and netmak,
range 192.168.0.10  192.168.0.50;   ##—> Define dhcp provide ip Range 
#option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
}

##–> Note- And Coment all line..
#
#
#
#
#

:wq!
__________________________________________________________

Step-5 Restart dhcp Service

 # /etc/init.d/dhcpd restart;chkconfig dhcpd on

or

 # service dhcpd restart
 # chkconfig dhcpd on

Step-6 Check Dhcpd Status

 # service dhcpd status
 # chkconfig –list dhcpd

dhcpd   0:off    1:off    2:on    3:on    4:on    5:on    6:off
DHCP use to assign ip address automaticaly in the netwok system.

Client Side-

1- Remove Static IP Then run ‘dhclient’ and Check…

 # dhclient
 # ifconfig

Server Side-

 How to Check dhcp lease log file…

 # cat /var/lib/dhcpd/dhcpd.leases
__________________________________________________________ 

# There are show Client information

 lease 192.168.0.10 {
  starts 5 2014/03/17 12:07:56;
  ends 5 2014/03/17 12:17:56;
  tstp 5 2014/03/17 12:17:56;
  cltt 5 2014/03/17 12:07:56;
  binding state free;
  hardware ethernet 00:0c:29:5d:1e:2c;
}
__________________________________________________________
or

# /var/log/dhcpd.log


__________________________________________________________ 

Mar 17 12:07:56 server dhcpd: DHCPDISCOVER from 00:0c:29:5d:1e:2c via eth0
Mar 17 12:07:56 server dhcpd: DHCPOFFER on 192.168.0.10 to 00:0c:29:5d:1e:2c via eth0
Mar 17 12:07:56 server dhcpd: DHCPREQUEST for 192.168.0.10 (192.168.0.254) from 00:0c:29:5d:1e:2c via eth0
Mar 17 12:07:56 server dhcpd: DHCPNAK on 192.168.0.10 to 00:0c:29:5d:1e:2c via eth0

__________________________________________________________
 

Note: DHCPD follows the DORA process:
D- Discovery (Client)
O- Offer (Server)
R- Request (Client)
A- Acknowledgement (Server)
First Option-

 
How to Bind Client MAC Address or Provide Particular IP to Client PC…

# vim /etc/dhcp/dhcpd.conf
__________________________________________________________ 

# Fixed IP addresses can also be specified for hosts. These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP.   Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
host ashu {                                           ##–> Host Nmae
  hardware ethernet 00:0c:29:5d:1e:2c; ##–> Client PC Mac
  fixed-address 192.168.0.20;               ##–> Defint IP
}

:wq
__________________________________________________________

service dhcpd restart;chkconfig dhcpd on
Client Side-

# ifdown eth0
# ifup eth0
# ifconfig eth0



Second Option-




How To Bind or Fix IP Address particular Systems or laptop-

For Example-
Suppose Your company in used 500+ above systems and laptops or Other Netwok Device..

like, 
200 system Sales Department.
330 System IT Support Team.
150 System Marketing Department.
20  System Acconut and HR Department.
5   System Admin Department.
Etc…

Now You Want to fix IP Address particular Systems or laptop…

When, 
You Have already create DHCP Server (and IP Range Define).
But This DHCP Server automatically provide any ip address.
It This Condition IP Trace is Very Difficult..

If you want To Fix Particular system..Fix IP Address.

Then,

How To Fix –   

Step-1 Configure DHCP server and define your network rang..

Note-


Check- First Option

How to Configure DHCP Server-

Step-2 open ‘/etc/dhcp/dhcpd.conf’ file and Edit…


# vim /etc/dhcp/dhcpd.conf    

__________________________________________________________

# option definitions common to all supported networks…
option domain-name “ashu.com”;                           ##–> Change Domain Name
option domain-name-servers  server.ashu.com;     ##–> Change Domain Name  Server

# define lease line
default-lease-time 600;
max-lease-time 7200;


# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;                ##—> Uncoment  this line

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).

log-facility local6;                      

##–> Note- After DHCPD to log using a different Facility: i.e. ‘local6’ Because boot message are logged via: ‘local7’ 
##–> Checklog file’     # vim /etc/rssyslog.conf 
##–> and mentation ‘local6.*   /var/log/dhcpd.log’ 
##–> Save boot messages also to boot.log
##–> local7.*           /var/log/boot.log
##–> local6.*           /var/log/dhcpd.log


#This is a very basic subnet declaration.

subnet 192.168.0.0 netmask 255.255.255.0 {   ##—> Define Your Subnen mask and netmak,
range 192.168.0.5  192.168.0.200;                 ##—> Define dhcp provide ip Range 
#option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
}

include “/etc/dhcp/sales.conf”;
include “/etc/dhcp/it.conf”;
include “/etc/dhcp/hr.conf”;

Note- You can also add other department file location like [ include “/etc/dhcp/admin.conf”; ]..

##–> Note- And Coment all line..
#
#
#
#
#

:wq! (Save & Quit)
__________________________________________________________

Step-3  open Particular Department File and Edit, and define particular system mac and ip address…

(1- Sales Team, 2 System Bind Mac Add..)


# vim /etc/dhcp/sales.conf


————————————————————

}
host  System-1 {
        hardware ethernet 20:CF:30:CB:52:76;
        fixed-address 192.168.0.20;
}
host  System-2 {
         hardware ethernet 20:CF:30:CB:53:78;
        fixed-address 192.168.0.21;
}

————————————————————

(2- IT Team, 3-System Bind MAC Add…)


# vim /etc/dhcp/it.conf


————————————————————

}
host  System-1 {
        hardware ethernet 20:CF:30:CB:54:79;
        fixed-address 192.168.0.30;
}
host  System-2 {
         hardware ethernet 20:CF:30:CB:55:80;
        fixed-address 192.168.0.31;
}

}
host  System-3 {
         hardware ethernet 20:CF:30:CB:56:81;
        fixed-address 192.168.0.32;
}

————————————————————


(3- HR Team, 1-System Bind MAC Add…)

# vim /etc/dhcp/hr.conf

————————————————————

}
host  System-1 {
        hardware ethernet 20:CF:30:CB:61:89;
        fixed-address 192.168.0.51;
}

————————————————————

Note-  If u want to add more Systems, you can also add more…

Step-4 Restart dhcp Service

# /etc/init.d/dhcpd restart;chkconfig dhcpd on

or

# service dhcpd restart
# chkconfig dhcpd on


Step-5 Now Check Client Side-

1- Remove Static IP Then run ‘dhclient’ and Check…

# dhclient
# ifconfig



Now Bind Process successfully has been completed…            

Leave a Reply

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