Saturday, 29 March 2014

DHCP Server Configuration in RHEL 5 ?

How to configure DHCP Server in RHEL 5

What is DHCP ?

Dynamic Host Configuration Protocol (DHCP) is a network protocol that enables a server to automatically assign an IP address to a computer from a defined range of numbers (i.e., a scope) configured for a given network.

DHCP (Dynamic Host Configuration Protocol) is a communications that lets network administrators centrally manage and automate the assignment of Internet Protocol IP addresses in an organization's network. Using the Internet Protocol, each machine that can connect to the Internet needs a unique IP address, which is assigned when an Internet connection is created for a specific computer. Without DHCP, the IP address must be entered manually at each computer in an organization and a new IP address must be entered each time a computer moves to a new location on the network. DHCP lets a network administrator supervise and distribute IP addresses from a central point and automatically sends a new IP address when a computer is plugged into a different place in the network.


RFCs 2131 and 2132 define DHCP as an Internet Engineering Task Force (IETF) standard based on Bootstrap Protocol (BOOTP), a protocol with which DHCP shares many implementation details. DHCP allows hosts to obtain necessary TCP/IP configuration information from a DHCP server.

Benefits of DHCP

  • Reliable IP address configuration. DHCP minimizes configuration errors caused by manual IP address configuration, such as typographical errors, or address conflicts caused by the assignment of an IP address to more than one computer at the same time.
  • Reduced network administration. DHCP includes the following features to reduce network administration:

    • Centralized and automated TCP/IP configuration.
    • The ability to define TCP/IP configurations from a central location.
    • The ability to assign a full range of additional TCP/IP configuration values by means of DHCP options.
    • The efficient handling of IP address changes for clients that must be updated frequently, such as those for portable computers that move to different locations on a wireless network.
    • The forwarding of initial DHCP messages by using a DHCP relay agent, thus eliminating the need to have a DHCP server on every subnet.

How DHCP Works

DHCP provides an automated way to distribute and update IP addresses and other configuration information on a network. A DHCP server provides this information to a DHCP client through the exchange of a series of messages, known as the DHCP conversation or the DHCP transaction. It is also known as "DORA-Process". If the DHCP server and DHCP clients are located on different subnets, a DHCP relay agent is used to facilitate the conversation.

 

1. DHCP-Discover:- 
Broadcast by a DHCP client when it firest attempts to connect to the network. The DHCPDiscover      message requests IP address information from a DHCP server.

2. DHCP-Offer:-
Broadcast by each DHCP server that receives the client DHCPDiscover message and has an IP address configuration to offer to the client. The DHCPOffer message contains an unleased IP address and additional TCP/IP configuration information, such as the subnet mask and default gateway. More than one DHCP server can respond with a DHCPOffer message. The client accepts the best offer, which for a Windows DHCP client is the first DHCPOffer message that it receives.

3. DHCP-Request:-
Broadcast by a DHCP client after it selects a DHCPOffer. The DHCPRequest message contains the IP address from the DHCPOffer that it selected. If the client is renewing or rebinding to a previous lease, this packet might be unicast directly to the server.

 4. DHCP-ACK:-
Broadcast by a DHCP server to a DHCP client acknowledging the DHCPRequest message. At this time, the server also forwards any options. Upon receipt of the DHCPAck, the client can use the leased IP address to participate in the TCP/IP network and complete its system startup. This message is typically broadcast, because the DHCP client does not officially have an IP address that it can use at this point. If the DHCPAck is in response to a DHCPInform, then the message is unicast directly to the host that sent the DHCPInform message.

Step by step configuration of DHCP Server :-



Video :-




Step 1: First of all configure your NIC with above lab structure.

             To check the current configuration of NIC , execute the following command.
              
            # ifconfig


to configure NIC, execute the following command-

#setup




Now restart the "network" service.

# service network restart 


Now check the NIC the configuration


Step 2 :- In the next step install the "DHCP" packages.
               There are two ways to install packages.
                 1.RPM(Redhat Package Manager).
                 2.YUM Server.

              If you haven't configured YUM Server in your network, then you have to install DHCP packages
              manually with the help of rpm command.
              To install DHCP packages through rpm command, first of all insert your RHEL 5 installation media
              (DVD) in your PC and then mount it in your PC.

          to mount the installation media, open the terminal and then  execute the following command :

              # mount /dev/cdrom /mnt


               To check the mount point, execute the following command 

               #df -h


following packages you have to install to configure DHCP Server :-

dhcp-3.0.5-7.el5.i386.rpm
dhcp-devel-3.0.5-7.el5.i386.rpm
dhcpv6-0.10-33.el5.i386.rpm (for ipv6 support )
dhcpv6_client-0.10-33.el5.i386.rpm ( for ipv6 support)

if you are working in IPv4 network environment, you don't need to install the following packages:-

dhcpv6-0.10-33.el5.i386.rpm (for ipv6 support )
dhcpv6_client-0.10-33.el5.i386.rpm ( for ipv6 support)

To check DHCP Packages install or not in your PC, use the following command.

#rpm -qa <package-name>



Now go to /mnt/Server directory.This directory contains all the packages of RHEL 5.

#cd /mnt/Server


use following command to install package with rpm command :-

#rpm -ivh <package-name>


You can also install these packages with the help of YUM-Server.

 to install these packages using YUM-Server, execute the following command.

#yum  install <package-name>




Now execute the following command to check that the dhcp packages are installed properly or not :-

#rpm -qa <package-name>


Step 3 :- Now copy the main configuration file of DHCP Server from  /usr/share/doc/dhcp-3.0.5/  to /etc/

By default the main configuration file (dhcpd.conf) is located in /usr/share/doc/dhcp-3.0.5/ directory.

to copy the sample file from /usr/share/doc/dhcp-3.0.5/ to /etc/ :-

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


Step 4 :- Now edit the /etc/dhcpd.conf file.

to edit the /etc/dhcpd.conf file, use the following command,

#vim  /etc/dhcpd.conf  



the file will look like as below :-


Add the following lines to the main configuration file or edit the default scope  :-

subnet 172.18.9.0 netmask 255.255.255.0 {
                      option routers 172.18.9.9;
                      option subnet-mask 255.255.255.0;
                      option nis-domain  "sgecollege.com";
                      option domain-name "sgecollege.com";
                      option domain-name-servers 172.18.9.1;
   range dynamic-bootp  172.18.9.20  172.18.9.50; 
   default-lease-time 21600;
   max-lease-time 43200;
}

after adding these lines or edit the default scope, save the file and exit  from it.
to save and exit from the file press "ESC + : + w + q + ! + Enter key".


in my practical i did not create new scope, i have edited the default scope.

 
Step 5 :- In the next step, start the "dhcpd" daemon.

to start the "dhcpd" daemon, execute the following command.

#service  dhcpd  restart

to restart "dhcpd" daemon, execute the following command.

#service  dhcpd  restart

to start "dhcpd" daemon on boot time, execute the following command.

#chkconfig  dhcpd  on

to check the "dhcpd" daemon status, execute the following command.

#service  dhcpd  status


Client Side configuration  :-

Linux :-

to obtain ip from DHCP Server, edit the particular NIC configuration file likewise on client PC.The NIC Configuration file is located in the "/etc/sysconfig/network-scripts/" directory.

edit the file with vim editor and set BOOTPROTO type DHCP:-

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

Note:- In the above command "eth0" is your NIC number, which you wanna configure,it may be different in your PC.

file configuration is :-

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
HWADDR=08:00:27:34:c9:34

then save the file and exit from it.

to save and exit from the file press "ESC + : + w + q + ! + Enter key".




Now restart the "Network" daemon.

execute the following command to restart the "Network" daemon.

#service  network  restart

and then check NIC configuration by executing the following command.

#ifconfig  eth0 


Now generate the lease database in the DHCP Server :-

execute the following command :-

#touch /var/lib/dhcpd/dhcpd.leases 

to check the lease database,execute the following command.

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



Windows :-

to obtain ip from DHCP Server in Windows Operating System do the following :-

Open the run menu -------->type "ncpa.cpl" -------->and then click on "OK".

the "Network Connections" wizard will appear.

Then go to NIC properties -------->Select "Internet Protocol (TCP/IP)" -------> Properties ------->
Select "Obtain an IP address automatically" ------->OK----->OK.







To check IP configuration graphically in Windows OS :-

Open the "Network Connections" wizard ----> and then Right click on "NIC"  ---------> Click on "Status" ------> Click on "Support"

To check IP configuration from command line :-

Use the following commad

ipconfig  

ipconfig /all










Static IP Address Using DHCP

to provide Static IP using DHCP, add the following line to "/etc/dhcpd.conf" in file particular Subnet Scope.

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

host xp {
                            option host-name "xp.sgecollege.com";
                            hardware ethernet 08:00:27:6A:7C:9F;
                            fixed-address 172.18.9.22;
}






1 comment: