Skip to content
Ask AI

DHCP Server Configuration

[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 | Default Lease Time(s) | Max Lease Time(s) | Bind Info | DNS |
+===========+===============+===============+================+=================+=======================+===================+===========+=================+
| test | 192.168.200.0 | 255.255.255.0 | 192.168.200.10 | 192.168.200.100 | 6000 | 12000 | Vlan43 | 114.114.114.114 |
+-----------+---------------+---------------+----------------+-----------------+-----------------------+-------------------+-----------+-----------------+

[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

[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

[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

[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

[Command] show dhcp failover info

[Purpose] Show DHCP server dual-active backup configuration

[View] System View

[Use Cases]

Terminal window
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%

[Command] show dhcp pool config

[Purpose] Show the binding interface status of the DHCP Server service

[View] System View

[Use Cases]

Terminal window
sonic# show dhcp pool config
+-----------------+----------------------+
| Interface | dhcp select server |
+=================+======================+
| Ethernet11 | true |
+-----------------+----------------------+
| Vlan100 | true |
+-----------------+----------------------+
| PortChannel0002 | true |
+-----------------+----------------------+

[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)#

[Command]

network A.B.C.D mask

[Purpose]

Specify the network segment where the DHCP server assigns the IP address to the Client

[Parameter]

ParameterDescription
A.B.C.Dip-address
masksubnet mask

[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

[Command]

address-pool A.B.C.D A.B.C.D

[Purpose]

Specify the range of IP addresses assigned to client by DHCP server

[Parameter]

ParameterDescription
A.B.C.DStart 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. Support configuring multiple address pools, with non-overlapping ranges. Each address pool must fall within the network scope. 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

[Command]

static-bind ip-address A.B.C.D mac-address nn:nn:nn:nn:nn:nn

[Purpose]

configure static MAC-IP binding on the DHCP server to assign fixed IP addresses to specified terminals

[Parameter]

ParameterDescription
A.B.C.Daddress in the format: A.B.C.D
nn:nn:nn:nn:nn:nntermial mac address in the formart: HH:HH:HH:HH:HH:HH

[View]

DHCP view

[Notes]

Configure the MAC-IP binding with addresses outside the DHCP pool range to ensure fixed IP assignment.

[Use Cases]

sonic(config-dhcp-pool-a)# static-bind ip-address 1.1.1.11 mac-address 00:00:00:00:00:01

[Command]

dns ip_address

[Purpose]

Specify the DNS server address

[Parameter]

ParameterDescription
ip_addressThe 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

[Command]

lease-time default_time max_time

[Purpose]

Specify IP address lease time

[Parameter]

ParameterDescription
default_timeDefault lease time
max_timeMaximum 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

[Command]

routers A.B.C.D

[Purpose] Specify the gateway address assigned to the DHCP client by the DHCP server

[Parameter]

ParameterDescription
A.B.C.DIP address

[View]

DHCP view

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp pool test
sonic(config-dhcp-pool-test)# routers 192.168.1.1

[Command]

server_detect enable

no server_detect enable

[Purpose]

Enable DHCP server connectivity probing function

[View]

DHCP Relay view

[Use Cases]

sonic(config-dhcp-relay-dhcp_relay__v4)# server_detect enable

[Command]

server_detect interval time

[Purpose]

Configure DHCP server connectivity probe packet interval

[Parameter]

ParameterDescription
timedefault 30 seconds, range 30-3600

[View]

DHCP Relay view

[Use Cases]

sonic(config-dhcp-relay-dhcp_relay__v4)# server_detect interval 60

[Command]

option43 hex value

[Purpose]

Enable the option43 function of DHCP Server

[Parameter]

ParameterDescription
valueHexadecimal 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

[Command]

bootfile-name bootfile

no bootfile-name

[Purpose]

Configure the boot configuration file name for DHCP clients

[Parameter]

ParameterDescription
bootfileString 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

[Command]

next-server ip_address

no next-server

[Purpose]

Configure the network server IP address to be used by DHCP client during the startup process

[Parameter]

ParameterDescription
ip_addressSpecifies 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

[Command]

tftp-server server_name

[Purpose]

Configure the TFTP Server Address for DHCP Clients

[Parameter]

ParameterDescription
server_nameA 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

[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

[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)#

[Command]

if-match rule rule_idoption 93 hex value

if-match rule rule_id option 82 remote-id value

[Purpose]

Configuring matching rules for DHCP user classes

[Parameter]

ParameterDescription
rule_idrange 1-16, the higher number has higher priority

[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

[Command]

dhcp option-group id

[Purpose]

Create a DHCP option group and enter the option group view

[Parameter]

ParameterDescription
idThe 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

[Command]

class name option-group id

[Purpose]

Bind user classes to option groups.

[Parameter]

ParameterDescription
nameDHCP class name
idOption 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

[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]

ParameterDescription
nameDHCP user class name
ip_addressStart 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