DHCP and DHCP relay
DHCP
DHCP (Dynamic Host Configuration Protocol, dynamic host configuration protocol) is a LAN network protocol, using UDP protocol to work, DHCP monitors port 67, the client monitors port 68
Two main purposes:
1. Automatically assign IP addresses to internal networks or network service providers
2. To users or internal network administrators as a means of central management of all computers
DHCP benefits:
1. Reduce the workload of the administrator
2. Avoid the possibility of input errors
3. Avoid IP address conflict
4. When changing the IP address segment, there is no need to reconfigure each user's IP address
5. Improve the use of IP addresses Rate
6. Convenient client configuration
The typical application mode of DHCP is as follows: set up a dedicated DEcP server in the network, which is responsible for centrally assigning various network address parameters (mainly including IP address, subnet mask, broadcast address, default gateway address, DNS server address); other As a DHCP client, the host configures the network card to automatically obtain an address, and then communicates with the DHCP server to complete the automatic configuration process.
The working principle of DHCP's automatic IP address acquisition
1. The client searches for the server in the network.
The client sends a DHCP Discover message by broadcasting to find the server.
2. The server responds to the client for service.
The server sends a DHCP Offer message through unicast to provide network information such as an IP address to the client, and selects an unallocated IP address from the IP address pool to assign the client
3. The client sends a service request to the server.
If multiple DHCP servers send a DHCP-offer message to the client, the client only accepts the first received DHCP-offer message and extracts the IP address, and then the client broadcasts a DHCP Request message to inform the server The client locally chooses to use the IP address
. 4. The server provides services to the client.
The server sends a DHCP Ack message through unicast to inform the client that the IP address is legal and usable, and adds the lease information of the IP address in the option field.
5. Re-login the
DHCP client every time it re-login to the network, it does not need to be sent again DHCP Discover information, but directly send the DHCP Request request information containing the IP address assigned last time.
6. Renew the lease
When the lease of the IP address leased by the DHCP server to the client reaches 50%, the lease needs to be renewed. The client directly sends a DHCP Request packet to the server that provides the lease, requesting to renew the existing address lease
DHCP has two configuration methods
. 1. Interface mode: The interface address pool can dynamically assign IP addresses, the range is the network segment where the IP address of the interface is located, and it only takes effect on this interface, when the DHCP server receives a request message from the DHCP client Later, the DHCP server will use the address network segment of the interface to assign addresses to the client.
2. Global mode: In the global mode, multiple global address pools are set up, and there is a corresponding relationship between the defined address pool network segment and port IP that are the same network segment, that is, multiple different network segment pools correspond to their respective ports, and finally realized Clients on different network segments automatically obtain corresponding addresses
DHCP relay
Application scenario
DHCP relay is needed for forwarding when DHCP and LAN are not in the same network segment
Working principle
1. When the DHCP client starts and initializes the DHCP, it broadcasts a configuration request message on the local network.
2. If there is a DHCP server in the local network, you can directly perform DHCP configuration without a DHCP relay.
3. If the local network does not have a DHCP server, the network device connected to this network with DHCP relay function will process the broadcast message appropriately and forward it to the designated DHCP server on other networks.
4. The DHCP server performs corresponding configuration according to the information provided by the client, and sends the configuration information to the client through the DHCP relay to complete the dynamic configuration of the client.
Configuration
AR1-1 | AR4-1 |
---|---|
int g0/0/0 | int g0/0/0 |
ip address 192.168.20.1 24 | ip address 192.168.30.2 24 |
undo shutdown | undo shutdown |
int g0/0/1 | int g0/0/1 |
ip address 192.168.30.1 24 | ip address 192.155.10.10 24 |
undo shutdown | undo shutdown |
dhcp enable (Enable the DHCP function in system mode) | dhcp enable |
int g0/0/0 | ip pool 1 (create address pool name) |
dhcp select interface (based on the interface configuration DHCP) | gateway-list 192.168.30.1 (Set the egress gateway address of the DHCP client) |
dhcp server dns-list 8.8.8.8 (automatically assign DNS server address to the client) | network 192.168.30.0 mask 24 (Configure DHCP assignable address network segment, and the mask can also be represented by 24) |
dhcp server lease day 7 (configure interface-based DHCP servser lease period (the default lease period is 1 day)) | dns-list 8.8.8.8 |
ip route-static 3.3.3.3 32 192.168.30.2 (must be configured with a static/default or dynamic route to the DHCP server) | excluded-ip-address 192.168.30.20 192.168.30.40 (configure reserved address) |
int g0/0/1 | int g0/0/0 |
dhcp select relay (open relay function) | dhcp select global (Configure DHCP as global mode) |
dhcp relay server-ip 192.168.30.2 (point to the address of the DHCP server xxx.xxx.xxx.xxx to request DHCP service) | ip pool 2 |
gateway-list 192.155.10.1 | |
network 192.155.10.0 mask 24 | |
dns-list 8.8.8.8 | |
static-bind ip-address 192.155.10.88 mac-address 5489-98D0-72A5 (Bind IP192.155.10.88 is fixedly assigned to the machine with MAC 5489-98D0-72A5, the IP in the pool is required) | |
lease day 10 | |
int g0/0/1 | |
dhcp select global | |