Configuration Guide
DHCP Configuration Guide
25 min
dhcp server configuration dhcp server configuration 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 1 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 2 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 3 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 4 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 5 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 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 interface interface ethernet \<id> | interface 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 1 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> 2 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> 3 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 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 devices 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 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 split \<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 \<id> interface vlan \<id> enable dhcp on the interface ip address dhcp alloc dhcp relay configuration dhcp relay configuration introduction introduction since dhcp uses broadcasting to send request messages during the ip address dynamic allocation process, it is suitable only for cases where the dhcp client and server are within the same subnet when the dhcp server and client are not in the same subnet, the dhcp relay mechanism needs to be employed explanation of principles explanation of principles in the context of dhcp relay, the message exchange is depicted as shown in the diagram 1 the client sends dhcp discovery broadcast when a dhcp client is located within a subnet and needs to obtain an ip address and other configuration information, it broadcasts a dhcp discovery message (dhcp discover) to the broadcast address of the local network 2 relay agent forwards dhcp message the dhcp relay agent forwards the received dhcp discovery message (along with any other relevant dhcp messages) to the dhcp server, encapsulating the original broadcast message 3 dhcp server response upon receiving the forwarded dhcp discovery message in a different subnet, the dhcp server assigns an ip address to the client and generates a dhcp offer broadcast message (dhcp offer) back to the relay agent 4 relay agent forwards dhcp offer the dhcp relay agent forwards the dhcp offer message back to the original subnet, encapsulating the ip address and configuration information provided by the dhcp server 5 client requests and acknowledges the dhcp client, upon receiving the dhcp offer message, selects a server and sends a dhcp request message (dhcp request) to request the allocated ip address this request message is also forwarded by the relay agent to the dhcp server 6 server acknowledgment and response upon receiving the dhcp request message, the dhcp server sends a dhcp acknowledgment message (dhcp acknowledgment) back to the relay agent similarly, the relay agent forwards the acknowledgment message to the subnet where the client is located through this process, dhcp relay allows dhcp clients and servers located in different subnets to communicate without requiring a dhcp server to be set up on each subnet the relay agent acts as a bridge, forwarding dhcp messages between different subnets, enabling dhcp communication to span physical network boundaries adding option82 adding option82 by default, when a device receives a request message from a dhcp client and re encapsulates it, a field called "option82" is appended to the message to record the client's location information the "relay agent ip address" field is the ip address of the vlan svi interface where the client is located dhcp servers that support parsing the option82 field can use the information carried within it to determine which ip address range to allocate to the client if the dhcp server does not support parsing the option82 field, the determination can be made based on the "relay agent ip address " however, in scenarios involving cluster networks, access devices are configured as distributed gateways with the same svi interface address in such cases, the "dhcp agent address" command needs to be used to allocate a unique agent ip address to each device this is done to enable dhcp servers, when sending response messages, to use this unique ip address as the destination address, allowing differentiation among different access devices dhcp relay configuration dhcp relay configuration operation command description enter the system configuration view configure terminal create a dhcp relay instance and enter the dhcp relay view dhcp relay relay name {v4|v6} specify the vlan to which the dhcp clients belong that require dynamic ip address allocation down link interface vlan vlan id specify the interface through which the device is connected to the dhcp server up link interface interface type interface name specify the ip address of the dhcp server server ip ip address configure using the loopback interface as the relay agent ip loopback interface loopback id enable the option to not encapsulate the option82 field (if needed) no option82 configure the relay agent ip address (if needed) dhcp agent address ip address configuration example configuration example network requirements suppose user 1 and user 3 of a company belong to department a, user 2 and user 4 belong to department b, device a acts as a dhcp relay, and device b acts as a dhcp server it is required to assign ip addresses between 10 1 2 2 and 10 1 2 100 to department a and between 10 1 10 2 and 10 1 10 100 to department b dns server, gateway and other information are assigned by dhcp server procedure 1 configuration of device a \# create vlan 100 and configure the ip address sonic(config)# vlan 100 sonic(config)# interface ethernet 1 sonic(config if 1)# switchport access vlan 100 sonic(config)# interface ethernet 2 sonic(config if 2)# switchport access vlan 100 sonic(config)# interface vlan 100 sonic(config vlanif 100)# ip address 10 1 2 1/24 \# create vlan 200 and configure the ip address sonic(config)# vlan 200 sonic(config)# interface ethernet 3 sonic(config if 3)# switchport access vlan 200 sonic(config)# interface ethernet 4 sonic(config if 4)# switchport access vlan 200 sonic(config)# interface vlan 200 sonic(config vlanif 200)# ip address 10 1 10 1/24 \# configure the ip address sonic(config)# interface ethernet 5 sonic(config if 5)# ip address 10 110 1 1/30 sonic(config)# interface loopback 0 sonic(config if lo0)# ip address 10 120 1 1/32 enable dhcp relay function sonic(config)# dhcp relay test v4 sonic(config dhcp relay test v4)# down link interface vlan 100 sonic(config dhcp relay test v4)# down link interface vlan 200 sonic(config dhcp relay test v4)# up link interface 5 sonic(config dhcp relay test v4)# server ip 10 110 1 2 sonic(config dhcp relay test v4)# loopback interface loopback 0 sonic(config dhcp relay test v4)# exit 2 configuration of device b sonic(config)# interface ethernet 1 sonic(config if 1)# ip address 10 110 1 2/30 sonic(config if 1)# dhcp select server \# create dhcp address pool sonic(config)# dhcp pool usera sonic(config dhcp pool usera)# network 10 1 2 1 255 255 255 0 sonic(config dhcp pool usera)# address pool 10 1 2 2 10 1 2 100 sonic(config dhcp pool usera)# dns 8 8 8 8 sonic(config dhcp pool usera)# exit sonic(config)# dhcp pool userb sonic(config dhcp pool userb)# network 10 1 10 1 255 255 255 0 sonic(config dhcp pool userb)# address pool 10 1 10 2 10 1 10 100 sonic(config dhcp pool userb)# dns 8 8 8 8 sonic(config dhcp pool userb)# exit verify configuration 1 check the requested ip address on the pc c \users\test>ipconfig windows ip configuration ethernet adapters ethernet connect to a specific dns suffix local link ipv6 address fe80 a495\ f96e 6573\ c383%12 ipv4 address 10 1 10 144 subnet mask 255 255 255 0 default gateway 10 1 10 1 2 use the commands show dhcp relay config and show dhcp pool info on device a and device b respectively to view the dhcp relay and dhcp server configuration
