Configuration Guide
IP Service Configuration
DHCP Server Configuration
26 min
introduction introduction the dynamic host configuration protocol (dhcp) is a technology used for centralized management and configuration of user ip addresses following the rfc 2131 standard, dhcp operates in a client/server communication model, where dhcp clients send requests to dhcp servers these servers allocate ip addresses to clients with a designated usage period known as the lease time this allocation mechanism is suitable for scenarios involving hosts that require temporary network access or cases where the total number of network hosts is substantial, and the available addresses are limited it is especially useful when hosts do not need a permanent network connection explanation of principles explanation of principles a typical dhcp network setup involves three primary roles dhcp server the dhcp server is responsible for selecting an ip address from an available address pool and assigning it to a dhcp client additionally, it can provide other network parameters such as the default gateway address, dns server addresses, and wins server addresses the dhcp server can handle dhcp request packets within its local subnet as well as dhcp request packets forwarded across subnets through dhcp relays dhcp client the dhcp client actively sends dhcp request packets using the bootp or dhcp protocol to obtain an ip address and other network parameters typical dhcp clients include devices like ip phones, personal computers, mobile phones, diskless workstations, and more dhcp relay when a dhcp client broadcasts a request packet, dhcp servers within the same subnet can receive and process these requests however, if the dhcp client and the dhcp server are not within the same subnet, the dhcp server will not directly receive the client's request in such cases, a dhcp relay is used to forward the dhcp packets unlike traditional ip packet forwarding, the dhcp relay receives dhcp request or response packets, reconstructs new dhcp unicast packets, and forwards them through the layer 3 network ip address acquisition process ip address acquisition process the dhcp process involves the following fundamental stages discovery and request stage when a device (dhcp client) joins a network or requires reconfiguration of network information, it broadcasts a dhcp discover message to all devices in the local network this message is sent to locate available dhcp servers offer and selection stage after one or more dhcp servers within the network receive the dhcp discover message, they respond with a dhcp offer broadcast message this message contains available ip addresses, lease durations, subnet masks, default gateways, and other configuration details request and acknowledgment stage upon receiving multiple dhcp offer messages, the dhcp client typically chooses one of them and sends a dhcp request broadcast message to the chosen server this indicates the client's acceptance of the offered configuration from that specific server acknowledgment and lease stage upon receiving the dhcp request message from the client, the dhcp server sends a dhcp acknowledgment broadcast message to confirm the allocation of the ip address and other configuration details this confirms that the client has successfully acquired the network configuration renewal and release before the lease expires, the client attempts to renew the lease by contacting the dhcp server halfway through the lease duration if the client no longer requires the configuration or leaves the network, it can send a dhcp release message to relinquish the allocated ip address and configuration settings dhcp failover working principle dhcp failover working principle the dhcp failover mechanism ensures high availability and redundancy for dhcp servers, which are critical parts of the network infrastructure by running multiple dhcp servers simultaneously, the network can continue to function even if one server fails the device supports dual dhcp server hot standby, as shown in the diagram two core switches each deploy a dhcp server, and when servers are connected to the network via dual network cards, the two dhcp servers can achieve load balancing and failover the servers compute a hash value from the client identifier field in the dhcp request packet, generating a value between 1 and 255 based on a configured weight distribution percentage, these 255 values are divided between the two dhcp servers for instance, if dhcp server a has a weight of 80 and dhcp server b has a weight of 20, then 80% of the values (204 values) will be assigned to server a, and the remaining 20% (51 values) to server b when a dhcp request is received from a client, the two dhcp servers will check if the hash value of the client falls within their respective assigned range the server with the assigned range will allocate an ip address to the client the server that did not allocate the ip will synchronize the lease information to avoid conflicts dhcp failover uses a specific protocol to manage communication and synchronization between the primary and secondary servers this protocol handles state updates ensuring both servers are aware of the client's current lease status heartbeat mechanism to detect when the primary or secondary server becomes unreachable failover procedures automatically triggering a failover if the primary server is detected to be down handling of failover events the two dhcp servers periodically send heartbeat messages to ensure normal communication between them if no response is received after three consecutive attempts, the servers consider the communication as interrupted and enter the "communications interrupted" state in this state, each server manages its own address pool independently when the servers are in the communications interrupted state and receive a dhcp request from a client, both servers will assign different ip addresses to the client the client will select the ip address from the first received dhcp reply and confirm it once communication between the servers is restored, they will synchronize the address allocation information that occurred during the communication failure to ensure consistency if communication is not restored after a certain period, the remaining active dhcp server will assume that the other server has failed and gone offline after the lease time for the address pool expires, the active server will take control of the entire address pool and will have the authority to assign addresses to clients from the full range of available ip addresses configuring the device as a dhcp server configuring the device as a dhcp server dhcp server configuration dhcp server configuration operation command description enter the system configuration view configure terminal create a dhcp address pool and enter the dhcp configuration view dhcp pool name configure the dynamic allocation subnet for the dhcp address pool network ip address mask specify the ip address range for dynamic ip allocation address pool i p address ip address configure the gateway for dhcp clients routers ip address configure dns addresses for dhcp clients dns ip address set the lease duration for dynamically allocated ip addresses lease time default time max time configure the tftp server address for dhcp clients tftp server server name specify the boot file name for dhcp clients bootfile name bootfile set the next server ip address for dhcp clients next server ip address bind the dhcp server to the interfac interface ethernet id | interface vlan vlan id dhcp select server configuring dhcp option configuring dhcp option the dhcp server can use the dhcp option feature to recognize specific vendor information from the dhcp client's request packets this allows the server to allocate customized network parameters based on the client's vendor or specific needs create a dhcp client classification group define a group that will classify dhcp clients based on specific criteria, such as option 93 dhcp class \<name> if match rule \<id> option 93 hex \<value> create an option group define an option group that will hold the custom dhcp options for the classified clients set the required dhcp options within this option group example to configure option 43 for custom vendor information dhcp option group \<id> option 43 hex \<hex value> example to configure a tftp server tftp server \<ip address> apply the option group to the dhcp client classification group bind the option group to the dhcp client classification group, so that clients matching the classification receive the custom options dhcp pool \<name> class \<name> option group \<id> dhcp failover configuration dhcp failover configuration operation command description configure dhcp failover dhcp failover name specify the local address for dhcp server peer communication address { a b c d | loopback0} define the local ip address used for communication between the dhcp servers specify the peer address of the dhcp server peer address a b c d set the ip address of the peer dhcp server for failover communication assign the primary/secondary role in dhcp failover role {primary|secondary} specify the role of the dhcp server in the failover configuration, either as primary or secondary assign hash value weight for dhcp client allocation splie value configure the hash value weight distribution between the two dhcp servers to manage load balancing enable dhcp failover for a specific dhcp address pool failover name activate the dhcp failover function for a particular address pool to allow redundancy and load balancing configuring the device as a dhcp client configuring the device as a dhcp client once the device is configured as a dhcp client, it can obtain an ip address and other information from the dhcp server however, if the ip address assigned by the dhcp server to the interface falls within the same subnet as the ip address of another interface on the device, the interface will not use that ip address operation command description enter the system configuration view configure terminal enter the interface configuration view interface ethernet interface vlan enable dhcp on the interface ip address dhcp alloc dhcp failover configuration example dhcp failover configuration example network requirements network requirements a company has a cluster of servers, and to ensure the stability of server access, the servers are connected to the network through dual uplinks the servers obtain their ip addresses dynamically from a dhcp server to ensure the reliability of the dhcp service, dhcp servers are deployed on two separate aggregation devices both the aggregation devices and the access devices run mc lag for redundancy and load balancing procedure procedure create an aggregation interface (port channel) and add the physical interfaces connecting to the server and the aggregation devices \# access switch a sonic(config)# interface link aggregation 1 sonic(config)# interface ethernet 1 sonic(config if 1)# link aggregation group 1 sonic(config)# interface link aggregation 2 sonic(config)# interface ethernet 2 sonic(config if 2)# link aggregation group 2 sonic(config)# interface link aggregation 3 sonic(config)# interface ethernet 4 sonic(config if 4)# link aggregation group 3 sonic(config)# interface ethernet 5 sonic(config if 5)# link aggregation group 3 \# switch b sonic(config)# interface link aggregation 1 sonic(config)# interface ethernet 1 sonic(config if 1)# link aggregation group 1 sonic(config)# interface link aggregation 2 sonic(config)# interface ethernet 2 sonic(config if 2)# link aggregation group 2 sonic(config)# interface link aggregation 3 sonic(config)# interface ethernet 4 sonic(config if 4)# link aggregation group 3 sonic(config)# interface ethernet 5 sonic(config if 5)# link aggregation group 3 create a aggregation interface and add the physical interfaces connecting switch a and switch b as a peerlink \# switch a sonic(config)# interface link aggregation 4 sonic(config)# interface ethernet 3 sonic(config if 3)# link aggregation group 4 \# switch b sonic(config)# interface link aggregation 4 sonic(config)# interface ethernet 3 sonic(config if 3)# link aggregation group 4 create vlan 100 and add aggregation interface \# switch a sonic(config)# vlan 100 sonic(config)# interface link aggregation 1 sonic(config lagif 1)# switchport access vlan 100 sonic(config)# interface link aggregation 2 sonic(config lagif 2)# switchport access vlan 100 sonic(config)# interface link aggregation 3 sonic(config lagif 3)# switchport access vlan 100 \# switch b sonic(config)# vlan 100 sonic(config)# interface link aggregation 1 sonic(config lagif 1)# switchport access vlan 100 sonic(config)# interface link aggregation 2 sonic(config lagif 2)# switchport access vlan 100 sonic(config)# interface link aggregation 3 sonic(config lagif 3)# switchport access vlan 100 create vlan 200 and assign an ip address to it add the peerlink aggregation interface to vlan 200 \# switch a sonic(config)# vlan 200 sonic(config)# interface link aggregation 4 sonic(config lagif 4)# switchport trunk vlan 200 sonic(config lagif 4)# switchport trunk vlan 100 sonic(config)# interface vlan 200 sonic(config vlanif 200)# ip address 10 1 1 24/24 \# switch b sonic(config)# vlan 200 sonic(config)# interface link aggregation 4 sonic(config lagif 4)# switchport trunk vlan 200 sonic(config lagif 4)# switchport trunk vlan 100 sonic(config)# interface vlan 200 sonic(config vlanif 200)# ip address 10 1 1 48/24 configure the mc lag, specify the member lag, peerlink, and peerlink ip address \# switch a sonic(config)# mclag domain 1 sonic(mclag domain)# local address 10 1 1 24 sonic(mclag domain)# peer address 10 1 1 48 sonic(mclag domain)# peer link lag 4 sonic(mclag domain)# member lag 1 sonic(mclag domain)# member lag 2 sonic(mclag domain)# member lag 3 \# switch b sonic(config)# mclag domain 1 sonic(mclag domain)# local address 10 1 1 48 sonic(mclag domain)# peer address 10 1 1 24 sonic(mclag domain)# peer link lag 4 sonic(mclag domain)# member lag 1 sonic(mclag domain)# member lag 2 sonic(mclag domain)# member lag 3 configure mc lag and vlan on aggregation device \# switch c sonic(config)# interface link aggregation 1 sonic(config)# interface ethernet 1 sonic(config if 1)# link aggregation group 1 sonic(config)# interface ethernet 2 sonic(config if 2)# link aggregation group 1 sonic(config)# vlan 100 sonic(config)# interface link aggregation 1 sonic(config lagif 1)# switchport access vlan 100 sonic(config)# interface vlan 100 sonic(config vlanif 100)# ip address 192 168 100 1/24 \# switch b sonic(config)# interface link aggregation 1 sonic(config)# interface ethernet 1 sonic(config if 1)# link aggregation group 1 sonic(config)# interface ethernet 2 sonic(config if 2)# link aggregation group 1 sonic(config)# vlan 100 sonic(config)# interface link aggregation 1 sonic(config lagif 1)# switchport access vlan 100 sonic(config)# interface vlan 100 sonic(config vlanif 100)# ip address 192 168 100 1/24 create vlan 200 and add peerlink interface to the vlan \# switch c sonic(config)# vlan 200 sonic(config)# interface link aggregation 2 sonic(config lagif 2)# switchport trunk vlan 200 sonic(config lagif 2)# switchport trunk vlan 100 sonic(config)# interface vlan 200 sonic(config vlanif 200)# ip address 10 1 1 24/24 \# switch d sonic(config)# vlan 200 sonic(config)# interface link aggregation 2 sonic(config lagif 2)# switchport trunk vlan 200 sonic(config lagif 2)# switchport trunk vlan 100 sonic(config)# interface vlan 200 sonic(config vlanif 200)# ip address 10 1 1 48/24 configure the mc lag, specify the member lag, peerlink, and peerlink ip address \# switch c sonic(config)# mclag domain 1 sonic(mclag domain)# local address 10 1 1 24 sonic(mclag domain)# peer address 10 1 1 48 sonic(mclag domain)# peer link lag 2 sonic(mclag domain)# member lag 1 \# switch d sonic(config)# mclag domain 1 sonic(mclag domain)# local address 10 1 1 48 sonic(mclag domain)# peer address 10 1 1 24 sonic(mclag domain)# peer link lag 2 sonic(mclag domain)# member lag 1 create dhcp address pool \# switch c sonic(config)# dhcp failover test sonic(config dhcp failover test)# address 10 1 1 24 sonic(config dhcp failover test)# peer 10 1 1 48 sonic(config dhcp failover test)# role primary sonic(config dhcp failover test)# split 50 sonic(config)# dhcp pool test sonic(config dhcp pool test)# address pool 192 168 100 2 192 168 100 254 sonic(config dhcp pool test)# network 192 168 100 0 255 255 255 0 sonic(config dhcp pool test)# routers 192 168 100 1 sonic(config dhcp pool test)# failover test sonic(config)# interface vlan 100 sonic(cofnig vlanif 100)# dhcp select server \# switch d sonic(config)# dhcp failover test sonic(config dhcp failover test)# address 10 1 1 48 sonic(config dhcp failover test)# peer 10 1 1 24 sonic(config dhcp failover test)# role secondary sonic(config dhcp failover test)# split 50 sonic(config)# dhcp pool test sonic(config dhcp pool test)# address pool 192 168 100 2 192 168 100 254 sonic(config dhcp pool test)# network 192 168 100 0 255 255 255 0 sonic(config dhcp pool test)# routers 192 168 100 1 sonic(config dhcp pool test)# failover test sonic(config)# interface vlan 100 sonic(cofnig vlanif 100)# dhcp select server
