Dynamic Host Configuration Protocol (DHCP)

The Dynamic Host Configuration Protocol (DHCP) is a network service that enables host computers to be automatically assigned settings from a fun88体育 as opposed to manually configuring each network host. Computers configured to be DHCP clients have no control over the settings they receive from the DHCP fun88体育, and the configuration is transparent to the computer’s user.

The most common settings provided by a DHCP fun88体育 to DHCP clients include:

  • IP address and netmask

  • IP address of the default-gateway to use

  • IP adresses of the DNS fun88体育s to use

However, a DHCP fun88体育 can also supply configuration properties such as:

  • Host Name

  • Domain Name

  • Time fun88体育

  • Print fun88体育

The advantage of using DHCP is that changes to the network, for example a change in the address of the DNS fun88体育, need only be changed at the DHCP fun88体育, and all network hosts will be reconfigured the next time their DHCP clients poll the DHCP fun88体育. As an added advantage, it is also easier to integrate new computers into the network, as there is no need to check for the availability of an IP address. Conflicts in IP address allocation are also reduced.

A DHCP fun88体育 can provide configuration settings using the following methods:

  • Manual allocation (MAC address)
    This method entails using DHCP to identify the unique hardware address of each network card connected to the network and then continually supplying a constant configuration each time the DHCP client makes a request to the DHCP fun88体育 using that network device. This ensures that a particular address is assigned automatically to that network card, based on it’s MAC address.

  • Dynamic allocation (address pool)
    In this method, the DHCP fun88体育 will assign an IP address from a pool of addresses (sometimes also called a range or scope) for a period of time or lease, that is configured on the fun88体育 or until the client informs the fun88体育 that it doesn’t need the address anymore. This way, the clients will be receiving their configuration properties dynamically and on a “first come, first served” basis. When a DHCP client is no longer on the network for a specified period, the configuration is expired and released back to the address pool for use by other DHCP Clients. This way, an address can be leased or used for a period of time. After this period, the client has to renegociate the lease with the fun88体育 to maintain use of the address.

  • Automatic allocation
    Using this method, the DHCP automatically assigns an IP address permanently to a device, selecting it from a pool of available addresses. Usually DHCP is used to assign a temporary address to a client, but a DHCP fun88体育 can allow an infinite lease time.

The last two methods can be considered “automatic” because in each case the DHCP fun88体育 assigns an address with no extra intervention needed. The only difference between them is in how long the IP address is leased, in other words whether a client’s address varies over time. The DHCP fun88体育 Ubuntu makes available is dhcpd (dynamic host configuration protocol daemon), which is easy to install and configure and will be automatically started at system boot.

Installation

At a terminal prompt, enter the following command to install dhcpd:

sudo apt install isc-dhcp-fun88体育

NOTE: dhcpd’s messages are being sent to syslog. Look there for diagnostics messages.

Configuration

You will probably need to change the default configuration by editing /etc/dhcp/dhcpd.conf to suit your needs and particular configuration.

Most commonly, what you want to do is assign an IP address randomly. This can be done with settings as follows:

# minimal sample /etc/dhcp/dhcpd.conf
default-lease-time 600;
max-lease-time 7200;

subnet 192.168.1.0 netmask 255.255.255.0 {
 range 192.168.1.150 192.168.1.200;
 option routers 192.168.1.254;
 option domain-name-fun88体育s 192.168.1.1, 192.168.1.2;
 option domain-name "mydomain.example";
}

This will result in the DHCP fun88体育 giving clients an IP address from the range 192.168.1.150-192.168.1.200. It will lease an IP address for 600 seconds if the client doesn’t ask for a specific time frame. Otherwise the maximum (allowed) lease will be 7200 seconds. The fun88体育 will also “advise” the client to use 192.168.1.254 as the default-gateway and 192.168.1.1 and 192.168.1.2 as its DNS fun88体育s.

You also may need to edit /etc/default/isc-dhcp-fun88体育 to specify the interfaces dhcpd should listen to.

INTERFACESv4="eth4"

After changing the config files you have to restart the dhcpd service:

sudo systemctl restart isc-dhcp-fun88体育.service

References

Last updated 1 year, 3 months ago. Help improve this document in the forum.