In the process of host network parameter configuration, there are often scenarios where IP addresses conflict or mobile terminals need to obtain addresses and other network parameters temporarily. Using manual configuration of network parameters such as host IP address, default gateway IP address and DNS server IP address is both tedious and error-prone, and some places such as wireless network environment are not suitable for manual configuration. The dynamic host configuration protocol (DHCP) can solve such problems well and bring great convenience to network engineers for network management.
What is DHCP server?
DHCP is Dynamic Host Configuration Protocol, which means that the server controls a range of IP addresses, and clients can automatically obtain the IP address and subnet mask assigned by the server when they log on to the server. The computer acting as DHCP server needs to install TCP/IP protocol and set static IP address, subnet mask, default gateway and other contents for it. Its purpose is to relieve the burden of planning, management and maintenance of TCP/IP networks and to solve the problem of lack of IP address space. This network service facilitates effective management of client IP addresses in the network.
DHCP was formerly known as BOOTP, which was originally used for networks without disk hosts: instead of a network host using a BOOT ROM to boot and connect to the network, BOOTP automatically sets up the TCP/IP environment for those hosts. However, BOOTP has one drawback: you have to obtain the hardware address of the client before setting it up, and the correspondence with IP is static. In other words, BOOTP is very lacking in “dynamism” and its one-to-one correspondence can be very wasteful in a limited IP resource environment.
DHCP can be said to be an enhanced version of BOOTP, which is divided into two parts: one is the server side and the other is the client side. All IP network setting data is centrally managed by the DHCP server, which is responsible for handling DHCP requests from clients, while clients use the IP environment data assigned from the server. Compared with BOOTP, DHCP can effectively and dynamically allocate the TCP/IP settings of clients through the concept of “lease”, and as a compatibility consideration, DHCP also fully takes care of the needs of BOOTP clients. First of all, there must be at least one DHCP working on the network, which will listen to the DHCP requests from the network and negotiate the TCP/IP setting environment with the client.
DHCP Server Functions and How it Works
Two computers connected to the Internet communicate with each other, must have their respective IP addresses, due to limited IP address resources, broadband access operators can not assign a fixed IP address to each user who has applied for broadband (the so-called fixed IP is that even when you are not online, others can not use this IP address, this resource has been exclusively occupied by you). So we have to use the DHCP method of temporary address assignment for users who access the Internet. That is, your computer is connected to the Internet before the DHCP server temporarily assigns an IP address to you from the address pool, and the IP address assigned may be different each time you go online, which is related to the IP address resources at that time. When going offline, the DHCP server may assign this address to other computers that come online afterwards. This will effectively save IP addresses, ensuring network communication and increasing the usage rate of IP addresses at the same time.
In a network using TCP/IP protocol, every computer must have at least one IP address to connect and communicate with other computers. In order to facilitate the unified planning and management of IP addresses in the network, DHCP was created. This network service facilitates the effective management of client IP addresses in the local network without the need to manually assign IP addresses one by one.
How DHCP Server Works
DHCP function is divided into two parts: one is the server side and the other is the client side (the client side does not need to be installed, usually the computer starts DHCP Client service by default) DHCP effectively and dynamically assigns TCP/IP settings to clients through the concept of “lease”. Lease is an important concept, when the client uses dynamic address assignment, the DHCP server will dynamically assign IP address to the client, but the assigned IP address is not always available to a client. When the DHCP server assigns an IP address to a client, it also informs the client of the period of time it can use the address (i.e., the lease period). If the client does not apply for an extension after the expiration date, the DHCP server will take back the IP address, and the remaining lease period is the time left for the DHCP server to take back the IP address. Therefore, the client will apply to the CHCP server to extend the lease period before the lease period expires (for example, when there is still half of the lease period left). Of course, when the client no longer uses this IP, it will notify the DHCP server to take back this IP, and then this IP can be assigned to other clients.
DHCP uses a single DHCP server or a group of DHCP servers to manage the distribution of network parameters, and this scheme is fault-tolerant. Even in a network with only a small number of machines, DHCP is still useful because a machine can be added to the local network with little or no impact.
Even for servers that rarely change their addresses, DHCP is still recommended to set their addresses. If a server needs to be reassigned (RFC2071), these changes can be made in as few places as possible. For some devices, such as routers and firewalls, DHCP should not be used. it is also useful to put TFTP or SSH servers on the same machine running DHCP, for centralized management purposes.
DHCP can also be used to assign addresses directly to servers and desktop computers, as well as through a PPP proxy, to dial-up and broadband hosts, and residential NAT gateways and routers. However, DHCP is not generally used on borderless routers and DNS servers.
How to configure DHCP server?
DHCP server can be built on either Windows or Linux operating system, or on network devices (such as routers, Layer 3 switches, etc.). The following only describes the commands related to building DHCP on network devices.
1. Enable DHCP service
By default, DHCP service is not enabled on the router. If you use DHCP server, you must enable DHCP service first. The command format to enable DHCP service is as follows.
- Router(config)# service dhcp
Tip: Use the no option of this command to disable the DHCP service function, such as Router(config)#no service dhcp.
2. Define the DHCP excluded address range.
By default, the DHCP server tries to assign all the subnet addresses defined in the address pool to the DHCP clients. If you want to keep some addresses from being assigned out, for example, they are already assigned to servers or devices, you must explicitly define that these addresses are not allowed to be assigned to clients. The command format to define the DHCP excluded address range is as follows.
- Router(config)#ip dhcp excluded-address low-ip-address [ high-ip-address ]
where low-ip-address is the excluded IP address, or the starting IP address of the excluded IP address range; high-ip-address is the ending IP address of the excluded address range. Use the no option of this command to cancel this definition.
3. Define DHCP address pool
DHCP address pool defines the addresses assigned by DHCP and other parameters transmitted to the client. If DHCP address pool is not configured, even if DHCP server is enabled, it cannot assign addresses to clients. The command format to define the DHCP address pool is as follows.
- Router(config)#ip dhcp pool pool-name
where pool-name is the name of the address pool. Use the no option of this command to delete a defined address pool, such as Router(config)#no ip dhcp pool pool-name.
4. Define the address range in the DHCP address pool.
The address in the DHCP address pool is the address range provided to users. The command format to define the address range in the DCHP address pool is as follows.
- Router(config)#network network-number mask
where network-number is the IP address network number of the DHCP address pool; mask is the IP address network mask of the DHCP address pool. If no mask is defined, the default is the natural network mask. Use the option of this command to delete the defined DHCP address pool network range.
5. Set the default gateway.
Generally, DHCP client needs to get the information of default gateway from DHCP server. the DHCP server needs to specify at least one gateway P address for the client, which must be in the same network segment as the address assigned to the client. The format of the command to set the default gateway address is as follows.
- Router(dhcp-config)#default-router ip-address [ ip-address2…ip-address8]
where ip-address is the defined device gateway address; ip-address2, ip-addresss8 are (optionally) other gateway addresses. Use the no option of this command to delete the set default gateway definition, such as Router(dhcp-config)#no default-router.
6. Specify the DNS server.
When clients use domain names, they need to specify DNS servers. When defining multiple DNS servers, the one written first has the priority is high, and DHCP clients will choose the next DNS server only when communication with the DNS server in front of it fails. The command format for setting client DNS servers is as follows.
- Router(dhcp-config)#dns-server address [address2…address8]
where address is the IP address of the first DNS server; address2…address8 is the address of the other DNS servers. addresses. Use the no option of this command to delete the DNS server definition in DHCP that has been set, such as Router(dhcp-config)# no dns-server.
7. Manual Address Binding (optional)
Address binding refers to the mapping relationship between IP address and client MAC address. There are two methods of address binding. Method 1: Manual binding, which is a static mapping of IP address and MAC address by manual definition in the DHCP server database, manual binding is actually a special address pool. Method 2: Dynamic binding, when DHCP server receives a DHCP request, it dynamically assigns IP addresses from the address pool to clients, thus forming a P-address and MAC address mapping. The method described above is based on dynamic binding.
To define manual address binding, you first need to define a pool of host addresses for each manual binding, and then define the IP address and hardware address (MAC address) of the DHCP client
7.1. Define the hardware address of the DHCP client.
To define the hardware address of a DHCP client, use the DHCP address pool configuration command hardware-address. the no form of this command removes the definition of the hardware address. The command format for defining the hardware address of a DHCP client is as follows.
- Router(dhcp-config)# hardware-address hardware-address type
where hardware-address is to define the MAC address of the DHCP client; type is to mark the DHCP client’s hardware-address is to define the MAC address of DHCP client; type is to mark the hardware platform protocol of DHCP client, which can be defined by string or number. The optional parameters are ethernet, ieee802, also can use the number 1 to indicate 10Mb/s Ethernet, the number 6 to indicate IEEE802 series standard, etc. The parameter defaults to ethernet.
7.2. Defining the IP address and network mask of a DHCP client host.
To define the IP address and network mask of a DHCP client host, use the DHCP address pool configuration command host. the no form of this command removes the definition of the DHCP client IP address and network mask.
- Router(dhcp-config)# host ip-address [netmask]
where ip-address is the IP address of the defined DHCP client host; netmask is the network mask of the defined DHCP client host. netmask is the network mask of the DHCP client host. If the netmask is not explicitly defined, the DHCP server will use the natural network mask of the IP address.