Wednesday, November 16, 2011

DHCP


What is DHCP

Dynamic Host Configuration Protocol (DHCP) is a network protocol that enables a DHCP server to automatically assign an IP address to an individual computer's TCP/IP stack software. DHCP assigns a number dynamically from a defined range of numbers (i.e., a scope) configured for a given network.
Client computers configured to use DHCP for IP assignment do not need to have a statically assigned IP address. In addition, they generally do not need to have addresses configured for DNS servers or WINS servers, as these are also set by the DHCP server.
DHCP assigns a TCP/IP address when a system is started. Typically, it works like this:
  1. A user turns on a computer with a DHCP client.
  2. The client computer sends a broadcast request (called a DISCOVER or DHCPDISCOVER), looking for a DHCP server to answer.
  3. The router directs the DISCOVER packet to the correct DHCP server.
  4. 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 (or DHCPOFFER) packet, with that address information. The server also configures the client's DNS servers, WINS servers, NTP servers, and sometimes other services as well.
  5. The client sends a REQUEST (or DHCPREQUEST) packet, letting the server know that it intends to use the address.
  6. The server sends an ACK (or DHCPACK) packet, confirming that the client has a been given a lease on the address for a server-specified period of time.

Why use DHCP



Every device on a TCP/IP-based network must have a unique unicast IP address to access the network and its resources. Without DHCP, IP addresses must be configured manually for new computers or computers that are moved from one subnet to another, and manually reclaimed for computers that are removed from the network.
DHCP enables this entire process to be automated and managed centrally. The DHCP server maintains a pool of IP addresses and leases an address to any DHCP-enabled client when it starts up on the network. Because the IP addresses are dynamic (leased) rather than static (permanently assigned), addresses no longer in use are automatically returned to the pool for reallocation.
The network administrator establishes DHCP servers that maintain TCP/IP configuration information and provide address configuration to DHCP-enabled clients in the form of a lease offer. The DHCP server stores the configuration information in a database, which includes:
-          Valid TCP/IP configuration parameters for all clients on the network.
-          Valid IP addresses, maintained in a pool for assignment to clients, as well as excluded addresses.
-          Reserved IP addresses associated with particular DHCP clients. This allows consistent assignment of a single IP address to a single DHCP client.
-          The lease duration, or the length of time for which the IP address can be used before a lease renewal is required.

A DHCP-enabled client, upon accepting a lease offer, receives:

-          A valid IP address for the subnet to which it is connecting.
-          Requested DHCP options, which are additional parameters that a DHCP server is configured to assign to clients. Some examples of DHCP options are Router (default gateway), DNS Servers, and DNS Domain Name. For a full list of DHCP options, see “DHCP Tools and Settings .


Packages:

Server – dhcpd
Client - dhcpcd or pump

Ports:

Server - UDP 67 (bootps)
Client - UDP 68 (bootpc)


Configuration files:

- /etc/dhcpd.conf

allow bootp;
allow booting;

ddns-update-style interim;
ignore client-updates;

subnet 192.168.0.0 netmask 255.255.255.0 {

# --- default gateway
      option routers                192.168.0.253;
      option subnet-mask            255.255.255.0;

      option nis-domain       "opensource.com";
      option domain-name            "opensource.com";
      option domain-name-servers    192.168.0.253;

      option time-offset            -18000;     # Eastern Standard Time
#     option ntp-servers            192.168.1.1;
      option netbios-name-servers   192.168.0.253;
# --- Selects point-to-point node (default is hybrid). Don't change this unless
# -- you understand Netbios very well
#     option netbios-node-type 2;

      range dynamic-bootp 192.168.0.1 192.168.0.254;
      default-lease-time 3600;
      max-lease-time 4800;

      # we want the nameserver to appear at a fixed address
      host ns  {
            next-server server.opensource.com;
            hardware ethernet 00:1E:90:79:6A:31;
            fixed-address 192.168.0.253;
      }

      host station1.opensource.com {
            hardware ethernet 00:1E:90:7A:86:3C;
            fixed-address 192.168.0.1;
            option host-name "station1.opensource.com";
            filename "pxelinux.0";
      }

      host station2.opensource.com {
            hardware ethernet 00:1E:90:7A:81:B4;
            fixed-address 192.168.0.2;
             option host-name "station2.opensource.com";
            filename "pxelinux.0";
      }
      host station6.opensource.com {
            hardware ethernet 00:1E:90:79:66:DE;
      fixed-address 192.168.0.6;
            option host-name "station6.opensource.com";
            filename "pxelinux.0";
      }
      host station4.opensource.com {
            hardware ethernet 00:1E:90:77:5B:3D;
            fixed-address 192.168.0.4;
      }
}






When DHCP starts, it reads the file /etc/dhcpd.conf. It uses the commands here to configure your network. The standard DHCP RPM package doesn't automatically install a /etc/dhcpd.conf file, but you can find a sample copy of dhcpd.conf in the following directory which you can always use as a guide.

 
/usr/share/doc/dhcp-<version-number>/dhcpd.conf.sample
 
You have to copy the sample dhcpd.conf file to the /etc directory and then you'll have to edit it.

Cp /usr/share/doc/dhcp-3.0pl1/dhcpd.conf.sample /etc/dhcpd.conf    

Stores information about leased IP addresses. It must exist in order for dhcp to start! If it
doesn't exist, type
 
touch /var/lib/dhcp/dhcpd.leases

No comments:

Post a Comment