DHCP Server



DHCP (BOOTP) Server

Dynamic Host Configuration Protocol (DHCP) is a network protocol that automatically assigns TCP/IP information to client machines. 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. 





  ** DHCP uses DORA process to release the ip adresses to clients. ( Ref.Above image )
  ** DHCP server works with port number "67". 

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

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
 

Why Use DHCP?

DHCP is useful for automatic configuration of client network interfaces. When configuring the client system, you can choose DHCP instead of specifying an IP address, netmask, gateway, or DNS servers. The client retrieves this information from the DHCP server. DHCP is also useful if you want to change the IP addresses of a large number of systems. Instead of reconfiguring all the systems, you can just edit one configuration file on the server for the new set of IP addresses. If the DNS servers for an organization changes, the changes happen on the DHCP server, not on the DHCP clients. When you restart the network or reboot the clients, the changes go into effect.
If an organization has a functional DHCP server correctly connected to a network, laptops and other mobile computer users can move these devices from office to office. 

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

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.

 
 


# cat /etc/dhcp/dhcpd.conf

The sample configuration file can be found at /usr/share/doc/dhcp-<version>/dhcpd.conf.sample. You should use this file to help you configure /etc/dhcp/dhcpd.conf

               cp /usr/share/doc/dhcp-<version_number>/dhcpd.conf.sample /etc/dhcp/dhcpd.conf


 ** DHCP also uses the file /var/lib/dhcpd/dhcpd.leases to store the client lease database. 


Range parameter:

To configure a DHCP server that leases a dynamic IP address to a system within a subnet, modify Below Example, with your values. It declares a default lease time, maximum lease time, and network configuration values for the clients. This example assigns IP addresses in the range 192.168.1.10 and 192.168.1.100 to client systems. 

Example,
"
Range parameter
"

default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.1.254;
option domain-name-servers 192.168.1.1, 192.168.1.2;
option domain-search "example.com";
subnet 192.168.1.0 netmask 255.255.255.0 {
   range 192.168.1.10 192.168.1.100;
}


Static IP address using DHCP:

To assign an IP address to a client based on the MAC address of the network interface card, use the hardware ethernet parameter within a host declaration. As demonstrated in Below Example, the host ftp declaration specifies that the network interface card with the MAC address 00:A0:78:8E:9E:AA always receives the IP address 192.168.1.4.
Note that you can also use the optional parameter host-name to assign a host name to the client.

Example.
"
Static IP address using DHCP
"

host ftp {
   option host-name "ftp.example.com";
   hardware ethernet 00:A0:78:8E:9E:AA;
   fixed-address 192.168.1.4;
}


Definitions:


default_lease_time [seconds]—This option defines the length of time, in seconds, for an IP address lease if the client does not request a specific lease length.



max_lease_time [seconds]—This option defines the maximum length, in seconds, of a lease length. This is the maximum lease length a client may receive regardless of what it requests.



option domain_name ["domain"]—Defines the domain name.

option domain_name_servers [address_list]—Lists the addresses of the DNS name servers.



option ntp_servers [address_list]—Lists the addresses of the NTP (Network Time Protocol) servers the client is to use.

option routers [address_list]—Defines the default router.

option subnet_mask [mask]—Defines the subnet mask. If this option is undefined, the network mask from the subnet statement is used.





       

# chkconfig  dhcpd  on

# service  dhcpd status  



Configuring a DHCP Client

:
vi  
 /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp 
ONBOOT=yes

 save an exit
 
# service network restart

#ifconfig  eth0
 #ifup eth0

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

No comments:

Post a Comment