TCP/IP Protocol: Dynamic Host Control Protocol (DHCP)

Discussion in 'Linux Networking' started by Jarret W. Buse, Oct 28, 2013.

  1. Jarret W. Buse

    Jarret W. Buse Active Member Staff Writer

    Messages:
    104
    Likes Received:
    116
    Trophy Points:
    43
    TCP/IP Protocol: Dynamic Host Control Protocol (DHCP)

    There are three things we need to look at with the Dynamic Host Control Protocol (DHCP) in this article for you to understand how DHCP works.​
    1. DHCP Server​
    2. DHCP Client​
    3. The DHCP Protocol​
    The DHCP Server is the system on a network which manages and assigns IP Addresses to the DHCP Clients.


    Let’s take a Linux system and set up a DHCP Server. We perform the following steps:​
    1. Install dhcp3-server following any prompts required​
    2. When asked for the connection to install the DHCP Server on, select your appropriate network port (such as eth0).​
    3. Configure the DHCP Server​
    4. Edit the DHCP configuration as root (sudo gedit /etc/dhcp3/dhcpd.conf)​
    The code in the configuration file is as follows:

    Code:
    subnet 10.0.0.0 netmask 255.0.0.0 {
      range 10.0.0.100 10.0.0.200;
      option domain-name “linux.net”;
      option domain-name-servers  8.8.8.8, 8.8.4.4;
      option broadcast-address 10.255.255.255;
      option routers 10.1.1.1;
      option subnet-mask 255.0.0.0;
    }
    The first line: subnet 10.0.0.0 netmask 255.0.0.0 shows that the subnet is 10.0.0.0. Since the Host ID is 0.0.0, this represents a subnet and not an actual address. The netmask for the subnet is the default for a Class A address of 255.0.0.0.

    NOTE: For more information on netmasking, see Netmasking Transmission Control Protocol/Internet Protocol (TCP/IP).

    The second line of the configuration file: range 10.0.0.100 10.0.0.200 shows the available addresses to assign. These are the actual addresses that the DHCP Server will assign to the DHCP Clients. Be sure that the range of addresses is available and also part of the subnet listed in line 1. Do not attempt to assign addresses that are already statically used by any systems or devices.

    The third line lists the domain name: option domain-name “linux.net”. The Domain Name is used within the network to find other systems on the Local Area Network (LAN) just as they would be on the Internet. Let’s assume we have a system with a name of ‘backup’. On the network the system would be accessed as ‘backup.linux.net’.

    The fourth line sets the DNS Servers which will be auto-assigned to the DHCP Clients: option domain-name-servers 8.8.8.8, 8.8.4.4. Be sure that the DNS server IP Addresses are valid and do not use a ‘friendly name’.

    The fifth line lists the broadcast address for the subnet: option broadcast-address 10.255.255.255. Here, the Network ID must be the same as the subnet (line 1) and the Host ID are all ones in binary.

    Line six lists the gateways or where the frames are sent if they are not destined for the local network. In the example listing: option routers 10.1.1.1 the gateway address is 10.1.1.1.

    The last line lists the subnet mask. In this example we use the default Class A netmask as shown: option subnet-mask 255.0.0.0. If we use CIDR, it would be different.

    Once any of these options are changed, they can be in effect after the service is restarted. In the above example 100 DHCP clients can be dynamically configured. If a gateway address should change it would be easier to change the value on the DHCP server than to have to go to 100 client systems and change the value manually.

    At this point, the DHCP server should be restarted or at least restart the DHCP Service.

    Now, we should cover the DHCP Client. The DHCP Clients are those clients which will be dynamically configured by the DHCP Client.

    The configuration is shown in Figure 1. ​

    TCPIP Protocol DHCP - Figure 1.JPG
    FIGURE 1​

    To enable the system for DHCP, the Method would be changed to ‘DHCP’. After this, the client would receive an IP Address and all settings from the DHCP Server.

    Once enabled for DHCP, the client can request an IP Address lease from the DHCP Server. There are four basic steps to obtain a lease:
    1. Request
    2. Offer
    3. Selection
    4. Acknowledgement
    The Request is made from the DHCP Client when it starts up and requires an IP Address. Since it has no address, it broadcasts a generic request to an address of 0.0.0.0 and a destination of 255.255.255.255. The name of the system is included in the information of the broadcast. If no response is received, the system will repeat the broadcast at specified intervals until a response is received. If no response is ever made, then the system will not be able to use TCP/IP.

    After the DHCP Server receives the Request, it can check its database to determine if there are any available addresses. If an address is available, the server makes an Offer. The frame contains the IP Address and other information that the DHCP Server is configured to set on the DHCP Client. Other information included is the DHCP Server’s IP Address and Netmask to allow the DHCP Client to contact the server again. Another item set in the Offer is the lease time. The DHCP Server will make a temporary reservation for the address offered so it is not offered simultaneously to another DHCP Client.

    NOTE: The lease time allows a server to reuse IP Addresses in case a system is off for too long, the range of addresses is not depleted. In actuality, most DHCP Clients start a renewal for the lease once half the lease time has expired. A problem can occur if a DHCP goes offline and all clients need time to renew the lease.

    The first offer that a DHCP Client receives from a DHCP Server is accepted or selected. On a network with multiple DHCP Servers (mainly for redundancy with each server issuing a different range of addresses), the first is accepted and the rest are rejected. Another broadcast is made to select the offer from a specific DHCP Server.

    Finally, the DHCP Server receives the broadcast of the selected offer. If everything is correct at this point, the DHCP Server sends a DHCP Acknowledgment to the DHCP Client. The DHCP Client at this point is set to initialize TCP/IP with the information sent from the DHCP Server. If the DHCP Server has found something wrong, a DHCP negative Acknowledgement is sent to the DHCP Client and it restarts the DHCP Lease process all over.

    As you can probably tell, IP Addresses are extremely important to setting up TCP/IP. To prevent mistakes from occurring, such as a duplicate IP Address, it is best to use a DHCP Server.

    NOTE: If two systems have the same IP Address on the same network, the second system cannot initialize TCP/IP. For this reason, when multiple DHCP Servers are used, the Address Range cannot overlap.

    Attached Files:

    DevynCJohnson likes this.

Share This Page