Dynamic Host Configuration Protocol (DHCP) is a network protocol used to automatically allocate TCP/IP information to the client machine. Each DHCP Client is connected to the DHCP server in the central position. The server returns the network configuration of the client that includes the IP address, gateway, and DNS server information.
18.1. Why DHCP?
DHCP is useful in fast sending customer network configurations. When configuring the customer system, the administrator can select DHCP without entering the IP address, subnet mask, gateway, or DNS server. The customer retrieves the information from the DHCP server. DHCP is also useful when administrators want to change a large number of system IP addresses. Instead of resetting all systems, the Administrator only needs to edit a DHCP configuration file on the server to obtain the new IP address set. If the DNS server of an organization changes, this change only needs to be performed on the DHCP server rather than on the DHCP client. Once the customer's network is restarted or the customer re-directs the system), the change will take effect.
In addition, if DHCP is configured for a portable computer or any type of removable computer, as long as each office has a DHCP server that allows it to connect to the Internet, it can be freely moved between offices without reconfiguration.
18.2. Configure the DHCP server
You can use the/etc/dhcpd. conf configuration file to configure the DHCP server.
DHCP also uses the/var/lib/dhcp/dhcpd. leases file to store the customer's lease period database. For more information, see section 18.2.2.
18.2.1. Configuration File
The first step in configuring the DHCP server is to create a configuration file for storing the customer's network information. Global options can be declared for all customers, and optional options can be declared for each customer system.
This configuration file can be simply formatted using any additional tab or blank lines. The keyword is case sensitive. The line that is first set to # Is a comment.
At present, two DNS update schemes are implemented-Special DNS update mode and transitional DHCP-DNS interactive sketch update mode. If the two models are accepted as part of the IETF standard process, the third mode-standard DNS update method appears. The DHCP server must be configured to use one of the two current schemes. Version 3.0b2pl11 and earlier use special mode; however, this mode is outdated. If you want to retain the same behavior, add the following line at the beginning of the configuration file:
Ddns-update-style ad-hoc;
To use the recommended mode, add the following line at the beginning of the configuration file:
Ddns-update-style interim;
Please read the manual man page of dhcpd. conf to obtain details about different modes.
There are two types of statements in the configuration file:
Parameter-indicates how to execute the task, whether to execute the task, or what network configuration options are sent to the customer.
Declaration-Describe the layout of the network; Describe the customer; provide the customer's address; or apply a set of parameters to a set of declarations.
Some parameters must begin with the option keyword, which is also called an option. The optional option for configuring DHCP. The parameter configuration is required or the value that controls DHCP server behavior.
Parameters declared before using braces {}) include options) are generally treated as global parameters. All parts of the global parameter application.
Important: If you change the configuration file, these changes will take effect only after you restart the DHCP daemon by using the service dhcpd restart command.
In Example 18-1, the routers, subnet-mask, domain-name, domain-name-servers, and time-offset options are used in all host declarations declared under them.
As shown in example 18-1, you can declare subnet. You must include a subnet Declaration for each subnet in your network. Otherwise, the DHCP server may fail to start.
In this example, each DHCP client in the subnet has a global option and declares a range. The IP address that the customer is allocated to within the range.
Subnet 192.168.1.0 netmask 255.255.255.0 {
Option routers 192.168.1.254;
Option subnet-mask limit 255.0;
Option domain-name "example.com ";
Option domain-name-servers 192.168.1.1;
Option time-offset-18000; # Eastern Standard Time
Range 192.168.1.10 192.168.1.100;
}
Example 18-1. subnet Declaration
All subnets that share the same physical network should be declared in the shared-network Statement, as shown in example 18-2. In shared-network mode, parameters other than subnet declarations that are surrounded are treated as global parameters. The shared-network name should be a descriptive title for the network, for example, using test-lab to describe all subnets in the lab test lab environment.
Shared-network name {
Option domain-name "test.redhat.com ";
Option domain-name-servers ns1.redhat.com, ns2.redhat.com;
Option routers 192.168.1.254;
More parameters for EXAMPLE shared-network
Subnet 192.168.1.0 netmask 255.255.255.0 {
Parameters for subnet
Range 192.168.1.1 192.168.1.31;
}
Subnet 192.168.1.32 netmask 255.255.255.0 {
Parameters for subnet
Range 192.168.1.33 192.168.1.63;
}
}
Example 18-2. Shared Network Statement
As demonstrated in example 18-3, the group declaration can be used to apply global parameters to a group of declarations. You can combine shared networks, subnets, hosts, and other groups.
Group {
Option routers 192.168.1.254;
Option subnet-mask limit 255.0;
Option domain-name "example.com ";
Option domain-name-servers 192.168.1.1;
Option time-offset-18000; # Eastern Standard Time
Host apex {
Option host-name "apex.example.com ";
Hardware ethernet 00: A0: 78: 8E: 9E: AA;
Fixed-address 192.168.1.4;
}
Host raleigh {
Option host-name "raleigh.example.com ";
Hardware ethernet 00: A1: DD: 74: C3: F2;
Fixed-address 192.168.1.6;
}
}
Example 18-3. Group Declaration
You need to configure to lease the dynamic IP address to the DHCP server of the system in the subnet, and use your value to modify example 18-4. It declares a default lease period, the longest lease period, and the network configuration value for the customer. In this example, the IP addresses between range 192.168.1.10 and 192.168.1.100 are allocated to the customer.
Default-lease-time 600;
Max-lease-time 7200;
Option subnet-mask limit 255.0;
Option broadcast-address 192.168.1.255;
Option routers 192.168.1.254;
Option domain-name-servers 192.168.1.1, 192.168.1.2;
Option domain-name "example.com ";
Subnet 192.168.1.0 netmask 255.255.255.0 {
Range 192.168.1.10 192.168.1.100;
}
Example 18-4. range parameter
Assign an IP address to the customer based on the MAC address of the network adapter and use the hardware ethernet parameter in the host declaration. As demonstrated in example 18-5, the host apex statement indicates that the MAC address of the NIC is 00: A0: 78: 8E: 9E: the IP address assigned by the AA system will always be 192.168.1.4.
Note that you can also use the optional host-name parameter to assign a host name to the customer.
Host apex {
Option host-name "apex.example.com ";
Hardware ethernet 00: A0: 78: 8E: 9E: AA;
Fixed-address 192.168.1.4;
}
Example 18-5. Use static IP address of DHCP
Tip: You can use the configuration file example of Red Hat Linux 9 as a sample, and then add your custom configuration options on it. Run the following command to copy it to the correct location:
Related Articles]
- TCP/IP basic DHCP protocol
- How does the DHCP protocol work?
- Comparison between mobile IP and DHCP and VPN technologies