Search This Blog

Sunday 21 April 2019

DHCP (Dynamic Host Configuration Protocol)


1. What is  DHCP  and  explain it?
       ->DHCP  stands  for  Dynamic  Host  Configuration  Protocol.  
       ->DHCP is a network protocol that enables the server to assign an  IP addresses to the clients in               the network automatically from a defined range of IP addresses  ie., scope configured for a                   given network.
       ->DHCP  allows a computer to join in an IP-based network without having a pre-configured  IP               address.  
       ->DHCP  is a protocol that assign unique IP addresses to devices,  then releases  and  renew                     those addresses as devices leave  and  rejoin in the network.
       ->Internet  Service  Providers  (ISPs) usually use  DHCP  to help customers join their networks              with minimum setup effort required. Likewise,  home network equipment like broadband                    routers offers  DHCP  support to joining  home computers to  Local  Area  Networks  (LANs).
      -> In  simple terms  DHCP is used to assign the  IP addresses to the remote hosts  automatically.               First client requests to the  DHCP  server,  then  DHCP  server accepts the client's request  and             assign the next available  IP address to the requested  DHCP  client.

2. How  the  DHCP  works?
The  process of requesting the  IP address from the  DHCP  clients  and  assign the  IP address             by the  DHCP  server is called  "D O R A".
(i) When we switch on the system with  DHCP  client,  the client system sends the  broadcast                    request  looking for a  DHCP  server to answer.  This  process is called  DISCOVER  or                  DHCP DISCOVER.
(ii) The  router directs the  DISCOVER  packet to the correct  DHCP  server.
(iii)  The server receives the  DISCOVER  packet.  Based on availability  and  usage policies set                   on the server,  the server determines an appropriate address  (if  any) to give to the client.                  The server then temporarily reserves that address for the client and sends back to the                        client an  OFFER  orDHCP OFFER  packet with that address information.  The server                    also configures the client's  DNS  servers,  WINS  servers,  NTP  serves  and  sometimes                  other  services also.
(iv) Then  the  Client sends  a  REQUEST  or  DHCP REQUEST  packet,  letting the server                         know that it intends to use the address.
(v) Then  the  server sends  an  ACK  or  DHCP ACK  packet,  conforming that the client has                     been given  a  lease on the address for a  server  specified  period  of  time.

3. What is the disadvantage to assign the  Static  IP address?
When  a  system uses  a  static  IP address,  It means that the system is manually configured to             use a specific  IP address.  One problem with static assignment, which can result from user                 error  or  inattention  to detail,  occurs when two systems are configured with the same  IP                   address.  This creates a conflict that results in loss of service.  Using  DHCP  to  dynamically               assign  IP addresses  to  avoid  these  conflicts.

4. What is the profile of  DHCP?
Package         : dhcp*
Script  file : /etc/init.d/dhcpd
Configuration  file : /etc/dhcp/dhcpd.conf
Deamon         : dhcpd
Port  numbers         : 67  (dhcp  server)  and  68  (dhcp  client)
Log  messages : /var/log/messages

5. How to configure the  DHCP  server?
(i) Assign  a  static  IP address  to the  DHCP server.
(ii) Install the  DHCP  package by  # yum  install  dhcp*   -y    command.
(iii) Open the  DHCP  configuration  file by  # vim   /etc/dhcp/dhcpd.conf   command.  This file                 is empty  and we have to copy the sample file from  /usr/share/doc/dhcp-                                         4.25/dhcpd.conf.example  to  the above location by  # cp   -p   /usr/share/doc/dhcp-                           4.25/dhcpd.conf.example    /etc/dhcp/dhcpd.conf    command.
(iv) Now  open the above  DHCP  configuration file by  # vim   /etc/dhcp/dhcpd.conf                                   command.
*   Go to line number   47  and  edit that line as below.
subnet     <DHCP  server  Network  ID>     netmask     <subnetmask  of the this network>   {
range    <starting  IP address><ending  IP address>;
default-lease-time    600; (the minimum  lease  time to the client  in  seconds)
max-lease-time    7200; (he maximum  lease  time to the client  in  seconds)
}
Example :
subnet     172.25.0.0    netmask    255.255.255.0   {
range    172.25.9.50    172.25.9.100;
default-lease-time    600;
max-lease-time    7200;
}
*  Go to line number   51  and  edit that as below.
option  routes    <DHCP  server  IP address>;
option  broadcast-address     <DHCP  server  broadcast  address>;
Example :
option  routes     172.25.9.11;
option  broadcast-address     172.25.9.255; (save  and  exit  this  file)
(v) Restart  the  DHCP services  in  RHEL - 6  and   RHEL - 7.
# service  dhcpd  restart (to restart the  DHCP  service  in  RHEL - 6)
# chkconfig  dhcpd  on         (to enable the  DHCP service at next boot  in  RHEL - 6)
# systemctl  restart  dhcpd (to restart the  DHCP  service  in  RHEL - 7)
# systemctl  enable  dhcpd         (to enable the  DHCP service at next boot  in  RHEL - 7)
(vi) Add the  DHCP  service to the  IP tables  and  Firewall.
In  RHEL - 6:
# iptables    -A   INPUT       -p   udp   -i   eth0    --deport    67   -j    ACCEPT
# iptables    -A   INPUT       -p   tcp    -i   eth0    --deport    67   -j    ACCEPT
# iptables    -A   INPUT       -p   udp   -i   eth0    --deport    68   -j    ACCEPT
# iptables    -A   INPUT       -p   tcp    -i   eth0    --deport    68   -j    ACCEPT
# iptables    -A   OUTPUT   -p   udp   -i   eth0    --deport    67   -j    ACCEPT
# iptables    -A   OUTPUT   -p   tcp    -i   eth0    --deport    67   -j    ACCEPT
# iptables    -A   OUTPUT   -p   udp   -i   eth0    --deport    68   -j    ACCEPT
# iptables    -A   OUTPUT   -p   tcp    -i   eth0    --deport    68   -j    ACCEPT
In  RHEL - 7 :
# firewall-cmd      --permanent     --add-service=dhcp
# firewall-cmd     --complete-reload
(vii) # cat  /var/lib/dhcpd/dhcpd.lease(to see the DHCP lease message database on DHCP server)

6. How to configure the  DHCP  client?
(i) Change the  IP addressing  from  static to  dynamic if it is configured as  static.
In  RHEL - 6 :
# setup
                Network Configuration ---> Press Enter--->Device Configuration ---> Select eth0--->Enter
                ---> Use DHCP --->Press Spacebar --->OK--->Save--->Save & Quit
# service  NetworkManager  restart
# service  network  restart
In  RHEL - 7:
# nmcli  connection  modify  "System  eth0"   ipv4.method    auto  or  dynamic
# nmcli  connection  down  "System  eth0"
# nmcli  connection  up  "System  eth0"
# systemctl  restart  network
(ii) Open   /etc/sysconfig/network-scripts/ifcfg-eth0    file  and  edit  the  BOOTPROTO  line.
# vim   /etc/sysconfig/network-scripts/ifcfg-eth0 
  *   Go to  BOOTPROTO   line  and  edit that line as below.
  BOOTPROTO=dhcp (save  and  exit  this  file)
(iii) Get the  IP address  from the  DHCP  server.
# dhclient
# ifdown  eth0
# ifup  eth0

7. How to fix the IP address to the client every time it requests  or  how to configure the  MAC                 binding?
The  process  of  assigning the same  IP address  (fixed  IP  address)  to  the  DHCP  client                     every time  it  booted  is  called  "MAC  binding".
(i) Open the file   /etc/dhcp/dhcpd.conf by   # vim   /etc/dhcp/dhcpd.conf    command.
*   Go to line  number   76  and  77  and  edit those lines as below.
host   <dhcp  client  hostname>    {
hardware  ethernet <MAC  address  of the  Client's  NIC  card>;
fixed  addresses <IP  address>;
}
Example :
host    client 1    {
hardware   ethernet    2015:ac18::55;
fixed  addresses    172.25.9.150;
} (save  and  exit  this  file)
(ii) Restart  the  DHCP services  in  RHEL - 6  and   RHEL - 7.
# service  dhcpd  restart (to restart the  DHCP  service  in  RHEL - 6)
# chkconfig  dhcpd  on (to enable the  DHCP service at next boot  in  RHEL - 6)
# systemctl  restart  dhcpd (to restart the  DHCP  service  in  RHEL - 7)
# systemctl  enable  dhcpd (to enable the  DHCP service at next boot  in  RHEL - 7)
*   Then  the above  MAC  address of the system will get the same  IP  address  every time it booted.

No comments:

Post a Comment