Dynamic Host Configuration Protocol (DHCP) - Linux

OS: 
Function: 
Summary
  • The Dynamic Host Configuration Protocol (DHCP) can be used to dynamically set and change configuration parameters of Internet hosts, including IP address, netmask, default router, and DNS server. DHCP is based on a client-server model. DHCP clients send requests to a DHCP server and the server responds with an allocation of IP addresses and other configuration parameters.
Example
  • On a Linux system, a DHCP server is started with the command dhcpd. The DHCP server reads the configuration file /etc/dhcpd.conf. The configuration file contains information on available IP addresses, as well as other configuration information. The following is an example of a configuration file for a DHCP server: 

#dhcpd.conf file

ddns-update-style none;

default-lease-time 600;

subnet 10.0.1.0 netmask 255.255.255.0 {

range 10.0.1.10 10.0.1.100;

option routers 10.0.1.1;

default-lease-time 120;

}

subnet 10.0.2.0 netmask 255.255.255.0 {

range 10.0.2.101 10.0.2.200;

}

subnet 10.0.3.0 netmask 255.255.255.0 {

range 10.0.3.6 10.0.3.10;

}

 

The DHCP server listens for requests from DHCP clients on all its interfaces. In Linux, the DHCP server must be restarted each time the configuration file is modified. 

  • Starting the DHCP server:

PC2% dhcpd

  • Starting a DHCP client:
PC1% dhclient -d eth0