Configuration Guide
DHCP Configuration Guide
34 min
introduction introduction dynamic host configuration protocol (dhcp) is a technology used for centralized dynamic management and configuration of user ip addresses dhcp belongs to the tcp/ip protocol, defined by rfc 2131, and adopts a client/server communication mode the client (dhcp client) submits a configuration request to the server (dhcp server), and the server returns the configuration information assigned to the client it is usually applied in large local area network environments, mainly for centralized management and allocation of ip addresses, enabling hosts in the network environment to dynamically obtain information such as ip addresses, gateway addresses, dns server addresses, etc , and can improve address utilization however, users do not need to equip a dhcp server on every network when the dhcp client and dhcp server are not in the same network segment, dhcp relay can be configured on the corresponding device to forward dhcp messages between the dhcp server and dhcp client, helping clients without ip addresses to obtain ip across network segments while avoiding the problem of too many dhcp servers basic basic concepts dhcp server dhcp server the dhcp server is mainly responsible for selecting idle ip addresses from the ip address pool to allocate to dhcp clients, and can also provide network parameters for dhcp clients, such as gateway addresses, tftp server addresses, etc ability to manage ip address leases, track and manage ip address lease terms, avoid address conflicts, and promptly recover and reassign ip addresses released by dhcp clients dhcp client dhcp client dhcp clients mainly send dhcp requests to the network, obtaining information such as ip addresses and network parameters through the dhcp protocol dhcp relay dhcp relay dhcp relay is mainly responsible for forwarding dhcp messages between dhcp servers and dhcp clients, assisting dhcp servers in dynamically allocating network parameters to dhcp clients, and realizing the forwarding of dhcp messages in different network segments address pool address pool an address pool is a collection of all ip addresses that dhcp servers can allocate to clients in addition to ip addresses, the address pool can also be configured with network parameters such as lease term, subnet mask, default gateway, etc lease time lease time when the dhcp server assigns an ip address to a client, it also sets a usage period for the client, which is the lease term before the lease term expires, if the client still needs to continue using this ip address, it will initiate a renewal request to renew the lease if it is no longer needed, it will actively release the ip address after reaching the lease term the dhcp server will retrieve the ip address released by the client and put it back into the address pool for reuse class and option group class and option group currently, it supports assigning specific ip addresses and network parameters based on certain user information user class is to create matching conditions, match this type of user information, binds the address pool after matching, and allocate ip addresses currently, it only supports matching the remote id and circuit id of option 82, as well as option 93, which is the system architecture information of the client the option group is to assign specific network parameters to users matched on the user class dhcp option dhcp option the option in dhcp messages is used to transmit control information and network configuration parameters, enabling dynamic address allocation while providing clients with richer network configuration information the range of dhcp options is 1 255, and common dhcp options are shown in the following table table 1 dhcp options table 1 dhcp options option id option content 1 subnet mask 3 gateway address 6 dns server address 43 manufacturer customization 50 ip address options requested by the client 51 lease time 53 dhcp message type 55 request a list of options the client uses this option to indicate which network configuration parameters need to be obtained from the server the content of this option is the option value corresponding to the parameter requested by the client 60 manufacturer identification, the client uses this option to identify the manufacturer to which they belong 61 client identifier 66 tftp server 67 bootfile 82 dhcp relay info basic principle basic principle we will introduce the process of obtaining an ip address for a dhcp client for the first time in both scenarios without and with dhcp relay no dhcp relay scene no dhcp relay scene when the dhcp client and dhcp server are in the same network segment, dhcp packets do not need to be forwarded through dhcp relays when a dhcp client first joins the network, it sends a dhcp discover broadcast message to all devices in the network, searching for available dhcp server information after receiving the dhcp address request from the client, the dhcp server selects an unallocated ip from the ip address pool and sends a dhcp offer packet to the dhcp client the offer packet contains ip address, lease information, server information, and other content after receiving the offer packet, the dhcp client sends a req broadcast packet to the dhcp server the req packet contains information about the dhcp server and the ip address to be assigned, formally requesting the assigned ip address from the server if there are multiple dhcp servers and dhcp clients responding to dhcp offer messages, the dhcp client generally only receives the first dhcp offer message received after receiving the req message, the dhcp server determines whether the dhcp server information in the req message is its own if it is not, it discards the message if it is, it sends an ack confirmation message to the client to obtain the ip address dhcp relay scene dhcp relay scene when the dhcp client and dhcp server are in different network segments, dhcp packets need to be forwarded through dhcp relays when a dhcp client first joins the network, it sends a dhcp discover broadcast message requesting an ip address after receiving the discover request message initiated by the client, the dhcp relay changes the destination ip address in the message to the address of the dhcp server, changes the source address of the message to the address of the dhcp relay, and then sends the dhcp discover message to the server in unicast form after receiving the dhcp discover message, the dhcp server assigns parameters such as ip address to the client and then sends a dhcp offer message to the dhcp relay unicast after receiving the offer message sent by the server, the dhcp relay will forward it to the dhcp client after receiving the offer message, the dhcp client will send the dhcp req message to the dhcp relay in broadcast form after receiving the req message, the dhcp relay will also forward it to the dhcp server in unicast form after receiving the req message, the dhcp server replies with an ack message to the dhcp relay, and the relay device forwards it to the dhcp client after receiving the ack confirmation message, the dhcp client obtains the ip address dhcp configuration dhcp configuration dhcp default setting dhcp default setting table 2 dhcp default setting table 2 dhcp default setting parameter default value dhcp disable deafult lease time 600s max lease time 7200s giaddr address downlink vlan ip enable dhcp feature enable dhcp feature before configuring a dhcp server or dhcp relay, the dhcp feature needs to be enabled first table 3 enable dhcp feature table 3 enable dhcp feature purpose commands description enter global configuration view configure terminal enable dhcp function feature dhcp state enable configure the device as a dhcp server configure the device as a dhcp server enable dhcp server function enable dhcp server function table 4 configure enable dhcp server function table 4 configure enable dhcp server function purpose commands description enter global configuration view configure terminal enter ethernet interface or vlanif configuration view interface \[ ethernet interface name | vlan vlan id ] enable the dhcp server function of the interface dhcp server configure address pool configure address pool table 5 configure address pool table 5 configure address pool purpose commands description enter global configuration view configure terminal create dhcp server address pool and enter dhcp pool configuration view dhcp pool name configure the network segment of the address pool network a b c d/m configure address pool ip range address pool start ip end ip the end ip needs to be after the start ip configure options configure options table 6 configure options table 6 configure options purpose commands description enter global configuration view configure terminal enter dhcp pool configuration view dhcp pool name configure lease time lease time default time max time configure bootfile option bootfile name configure dns option dns a b c d configure next server option next server a b c d configure tftp server option tftp server a b c d configure capwap ac option capwap ac a b c d configure routers option routers a b c d configure option43 option43 hex value force configure address allocation strategy configure address allocation strategy table 7 configure address allocation strategy table 7 configure address allocation strategy purpose commands description enter global configuration view configure terminal create dhcp server user class and enter dhcp user class configuration view dhcp class name create a dhcp server option group and enter the option group configuration view dhcp option group id create user class matching rules if match rule rule id option option id only support option82 and option93 configure user class address range class name address pool start ip end ip bind user classes and option groups class name option group id configure dhcp server failover configure dhcp server failover table 8 configure dhcp server failover table 8 configure dhcp server failover purpose commands description enter global configuration view configure terminal enable dhcp server dual machine hot standby dhcp failover name configure local ip address address { a b c d | loopback 0 } configure peer ip address peer address a b c d configure peer offline time auto partner down time configure maximum communication interruption time max response delay time configure primary and secondary roles role { primary | secondary } configure the device as a dhcp relay configure the device as a dhcp relay configure dhcp relay configure dhcp relay table 9 configure dhcp relay table 9 configure dhcp relay purpose commands description enter global configuration view configure terminal create dhcp relay and enter configuration view dhcp relay name v4 configure dhcp relay downlink vlan downlink vlan vlan id the downlink is the port connected to the client configure dhcp relay uplink uplink { ethernet | link aggregation | vlan } interface name the uplink is the port connected to the server configure dhcp server address server { a b c d } configure giaddr configure giaddr giaddd (gateway ip address) is a field in the dhcp protocol primarily used to identify the ip address of a relay agent by default, the giaddr address is the ip address of the downstream vlan when the dhcp server receives a dhcp packet, it will allocate an ip address to the client from the correct address pool based on the network segment where the giaddr address is located table 10 configure giaddr table 10 configure giaddr purpose commands description enter global configuration view configure terminal create dhcp relay and enter configuration view dhcp relay name v4 configure giaddr downlink vlan vlan id giaddr a b c d configure option82 configure option82 option82 sub5 is a sub option of the relay agent information option in dhcp packets, which is a link selection sub item when assigning ip addresses to dhcp clients, the dhcp server can allocate ip addresses in the same network segment as the address based on this ip address, which helps to achieve more accurate address allocation strategies when there are multiple ip addresses in the current vlan, option82 stub5 can be manually configured to be one of the ip addresses in the specified network segment, thereby controlling the client to obtain the ip address of the specified network segment after configuring option82 stub5, the dhcp server will allocate an ip based on the option82 stub5 address network segment and search for a route to the relay based on giaddr table 11 configure option82 table 11 configure option82 purpose commands description enter global configuration view configure terminal create dhcp relay and enter configuration view dhcp relay name v4 configure the sub5 address of option85 downlink vlan vlan id option82 sub5 a b c d display and maintenance display and maintenance table 12 dhcp display and maintenance table 12 dhcp display and maintenance purpose commands description display the address pool information of dhcp servers show dhcp pool info ip version v4 display the addresses allocated by the dhcp server show dhcp pool ip in use ip version v4 display dhcp server reclaimed addresses show dhcp pool expired ip version v4 display dhcp server user class configuration show dhcp class display dhcp server options group configuration show dhcp option group display dhcp relay configuration information show dhcp relay typical configuration example typical configuration example configure the device as a dhcp server configure the device as a dhcp server networking requirements an efficient ip address management mechanism is needed within a certain enterprise to enable all internal terminals to dynamically obtain valid ip addresses, while avoiding ip conflicts and address waste dhcp servers need to be configured to automatically allocate ip addresses, reducing the workload of manual configuration and improving the automation level of network management topology configuration steps \#enable the interface dhcp server function on the dhcp server sonic# configure sonic(config)# interface ethernet 0/88 sonic(config if 0/88)# dhcp server sonic(config if 0/88)# exit \#configure interface ip address sonic# configure sonic(config)# interface ethernet 0/88 sonic(config if 0/88)# ip address 10 0 0 1/24 sonic(config if 0/88)# exit \#create dhcp address pool, configure address pool ip information, configure network segment and other network parameter information sonic# configure sonic(config)# dhcp pool test1 sonic(config dhcp pool test1)# network 10 0 0 1/24 sonic(config dhcp pool test1)# address pool 10 0 0 10 10 0 0 200 sonic(config dhcp pool test1)# lease time 1200 2000 verify configuration \#show dhcp server configuration sonic# show dhcp pool info \ pool name test1 network 10 0 0 0 mask 255 255 255 0 lease 10 0 0 10 10 0 0 200 lease default time 600 lease max time 7200 after each pc goes online, it will initiate an ip address request and successfully obtain the ip address of the 10 0 0 0/24 network segment configure the device as a dhcp relay configure the device as a dhcp relay networking requirements a large enterprise has multiple office areas and departments, each located in a different subnet to simplify network management, the enterprise has decided to deploy a dhcp server in the core network and ensure that clients in each subnet can successfully obtain ip addresses through dhcp relays topology different subnets require different address pool information to be configured on the dhcp server taking one subnet configuration as an example, the configuration steps are as follows a configure dhcp server information \#enable the dhcp server interface function on the dhcp server device and configure the interface ip address sonic# configure sonic(config)# interface ethernet 0/88 sonic(config if 0/88)# dhcp server sonic(config if 0/88)# ip address 100 0 0 1/24 \#configure static routing to make the ip address assigned by the server reachable to the relay sonic# configure sonic(config)# ip route 10 0 0 2/24 100 0 0 2 \#create dhcp address pool and configure network parameter information sonic# configure sonic(config)# dhcp pool test1 sonic(config dhcp pool test1)# network 10 0 0 1/24 sonic(config dhcp pool test1)# address pool 10 0 0 10 10 0 0 200 sonic(config dhcp pool test1)# lease time 600 1000 sonic(config dhcp pool test1)# exit b configure dhcp relay \#configure the ip address for the interface connected to the server sonic# configure sonic(config)# interface ethernet 0/60 sonic(config if 0/60)# ip address 100 0 0 2/24 \#create a downstream vlan and configure an ip address in the same network segment as the subnet sonic# configure sonic(config)# vlan 100 sonic(config vlan 100)# exit sonic(config)# interface vlan 100 sonic(config vlanif 100)# ip address 10 0 0 2/24 sonic(config vlanif 100)# exit \#create dhcp relay and configure relay information sonic# configure sonic(config)# dhcp relay t1 v4 sonic(config dhcp relay t1)# downlink vlan 100 sonic(config dhcp relay t1)# uplink ethernet 0/60 sonicconfig dhcp relay t1)# server 100 0 0 1 sonic(config dhcp relay t1)# exit verify configuration \#show dhcp relay configuration sonic# show dhcp relay + + + + + + + \| name | down link | up link | loopback | server | vrf | +============+=============+============+============+===========+=======+ \| t1 v4(v4) | vlan100 | 0/60 | na | 100 0 0 1 | na | + + + + + + + when a pc device in the 10 0 0 0/24 network segment goes online, it will automatically obtain an ip address
