Command Line Reference
IP Service
DHCP Server Configuration
40 min
dhcp server configuration dhcp server configuration show dhcp pool info ip version {v4|v6} show dhcp pool info ip version {v4|v6} \[command] show dhcp pool info ip version {v4|v6} \[purpose] view the status and configuration of the created dhcp address pool \[view] system view \[use cases] sonic# show dhcp pool info ip version v4 + + + + + \| pool name | network | mask | lease start | lease end +===========+===============+===============+================+================= \| test | 192 168 200 0 | 255 255 255 0 | 192 168 200 10 | 192 168 200 100 + + + + + + + + + + \| default lease time(s) | max lease time(s) | bind info | dns | +=======================+===================+===========+=================+ \| 6000 | 12000 | vlan43 | 114 114 114 114 | + + + + + show dhcp pool ip in use \[a b c d/a b] show dhcp pool ip in use \[a b c d/a b] \[command] show dhcp pool ip in use \[a b c d/a b] \[purpose] view dhcp address pool ip address allocation status \[view] system view \[usage scenario] display ip addresses already assigned in the dhcp pool \[use cases] sonic# show dhcp pool ip in use reading leases from /var/lib/dhcp/dhcpd leases ip mac hostname binding state starts ends \===================================================================================================== 20 1 1 41 00 00 12 01 01 15 xinertel active 2024 02 26 09 27 00 2024 02 26 09 37 00 20 1 1 23 00 00 12 01 01 03 xinertel active 2024 02 26 09 27 00 2024 02 26 09 37 00 20 1 1 22 00 00 12 01 01 02 xinertel active 2024 02 26 09 27 00 2024 02 26 09 37 00 total lease 3 show dhcp pool expired \[a b c d/a b] show dhcp pool expired \[a b c d/a b] \[command] show dhcp pool expired \[a b c d/a b] \[purpose] view expired ip addresses in the dhcp address pool \[view] system view \[usage scenario] display ip addresses that were previously allocated in the dhcp address pool but have expired their lease \[use cases] sonic# show dhcp pool expired reading leases from /var/lib/dhcp/dhcpd leases ip mac hostname binding state starts ends \===================================================================================================== 20 1 1 10 00 00 02 01 01 0a na free 2024 02 26 09 09 57 2024 02 26 09 11 30 20 1 1 9 00 00 02 01 01 09 na free 2024 02 26 09 09 57 2024 02 26 09 11 30 total lease 2 show dhcp class show dhcp class \[command] show dhcp class \[purpose] display dhcp class \[view] system view \[use cases] sonic# show dhcp class dhcp class pc if match rule 1 option 93 hex 0000 dhcp class test1 dhcp class x86 if match rule 1 option 93 hex 0001 show dhcp option group show dhcp option group \[command] show dhcp option group \[purpose] display dhcp option group \[view] system view \[use cases] sonic# show dhcp option group dhcp option group 1 bootfile name ftp\ //teraspek\ teraspek\@150 1 0 1/test txt option43 hex 8888 force tftp server 150 1 0 1 dhcp option group 2 bootfile name ftp\ //teraspek\ teraspek\@150 1 0 1/ppap txt option43 hex 8888 force tftp server 150 1 0 1 show dhcp failover info show dhcp failover info \[command] show dhcp failover info \[purpose] view dhcp server dual active backup configuration \[view] system view \[use cases] sonic# show dhcp failover info \ failover name ceshi local address 30 102 0 230 peer address 30 102 0 216 role primary max response delay 60 heartbeat inteval 20 local state normal peer state normal split 50% dhcp pool dhcp pool \[command] dhcp pool name no dhcp pool name \[purpose] create address pools \[view] system configuration view \[use cases] sonic# configure terminal sonic(config)# dhcp pool test sonic(config dhcp pool test)# network ip address network ip address mask \[command] network ip address mask \[purpose] specify the network segment where the dhcp server assigns the ip address to the client \[parameter] parameter parameter description description ip address supports configuration of ipv4 and ipv6 addresses in the format of a b c d/a b mask ipv4 subnet mask in dotted decimal format; ipv6 network prefix in x\ x x\ x x\ x x\ x \[view] dhcp view \[notes] when creating dhcp address pools, it is advisable to prioritize the configuration of this command \[use cases] sonic# configure terminal sonic(config)# dhcp pool test sonic(config dhcp pool test)# network 192 168 0 0 255 255 0 0 address pool address pool \[command] address pool ip address ip address \[purpose] specify the range of ip addresses assigned to client by dhcp server \[parameter] parameter description ip address start ip address and end ip address in the format a b c d/a b \[view] dhcp view \[notes] before specifying the address pool range, user should first use the network command to confirm the subnet to which the addresses belong if this address pool is already bound to a specific vlan, any necessary modifications require unbinding and rebinding to take effect \[use cases] sonic# configure terminal sonic(config)# dhcp pool test sonic(config dhcp pool test)# address pool 192 168 1 1 192 168 10 1 dns dns \[command] dns ip address \[purpose] specify the dns server address \[parameter] parameter description ip address the format is a b c d/a b \[view] dhcp view \[use cases] sonic# configure terminal sonic(config)# dhcp pool test sonic(config dhcp pool test)# dns 8 8 8 8 lease time lease time \[command] lease time default time max time \[purpose] specify ip address lease time \[parameter] parameter parameter description description default time default lease time max time maximum lease time \[view] dhcp view \[usage scenario] clients use ip addresses assigned by dhcp servers for network communication when the default lease time is reached, clients must either renew their lease or obtain a new ip address from the dhcp server if a client fails to renew its lease after the default lease time, it will continue using the ip address lease until it reaches the maximum lease time once the maximum lease time expires, the client must request a new ip address \[use cases] sonic# configure terminal sonic(config)# dhcp pool test sonic(config dhcp pool test)# lease time 6000 12000 routers routers \[command] routers a b c d \[purpose] specify the gateway address assigned to the dhcp client by the dhcp server \[parameter] parameter parameter description description a b c d ip address \[view] dhcp view \[use cases] sonic# configure terminal sonic(config)# dhcp pool test sonic(config dhcp pool test)# routers 192 168 1 1 option43 hex option43 hex value \[command] option43 hex value \[purpose] enable the option43 function of dhcp server \[parameter] parameter parameter description description value hexadecimal number, according to the ac format requirements of different vendors \[view] dhcp view \[usage scenario] option 43 is used to specify the ip address of the ac for the ap so that the ap can establish a connection with the ac \[use cases] sonic(config)# dhcp pool 1 sonic(config dhcp pool 1)# option43 hex 8007000001ac100102 bootfile name bootfile name bootfile \[command] bootfile name bootfile \[purpose] configure the boot configuration file name for dhcp clients \[parameter] parameter parameter description description bootfile string format, case sensitive, specifying the configuration file name \[view] dhcp view \[usage scenario] dhcp servers can provide network configuration parameters needed by clients, such as boot configuration files, in addition to assigning ip addresses to clients by configuring this command, the dhcp server includes the specified file name in offer and ack messages sent to clients subsequently, dhcp clients can use this file name to retrieve the boot configuration file from a designated file server \[use cases] sonic(config)# dhcp pool 1 sonic(config dhcp pool 1)# bootfile name test json next server next server ip address \[command] next server ip address \[purpose] configure the network server ip address to be used by dhcp client during the startup process \[parameter] parameter parameter description description ip address specifies the server ip address to be used by the dhcp client \[view] dhcp view \[usage scenario] in addition to assigning ip addresses to dhcp clients, dhcp servers can also allocate server ip addresses for providing network services to dhcp clients for example, some clients like ip phones may require connecting to a specified server to install software after obtaining an ip address automatically by executing this command to configure the server address that the client should use after automatically obtaining an ip address, the client will request configuration information from the specified server after acquiring an ip address automatically \[use cases] sonic(config)# dhcp pool 1 sonic(config dhcp pool 1)# next server 192 168 0 10 tftp server tftp server server name \[command] tftp server server name \[purpose] configure the tftp server address for dhcp clients \[parameter] parameter parameter description description server name a case sensitive string specifying the tftp server address or domain name used by dhcp clients \[view] dhcp view \[usage scenario] after booting up, devices may need to access configuration files from a tftp server by configuring this option, dhcp clients can obtain the ip address of a tftp server while acquiring an ip address, enabling them to access the server after booting up to retrieve necessary information \[use cases] sonic(config)# dhcp pool 1 sonic(config dhcp pool 1)# tftp server 192 168 0 10 dhcp select server dhcp select server \[command] dhcp select server \[purpose] enable the dhcp server feature on the interface using the global address pool \[view] interface view \[notes] this command is used for the dhcp server when the dhcp server receives a dhcp message from a dhcp client, it will look up a suitable ip address from the address pool to assign to the client \[use cases] sonic(config)# interface ethernet 1 sonic(config if 1)# dhcp select server dhcp class dhcp class name \[command] dhcp class name \[purpose] creating a dhcp user class \[view] system configuration view \[usage scenario] creating a dhcp user class involves configuring a set of parameters and options that are associated with a specific class of dhcp clients \[use cases] sonic(config)# dhcp class test1 sonic(config dhcp class test1)# if match rule if match rule id \[command] if match rule id option 93 hex value if match rule id option 82 remote id value \[purpose] configuring matching rules for dhcp user classes \[parameter] parameter parameter description description id rule id, the range of values from 1 to 16 a smaller number indicates a higher priority value specifies the content used to match the specified option in the message, in hexadecimal string format \[view] dhcp class view \[usage scenario] the dhcp server determines the dhcp user class to which a dhcp client belongs by matching the messages sent by the dhcp client with the rules configured in this command within the dhcp user class view, multiple matching rules can be configured by repeatedly executing the "if match" command as long as any rule successfully matches, the dhcp client is considered part of that user class, and the contents bound to the option group for that user class can be assigned to the client \[notes] currently, only filtering of option 93 is supported \[use cases] sonic(config)# dhcp class test1 sonic(config dhcp class test1)# if match rule 1 option 93 hex 0000 dhcp option group dhcp option group id \[command] dhcp option group id \[purpose] create a dhcp option group and enter the option group view \[parameter] parameter parameter description description id the range of values from 1 to 65535 \[view] system configuration view \[use cases] sonic(config)# dhcp option group 1 sonic(config dhcp option group 1)# bootfile name test txt sonic(config dhcp option group 1)# tftp server 150 1 0 1 class name option group class name option group id \[command] class name option group id \[purpose] bind user classes to option groups \[parameter] parameter parameter description description name dhcp class name id option group id \[view] dhcp view \[notes] a dhcp user class can only be associated with one dhcp option group \[use cases] sonic(config)# dhcp pool test sonic (config dhcp pool test)# class pc option group 1 sonic (config dhcp pool test)# class x86 option group 2 class name address pool class name address pool ip address start ip address end \[command] class name address pool ip address start ip address end \[purpose] configure the assignment of specific address pools based on the user class of the dhcp address pool \[parameter] parameter parameter description description name dhcp user class name ip address start ip address and end ip address in the format a b c d/a b \[view] dhcp view \[notes] before specifying the address pool range, user should first use the network command to confirm the subnet to which the addresses belong if this address pool is already bound to a specific vlan, any necessary modifications require unbinding and rebinding to take effect \[use cases] sonic# configure terminal sonic(config)# dhcp pool test sonic(config dhcp pool test)# class test address pool 192 168 1 1 192 168 10 1 sonic(config dhcp pool test)# class public address pool 192 168 20 1 192 168 30 1 failover failover \[command] failover string \[purpose] configure the dhcp address pool to be bound with a dual active backup \[parameter] parameter parameter description description string failover name \[view] dhcp view \[usage scenario] this scenario applies to environments like mc lag where dual device load balancing is implemented in such setups, dhcp servers are deployed on two devices that share the same address pool if one of the servers fails, the other server takes over and manages the allocation of all dhcp addresses from the shared pool this redundancy ensures continuous availability and reliability of ip address assignments for network clients \[use cases] sonic# configure terminal sonic(config)# dhcp pool test sonic(config dhcp pool test)# failover test address address \[command] address \[purpose] this feature configures the local ip address used for protocol interactions between two dhcp servers in a dhcp failover scenario \[parameter] parameter parameter description description loopback0 loopback0 ip address a b c d ip address of the local device interface \[view] dhcp failover view \[use cases] sonic(config)# dhcp failover ceshi sonic(config dhcp failover ceshi)# address loopback0 peer address peer address \[command] peer address \[purpose] this feature configures the peer ip address used for protocol interactions between two dhcp servers in a dhcp failover scenario \[parameter] parameter parameter description description a b c d ip address of the peer device interface \[view] dhcp failover view \[use cases] sonic(config)# dhcp failover ceshi sonic(config dhcp failover ceshi)# peer address 30 102 0 216 role role \[command] role \[purpose] configure the server role during dual active backup \[parameter] parameter parameter description description primary primary server secondary backup server \[view] dhcp failover view \[notes] the primary dhcp server allows you to specify a split value, which determines the percentage of the address pool it will manage \[use cases] sonic(config)# dhcp failover ceshi sonic(config dhcp failover ceshi)# role primary max response delay max response delay \[command] max response delay \[purpose] configure the max response delay for communication interruption during dual active backup \[parameter] parameter parameter description description interval time interval, range 30 3600 seconds, default is 60 seconds \[view] dhcp failover view \[usage scenario] if a server does not receive messages from its failover peer after the set time, it considers the communication link between the two servers interrupted each server then manages its own address pool when receiving a dhcp request from a client, both servers will allocate different ip addresses, with the client confirming the address from the first dhcp relay message once communication between the dhcp servers is restored, they will synchronize the address allocation that occurred during the failure \[use cases] sonic(config)# dhcp failover ceshi sonic(config dhcp failover ceshi)# max response delay 30 auto partner down auto partner down \[command] auto partner down \[purpose] enable the timed delay for dual active backup \[parameter] parameter parameter description description second time interval, range 1 3600 \[view] dhcp failover view \[usage scenario] when the two servers are in a state of communication link interruption, after the configured delay timer, the servers will automatically enter the partner down state the surviving dhcp server will consider its peer to be down after the lease time configured for the address pool, the active server will have full authority to allocate addresses from the entire address pool to clients \[use cases] sonic(config)# dhcp failover ceshi sonic(config dhcp failover ceshi)# auto partner down 60 split split \[command] split \[purpose] set the server address allocation weight \[view] dhcp failover view \[usage scenario] when the two servers can achieve load balancing and failover, they calculate a hash value in the range of 1 255 based on the client identifier field in the dhcp request message these 255 values are divided according to the configured weight ratio for example, if the primary server's weight is set to 80 and the backup server's weight is set to 20, then 80% of these 255 values will be allocated to the primary server, and the remaining 20% will go to the backup server \[use cases] sonic(config)# dhcp failover ceshi sonic(config dhcp failover ceshi)# split 80
