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...            



_____________________________________________________________________________________________
Click Back..                                Click Home..


https://docs.google.com/forms/d/1iNRZlJJO6rBFizzPcFmyOTEtfkdjhdVRmpM74IbiT3o/viewform

 

  Interview questions on DHCP



Q: - What is DHCP?

DHCP stands for "Dynamic Host Configuration Protocol".

 
Q: - How can I prevent unauthorized laptops from using a network that uses DHCP for dynamic addressing?
This would have to be done using a mechanism other than DHCP. DHCP does not prevent other clients from using the addresses it is set to hand out nor can it distinguish between a computer's permanent MAC address and one set by the computer's user. DHCP can impose no restrictions on what IP address can use a particular port nor control the IP address used by any client.


Q: - Can a BOOTP client boot from a DHCP server?
Only if the DHCP server is specifically written to also handle BOOTP queries.
Q: - What is DHCP's purpose?
DHCP's purpose is to enable individual computers on an IP network to extract their configurations from a server (the 'DHCP server') or servers, in particular, servers that have no exact information about the individual computers until they request the information. The overall purpose of this is to reduce the work necessary to administer a large IP network. The most significant piece of information distributed in this manner is the IP address.

Q: - How can I prevent unauthorized laptops from using a network that uses DHCP for dynamic addressing?
This would have to be done using a mechanism other than DHCP. DHCP does not prevent other clients from using the addresses it is set to hand out nor can it distinguish between a computer's permanent MAC address and one set by the computer's user. DHCP can impose no restrictions on what IP address can use a particular port nor control the IP address used by any client.


Q: - Can a BOOTP client boot from a DHCP server?
Only if the DHCP server is specifically written to also handle BOOTP queries.


Q: - Can DHCP work with Apple Talk or IPX?

No, it is too tied to IP. Furthermore, they don't need it since they have always had automated mechanisms for assigning their own network addresses.



Q: - What is a DHCP lease?
A DHCP lease is the amount of time that the DHCP server grants to the DHCP client permission to use a particular IP address. A typical server allows its administrator to set the lease time.


Q: - What is DHCP Spoofing?
Ascend Pipeline ISDN routers (which attach Ethernets to ISDN lines) incorporate a feature that Ascend calls "DHCP spoofing" which is essentially a tiny server implementation that hands an IP address to a connecting Windows 95 computer, with the intention of giving it an IP number during its connection process.


Q: - How long should a lease be?
A very relevant factor is that the client starts trying to renew the lease when it is halfway through: thus, for example, with a 4 day lease, the client which has lost access to its DHCP server has 2 days from when it first tries to renew the lease until the lease expires and the client must stop using the network. During a 2- day outage, new users cannot get new leases, but no lease will expire for any computer turned on at the time that the outage commences. Another factor is that the longer the lease the longer time it takes for client configuration changes controlled by DHCP to propogate.

Q: - Is a DHCP client "supposed to" be able to use a BOOTP server?
The RFC on such interoperability (1534) is clear: "A DHCP client MAY use a reply from a BOOTP server if the configuration returned from the BOOTP server is acceptable to the DHCP client." (section 3). The word "MAY" indicates such support, however useful, is left as an option.


Q: - What is a Client ID?
What is termed the Client ID for the purposes of the DHCP protocol is whatever is used by the protocol to identify the client computer. By default, DHCP implementations typically employ the client's MAC address for this purpose, but the DHCP protocol allows other options. Some DHCP implementations have a setup option to specify the client ID you want. One alternative to the MAC address is simply a character string of your choice. In any case, in order for DHCP to function, you must be certain that no other client is using the client ID you choose, and you must be sure the DHCP server will accept it.


Q: - How can I relay DHCP if my router does not support it?
A server on a net(subnet) can relay DHCP or BOOTP for that net. Microsoft has software to make Windows NT do this.


Q: - Is a DHCP server "supposed to" be able to support a BOOTP client?
The RFC on such interoperability (1534) is clear: "In summary, a DHCP server:
... MAY support BOOTP clients," (section 2). The word "MAY" indicates such support, however useful, is left as an option.
A source of confusion on this point is the following statement in section 1.5 of RFC 1541: "DHCP must provide service to existing BOOTP clients." However, this statement is one in a list of "general design goals for DHCP", i.e. what the
designers of the DHCP protocol set as their own goals. It is not in a list of requirements for DHCP servers.


Q: - Can DHCP support statically defined addresses??

Yes. At least there is nothing in the protocol to preclude this and one expects it to be a feature of any DHCP server. This is really a server matter and the client should work either way. The RFC refers to this as manual allocation.


Q: - What is a MAC address?
A MAC address (also called an Ethernet address or an IEEE MAC address) is a number (typically written as twelve hexadecimal digits, 0 through 9 and A through F, or as six hexadecimal numbers separated by periods or colons, i.e. 0080002012ef, 0:80:0:2:20:ef) which uniquely identifes a computer that has an Ethernet interface. Unlike the IP number, it includes no indication of where your computer is located. In DHCP's typical use, the server uses a requesting computer's MAC address to uniquely identify it.


Q: - Can a DHCP server back up another DHCP server?
You can have two or more servers handing out leases for different addresses. If each has a dynamic pool accessible to the same clients, then even if one server is down, one of those clients can lease an address from the other server. However, without communication between the two servers to share their information on current leases, when one server is down, any client with a lease from it will not be able to renew their lease with the other server. Such communication is the purpose of the "server to server protocol" (see next question). It is possible that some server vendors have addressed this issue with their own proprietary server-to-server communication.


Q: - When will the server to server protocol be defined?
The DHC WG of the IETF is actively investigating the issues in inter-server communication. The protocol should be defined "soon".


Q: - How does DHCP and BOOTP handle multiple subnets?
For the situations where there is more than one LAN, each with its own subnet number, there are two ways. First of all, you can set up a seperate server on each subnet. Secondly, a feature of some routers known as "BOOTP forwarding"
to forward DHCP or BOOTP requests to a server on another subnet and to forward the replies back to the client. The part of such a router (or server acting as a router) that does this is called a "BOOTP forwarding agent". Typically you
have to enable it on the interface to the subnet to be served and have to configure it with the IP address of the DHCP or BOOTP server. On a Cisco router, the address is known as the "UDP Helper Address".


Q: - Can a DHCP client boot from a BOOTP server?
Only if the DHCP client were specifically written to make use of the answer from a BOOTP server. It would presumably treat a BOOTP reply as an unending lease on the IP address.
In particular, the TCP/IP stack included with Windows 95 does not have this capability.


Q: - What protocol and port does DHCP use?
DHCP, like BOOTP runs over UDP, utilizing ports 67 and 68.


Q: - What is DHCP's purpose?
DHCP's purpose is to enable individual computers on an IP network to extract their configurations from a server (the 'DHCP server') or servers, in particular, servers that have no exact information about the individual computers until they request the information. The overall purpose of this is to reduce the work necessary to administer a large IP network. The most significant piece of information distributed in this manner is the IP address.


Q: - What is an IP address?

An IP address (also called an IP number) is a number (typically written as four numbers separated by periods, i.e. 107.4.1.3 or 84.2.1.111) which uniquely identifies a computer that is making use of the Internet. It is analogous to your
telephone number in that the telephone number is used by the telephone network to direct calls to you. The IP address is used by the Internet to direct data to your computer, e.g. the data your web browser retrieves and displays
when you surf the net. One task of DHCP is to assist in the problem of getting a functional and unique IP number into the hands of the computers that make use of the Internet.

Q: - How can I relay DHCP if my router does not support it?
A server on a net(subnet) can relay DHCP or BOOTP for that net. Microsoft has software to make Windows NT do this.


Q: - Can DHCP work with AppleTalk or IPX?
No, it is too tied to IP. Furthermore, they don't need it since they have always had automated mechanisms for assigning their own network addresses.


Q: - Who Created DHCP?
DHCP was created by the Dynamic Host Configuration Working Group of the Internet Engineering Task Force (IETF; a volunteer organization which defines protocols for use on the Internet). As such, it's definition is recorded in an Internet RFC and the Internet Activities Board (IAB) is asserting its status as to Internet Standardization. As of this writing (June 1998), DHCP is an Internet Draft Standard Protocol and is Elective. BOOTP is an Internet Draft Standard Protocol and is recommended. For more information on Internet standardization, see RFC2300 (May 1998)


Q: - What is a Client ID?
What is termed the Client ID for the purposes of the DHCP protocol is whatever is used by the protocol to identify the client computer. By default, DHCP implementations typically employ the client's MAC address for this purpose, but the DHCP protocol allows other options. Some DHCP implementations have a setup option to specify the client ID you want. One alternative to the MAC address is simply a character string of your choice. In any case, in order for DHCP to function, you must be certain that no other client is using the client ID you choose, and you must be sure the DHCP server will accept it.


Q: - Can DHCP support statically defined addresses?
Yes. At least there is nothing in the protocol to preclude this and one expects it to be a feature of any DHCP server. This is really a server matter and the client should work either way. The RFC refers to this as manual allocation.


Q: - How is it different than BOOTP or RARP?
DHCP is based on BOOTP and maintains some backward compatibility. The main difference is that BOOTP was designed for manual pre-configuration of the host information in a server database, while DHCP allows for dynamic allocation of
network addresses and configurations to newly attached hosts. Additionally, DHCP allows for recovery and reallocation of network addresses through a leasing mechanism.
RARP is a protocol used by Sun and other vendors that allows a computer to find out its own IP number, which is one of the protocol parameters typically passed to the client system by DHCP or BOOTP. RARP doesn't support other parameters and using it, a server can only serve a single LAN. DHCP and BOOTP are designed so they can be routed.

Q: - How is it different than BOOTP or RARP?
DHCP is based on BOOTP and maintains some backward compatibility. The main difference is that BOOTP was designed for manual pre-configuration of the host information in a server database, while DHCP allows for dynamic allocation of network addresses and configurations to newly attached hosts. Additionally, DHCP allows for recovery and reallocation of network addresses through a leasing mechanism.
RARP is a protocol used by Sun and other vendors that allows a computer to find out its own IP number, which is one of the protocol parameters typically passed to the client system by DHCP or BOOTP. RARP doesn't support other parameters and using it, a server can only serve a single LAN. DHCP and BOOTP are designed so they can be routed.


Q: - How does DHCP and BOOTP handle multiple subnets?

For the situations where there is more than one LAN, each with its own subnet number, there are two ways. First of all, you can set up a seperate server on each subnet. Secondly, a feature of some routers known as "BOOTP forwarding" to forward DHCP or BOOTP requests to a server on another subnet and to forward the replies back to the client. The part of such a router (or server acting as a router) that does this is called a "BOOTP forwarding agent". Typically you have to enable it on the interface to the subnet to be served and have to configure it with the IP address of the DHCP or BOOTP server. On a Cisco router, the address is known as the "UDP Helper Address".

Q: - In a DHCP environment, which of the components (Client or Server) initiates the request
The client would always initiate the DHCP request. The request is triggerred from the client , when the TCP/IP adapter is configured for the option “Obtain IP address automatically”. When this is selected, the operating system would automatically generate the DHCP Discover to identify valid DHCP Servers on the network.
Q: - How many DHCP packets are exchanged between a client and a server before the client receives an IP address
4 DHCP packets are exchanged between the client and the server. They are DHCP Discover, DHCP Offer, DHCP Request, DHCP Ack.
Q: - What type of packet is a DHCP Discover packet
DHCP Discover is a layer 3 broadcast packet with destination IP address as 255.255.255.255
Q: - What is an IP Helper address feature and why is it required in a DHCP environment
DHCP Discover packets are broadcast packets. This means that a DHCP Discover packet which is sent from the client would not reach the DHCP Server , if the server resides on a different network. This is because , routers are required for communication between different networks and routers do not forward broadcast packets. The IP Helper address feature is configured on the router. The feature informs the router the DHCP Servers IP address for the network. So, When the router receives the DHCP Discover packet, it would convert it from broadcast to unicast packet and then send it to the DHCP Server.

Q: - What is a DHCP Scope and why is it required
A scope includes information like IP address ranges, Subnet Masks, gateway address, DNS Server etc. This required so that clients would require the necessary information from the server.
Q: - What would happen if there are multiple DHCP servers on a network
The clients would trigger DHCP Discover packets and the server which responds first would provide the IP address to the client
Q: - How does a client know that a lease has expired and how is it renewed
When a client receives an IP address from the DHCP Server, the lease expiry date and time is provided as part of DHCP options. This is maintained and recorded by the client. Just before the lease expiry time, the client would initiate a renew request to the server for a new lease
Q: - How many DHCP Servers can reside on one subnet
It’s unlimited. But if there is a DHCP client, which server would lease out the IP address ? It’s a simple logic. The first server which responds to the DHCP clients IP address request would lease out the IP address.
Q: - Explain the communication flow between a DHCP client and server on a network with two DHCP Servers
The first packet the DHCP Client initiates would be the DHCP Discover packet. The DHCP Discover packet is broadcast in nature and would be received by both the DHCP servers. The DHCP servers would respond with DHCP offer packet containing the IP addresses which they offer. Based on the first DHCP offer the client receives, the client would respond with DHCP request packet which contains the IP address which it would be using along with the DHCP servers IP address which had provide the respective. This packet is send as broadcast. The packet, when received by the other DHCP server would understand that the IP address which it had leased to the client (In the DHCP offer packet) is not taken. So the DHCP server would put the IP address back to it’s pool.


_____________________________________________________________________________________________
Click Back..                                Click Home..


https://docs.google.com/forms/d/1iNRZlJJO6rBFizzPcFmyOTEtfkdjhdVRmpM74IbiT3o/viewform