Skip to content
Ask AI

DHCP

Table 1 DHCP Relay View

CommandPurpose
show dhcp_relayDisplay DHCP Relay configuration.

[Command] show dhcp_relay

[Purpose] Display DHCP Relay configuration.

[View] Privileged User View

[Use Cases]

sonic# show dhcp_relay
+------------------------------+-------------+-----------+------------+----------+--------+
| Name | down link | up link | loopback | server | vrf |
+==============================+=============+===========+============+==========+========+
| test__v4(v4) | NA | NA | NA | NA | NA |
+------------------------------+-------------+-----------+------------+----------+--------+
| test_dhcp_over_vxlan__v4(v4) | vlan20 | 0/2 | NA | 21.0.0.2 | vrf 123|
+------------------------------+-------------+-----------+------------+----------+--------+
| test_dhcp_over_vxlan__v6(v6) | vlan20 | 0/2 | NA | 2123::2 | vrf 123|
+------------------------------+-------------+-----------+------------+----------+--------+

Table 2 DHCP Relay Config

CommandPurpose
feature dhcp state enableEnable feature DHCP.
dhcp-relay name {v4|v6} [vrf vrf_name]Create an IPv4 or IPv6 DHCP Relay instance.
downlink vlan vlan-id [giaddr A.B.C.D | option82_sub5 A.B.C.D]Specify the VLAN for DHCP Relay (on DHCP Client side).
giaddr loopback loopback-idSpecify the gateway IP address.
server dhcp_server_ipSet DHCP Server IP.
uplink {ethernet|link-aggregation|vlan} interface_nameSpecify the uplink port (on DHCP Server side) of DHCP Relay.

[Command] feature dhcp state enable

[Purpose] Enable feature DHCP.

[View] Global Configuration View

[Notes] Run command feature dhcp state disable to disable DHCP feature.

[Use Cases]

sonic# configure terminal
sonic(config)# feature dhcp state enable

[Command] dhcp-relay name {v4|v6} [vrf vrf_name]

[Purpose] Create an IPv4 or IPv6 DHCP Relay instance.

[Parameters]

ParameterDescription
nameName of DHCP Relay instance.
vrf_nameVRF name, specifying the VRF where the DHCP Relay instance is located.

[View] Global Configuration View

[Notes] Please run feature dhcp state enable to enable DHCP before you configure DHCP Relay.

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp-relay test v4

[Command] downlink vlan vlan-id [giaddr A.B.C.D | option82_sub5 A.B.C.D]

[Purpose] Specify the VLAN for DHCPv4 Relay (on DHCP Client side).

[Parameters]

ParameterDescription
vlan-idVLAN ID, the range is [1,4094].
giaddrRelay agent address, only supported by DHCPv4 Relay instance.
option82_sub5Set option82, only supported by DHCPv4 Relay instance.

[View] DHCP Relay Instance Configuration View

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp-relay test v4
sonic(config-dhcp-relay-test)# downlink vlan 10 giaddr 10.0.0.1

[Command] downlink vlan vlan-id [option option client-linklayer-addr]

[Purpose] Specify the VLAN for DHCPv6 Relay (on DHCP Client side).

[Parameters]

ParameterDescription
vlan-idVLAN ID, the range is [1,4094].
client-linklayer-addrRelay agent address,only IP,Configure option 79,after configuration, the message forwarded by Relay will carry the MAC address of the client. Only supported by DHCPv6 Relay instance.

[View] DHCP Relay Instance Configuration View

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp-relay test v6
sonic(config-dhcp-relay-test)# downlink vlan 100 option client-linklayer-addr

[Command] giaddr loopback loopback-id

[Purpose] Specify the gateway IP address.

[Parameters]

ParameterDescription
loopback-idLoopback interface number, integer form, range from 0 to 999.

[View] DHCP Relay Instance Configuration View

[Notes] By default, the switch will set the giaddr to the IP address of the host VLAN interface when it receives a DHCP request.

[Use Cases]

sonic(config)# dhcp-relay test v4
sonic(config-dhcp-relay-test)# giaddr loopback 0

[Command] server dhcp_server_ip

[Purpose] Set DHCP Server IP.

[Parameters]

ParameterDescription
dhcp_server_ipSpecify the DHCP server IP address.

[View] DHCP Relay Instance Configuration View

[Use Cases]

sonic(config)# dhcp-relay test v4
sonic(config-dhcp-relay-test)# server 10.248.0.1

[Command] uplink {ethernet|link-aggregation|vlan} interface_name

[Purpose] Specify the uplink port ( on DHCP Server side) of DHCP Relay.

[Parameters]

ParameterDescription
interface_nameInterface name (eg.0/1)

[View] DHCP Relay Instance Configuration View

[Use Cases]

sonic(config)# dhcp-relay test v4
sonic(config-dhcp-relay-test)# uplink ethernet 0/2

Table 3 DHCP Server View

CommandPurpose
**show dhcp pool info ** [ip-version {v4|v6}]Display DHCP Server pool information.
**show dhcp pool ip-use ** [ip-version {v4|v6}]Display the address assigned to clients by DHCP Server.
**show dhcp pool expired ** [ip-version {v4|v6}]Display DHCP Server expired ip information.
show dhcp classDisplay DHCP Server User Class configuration.
show dhcp option-groupDisplay DHCP Server option group configuration.

[Command] **show dhcp pool info ** [ip-version {v4|v6}]

[Purpose] Display DHCP Server pool infomation.

[View] Privileged User View

[Notes] When no IP address version is specified, default view of IPv4 version address pool information

[Use Cases]

sonic# show dhcp pool info
--------------------------------------------------
Pool-name : t1
Network : 201.0.0.0
Mask : 255.255.255.0
Lease : 201.0.0.20 - 201.0.0.50
Lease_default_time : 600
Lease_max_time : 7200
Used Lease : 0
Total Lease : 72

show dhcp pool ip-use [ip-version {v4|v6}]

Section titled “show dhcp pool ip-use [ip-version {v4|v6}]”

[Command] **show dhcp pool ip-use ** [ip-version {v4|v6}]

[Purpose] Display the addresses assigned to clients by DHCP Server.

[View] Privileged User View

[Notes] When no IP address version is specified, the default view is the IP address information assigned by the IPv4 version

[Use Cases]

sonic# show dhcp pool ip-in-use ip-version v4
Reading leases from /var/lib/dhcp/dhcpd.leases
IP MAC hostname binding state starts ends
==================================================================================================================
total lease :0

show dhcp pool expired [ip-version {v4|v6}]

Section titled “show dhcp pool expired [ip-version {v4|v6}]”

[Command] **show dhcp pool expired ** [ip-version {v4|v6}]

[Purpose] Display DHCP Server expired ip information.

[View] Privileged User View

[Notes] When no IP address version is specified, the default view is the IP address information reclaimed by IPv4 version

[Use Cases]

sonic# show dhcp pool expired
Reading leases from /var/lib/dhcp/dhcpd.leases
IP MAC hostname binding state starts ends
==================================================================================================================
201.0.0.35 18:17:25:37:64:40 -NA- free 2024-10-21 03:07:01 2024-10-21 03:09:07
total lease :1

[Command] show dhcp class

[Purpose] Display DHCP Server User Class configuration.

[View] Privileged User View

[Use Cases]

sonic# show dhcp class
!
dhcp class t1
!
dhcp class test1
if-match rule 1 option 93 hex ffff

[Command] show dhcp option-group

[Purpose] Display DHCP Server option group configuration.

[View] Privileged User View

[Use Cases]

sonic# show dhcp option-group
!
dhcp option-group 1
option43 hex 01 force

Table 4 DHCP Server Config

CommandPurpose
dhcp serverEnable interface DHCP Server function.
dhcp pool name [v6]Create a DHCP server address pool and enter the DHCP pool configuration view.
dhcp class nameCreate DHCP Server user class and enter DHCP user class configuration view.
dhcp option-group idCreate a DHCP Server option group and enter the option group configuration view.
network {A.B.C.D A.B.C.D|A::B A::B}Configure the network of the address pool.
address-pool start_ip end_ipConfigure address pool IP range.
lease-time default_time max_timeConfigure lease time.
bootfile nameConfigure bootfile option.
dns {A.B.C.D|A::B}Configure DNS option.
next-server {A.B.C.D|A::B}Configure next server option.
tftp-server {A.B.C.D|A::B}Configure tftp server option.
capwap-ac A.B.C.DConfigure capwap-ac option.
routers A.B.C.DConfigure routers option.
option43 hex value forceConfigure option43 option.
class name address-pool start_ip end_ipConfigure user class IP range.
class name option-group idBind class and option-group.
if-match rule rule_id option option_idCreate user class matching rule.
dhcp failover nameEnable DHCP Server failover.
adddress {A.B.C.D|loopback 0}Configure failover local IP.
peer address A.B.C.DConfigure failover peer IP.
auto-partner-down timeConfigure peer offline time.
max-response-delay timeConfigure maximum communication interruption time.
role {primary|secondary}Configure primary and secondary roles.

[Command] dhcp server

[Purpose] Enable interface DHCP Server function.

[View] Physical Interface / VLANIF Configuration View

[Notes] Run command no dhcp server to disable interface DHCP Server fuction.

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp pool test1

[Command] dhcp pool name [v6]

[Purpose] Create a DHCP server address pool and enter the DHCP pool configuration view.

[Parameters]

ParameterDescription
nameDHCP Server pool name.

[View] Global Configuration View

[Notes] Default creation of IPv4 type address pool, with v6 parameter, creates IPv6 type address pool Run command no dhcp pool name [v6] to delete DHCP pool.

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp pool test1

[Command] dhcp class name

[Purpose] Create DHCP Server user class and enter DHCP user class configuration view.

[Parameters]

ParameterDescription
nameDHCP Server class name.

[View] Global Configuration View

[Notes] Run command no dhcp class name to delete DHCP class.

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp class t1

[Command] dhcp option-group id

[Purpose] Create a DHCP Server option group and enter the option group configuration view.

[Parameters]

ParameterDescription
idDHCP Server option group ID, with a value range of 1-65535.

[View] Global Configuration View

[Notes] Run command no dhcp option-group id to delete DHCP option-group.

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp option-group 1

[Command] network {A.B.C.D A.B.C.D|A::B A::B}

[Purpose] Configure the network of the address pool.

[Parameters]

ParameterDescription
A.B.C.D A.B.C.DIPv4 address and mask.
A:;B A::BIPv6 address and mask.

[View] DHCP pool Configuration View

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp pool test1
sonic(config-dhcp-pool-t1)# network 100.0.0.1 255.255.255.0

[Command] address-pool start_ip end_ip

[Purpose] Configure address pool IP range.

[Parameters]

ParameterDescription
start_ipStart_ip.
end_ipEnd_ip

[View] DHCP pool Configuration View

[Notes] The end_ip address must be after the start_ip address

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp pool test1
sonic(config-dhcp-pool-t1)# address-pool 100.0.0.10 100.0.0.100

[Command] lease-time default_time max_time

[Purpose] Configure lease time.

[Parameters]

ParameterDescription
default_timeDefault lease time, in seconds, with a value range greater than 300, default value is 600.
max_timeThe maximum lease time, in seconds, needs to be greater than the default lease time, the default value is 7200.

[View] DHCP pool Configuration View

[Notes] Run command no lease-time to restore lease time to default value

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp pool test1
sonic(config-dhcp-pool-t1)# lease-time 300 1000

[Command] bootfile name

[Purpose] Configure bootfile option.

[Parameters]

ParameterDescription
nameFile name.

[View] DHCP pool Configuration View/DHCP option-group Configuration View

[Notes] Run command no bootfile to delete bootfile option

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp pool test1
sonic(config-dhcp-pool-t1)# bootfile-name test.txt

[Command] dns {A.B.C.D|A::B}

[Purpose] Configure DNS option.

[Parameters]

ParameterDescription
A.B.C.DIPv4 address.
A::BIPv6 address.

[View] DHCP pool Configuration View/ DHCP option-group Configuration View

[Notes] Run command no dns to delete DNS option

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp pool test1
sonic(config-dhcp-pool-t1)# dns 8.8.8.8

[Command] next-server {A.B.C.D|A::B}

[Purpose] Configure next-server option.

[Parameters]

ParameterDescription
A.B.C.DIPv4 address.
A::BIPv6 address.

[View] DHCP pool Configuration View

[Notes] Run command no next-server to delete next-server option

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp pool test1
sonic(config-dhcp-pool-t1)# next-server 1.1.1.1

[Command] tftp-server {A.B.C.D|A::B}

[Purpose] Configure tftp-server option.

[Parameters]

ParameterDescription
A.B.C.DIPv4 address.
A::BIPv6 address.

[View] DHCP pool Configuration View/DHCP option-group Configuration View

[Notes] Run command no tftp-server to delete tftp-server option

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp pool test1
sonic(config-dhcp-pool-t1)# tftp-server 2.2.2.2

[Command] capwap-ac A.B.C.D

[Purpose] Configure capwap-ac option.

[Parameters]

ParameterDescription
A.B.C.DIPv4 address.

[View] DHCP pool Configuration View/DHCP option-group Configuration View

[Notes] Run command no capwap-ac to delete capwap-ac option

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp pool test1
sonic(config-dhcp-pool-t1)# capwap-ac 3.3.3.3

[Command] routers A.B.C.D

[Purpose] Configure routers option.

[Parameters]

ParameterDescription
A.B.C.DIPv4 address.

[View] DHCP pool Configuration View/DHCP option-group Configuration View

[Notes] Only supports IPv4 addresses Run command no routers to delete routers option

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp pool test1
sonic(config-dhcp-pool-t1)# routers 100.0.0.1

[Command] option43 hex value force

[Purpose] Configure option43 option.

[Parameters]

ParameterDescription
valueHexadecimal number.

[View] DHCP pool Configuration View/DHCP option-group Configuration View

[Notes] Run command no option43 to delete routers option

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp pool test1
sonic(config-dhcp-pool-t1)# option43 hex 10 force

[Command] class name address-pool start_ip end_ip

[Purpose] Configure DHCP user class IP range.

[Parameters]

ParameterDescription
nameClass name
start_ipStart_ip
end_ipEnd_ip

[View] DHCP pool Configuration View

[Notes] Run command no class name address-pool to delete DHCP user class IP range

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp pool test1
sonic(config-dhcp-pool-t1)# class test1 address-pool 100.0.0.110 100.0.0.150

[Command] class name option-group id

[Purpose] Bind class and option-group.

[Parameters]

ParameterDescription
nameClass name.
idOption-group ID

[View] DHCP pool Configuration View

[Notes] Run command no class name option-group to unbind class and option-group

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp pool test1
sonic(config-dhcp-pool-t1)# class test1 option-group 1

[Command] if-match rule rule_id option option_id

[Purpose] Create user class matching rule.

[Parameters]

ParameterDescription
rule_idRule id, also indicating priority, with a value range of 1-16. The larger the value, the higher the priority.
option_idOption ID, currently only supports 82 and 93.

[View] DHCP class Configuration View

[Notes] Run command no if-match rule rule_id to delete user class matching rule.

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp class test1
sonic(config-dhcp-class-test1)# if-match rule 1 option 93 hex ffff

[Command] dhcp failover name

[Purpose] Enable DHCP Server failover.

[Parameters]

ParameterDescription
nameInstance name.

[View] Global Configuration View

[Notes] Run command no dhcp failover name to disable DHCP Server failover.

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp failover t456

[Command] adddress {A.B.C.D|loopback 0}

[Purpose] Configure local IP.

[Parameters]

ParameterDescription
A.B.C.DIPv4 address.

[View] DHCP failover Configuration View

[Notes] Run command no address to delete local IP

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp failover t456
sonic(config-dhcp-failover-t456)# address 20.0.0.1

[Command] peer address A.B.C.D

[Purpose] Configure peer IP.

[Parameters]

ParameterDescription
A.B.C.DIPv4 address.

[View] DHCP failover Configuration View

[Notes] Run command no peer address to delete peer IP

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp failover t456
sonic(config-dhcp-failover-t456)# peer address 20.0.0.2

[Command] auto-partner-down time

[Purpose] Configure peer offline time.

[Parameters]

ParameterDescription
timePeer offline time, in seconds and ranging from 1 to 3600. By default, peers will not go offline.

[View] DHCP failover Configuration View

[Notes] Run command auto-partner-down to disable peer offline function

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp failover t456
sonic(config-dhcp-failover-t456)# auto-partner-down 100

[Command] max-response-delay time

[Purpose] Configure maximum communication interruption time.

[Parameters]

ParameterDescription
timeThe maximum communication interruption time, measured in seconds, ranges from 30 to 3600, with a default value of 60.

[View] DHCP failover Configuration View

[Notes] Run command nomax-response-delay to restore maximum communication time to default value

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp failover t456
sonic(config-dhcp-failover-t456)# max-response-delay 100

[Command] role {primary|secondary}

[Purpose] Configure primary and secondary roles.

[Parameters]

ParameterDescription
A.B.C.DIPv4 address.

[View] DHCP failover Configuration View

[Use Cases]

sonic# configure terminal
sonic(config)# dhcp failover t456
sonic(config-dhcp-failover-t456)# role primary