Skip to content

Commit ffc891d

Browse files
authored
[dhcp_server] Add CLI sample for dhcp_server (sonic-net#4033)
What I did Add CLI sample for dhcp_server How I did it Add CLI sample for dhcp_server
1 parent 1e9d04c commit ffc891d

File tree

1 file changed

+314
-0
lines changed

1 file changed

+314
-0
lines changed

doc/Command-Reference.md

Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
* [DHCP Relay show commands](#dhcp-relay-show-commands)
5757
* [DHCP Relay clear commands](#dhcp-relay-clear-commands)
5858
* [DHCP Relay config commands](#dhcp-relay-config-commands)
59+
* [DHCP Server](#dhcp-server)
60+
* [DHCP Server show commands](#dhcp-server-show-commands)
61+
* [DHCP Server config commands](#dhcp-server-config-commands)
5962
* [Drop Counters](#drop-counters)
6063
* [Drop Counter show commands](#drop-counters-show-commands)
6164
* [Drop Counter config commands](#drop-counters-config-commands)
@@ -3683,6 +3686,317 @@ This command is used to add or del IPv6 DHCP Relay destination addresses to a VL
36833686

36843687
Go Back To [Beginning of the document](#) or [Beginning of this section](#dhcp-relay)
36853688

3689+
## DHCP Server
3690+
### DHCP Server show commands
3691+
This sub-section of commands is used to show the DHCP Server configuratoin and status
3692+
**show dhcp_server info**
3693+
3694+
This command is used to show dhcp_server config.
3695+
- Usage
3696+
```
3697+
show dhcp_server ipv4 info [--with_customize_option] [<dhcp_interface>]
3698+
```
3699+
3700+
- Example
3701+
```
3702+
show dhcp_server ipv4 info Vlan1000
3703+
+-------------+--------+-------------+---------------+-----------------+---------+
3704+
| Interface | Mode | Gateway | Netmask | Lease Time(s) | State |
3705+
+=============+========+=============+===============+=================+=========+
3706+
| Vlan1000 | PORT | 192.168.0.1 | 255.255.255.0 | 900 | enabled |
3707+
+-------------+--------+-------------+---------------+-----------------+---------+
3708+
3709+
show dhcp_server ipv4 info --with_customized_options Vlan1000
3710+
+-------------+--------+-------------+---------------+-----------------+---------+----------------------+
3711+
| Interface | Mode | Gateway | Netmask | Lease Time(s) | State | Customized Options |
3712+
+=============+========+=============+===============+=================+=========+======================+
3713+
| Vlan1000 | PORT | 192.168.0.1 | 255.255.255.0 | 900 | enabled | option_1 |
3714+
+-------------+--------+-------------+---------------+-----------------+---------+----------------------+
3715+
3716+
show dhcp_server ipv4 info
3717+
+-------------+--------+-------------+---------------+-----------------+----------+
3718+
| Interface | Mode | Gateway | Netmask | Lease Time(s) | State |
3719+
+=============+========+=============+===============+=================+==========+
3720+
| Vlan1000 | PORT | 192.168.0.1 | 255.255.255.0 | 900 | enabled |
3721+
+-------------+--------+-------------+---------------+-----------------+----------+
3722+
| Vlan2000 | PORT | 192.168.0.1 | 255.255.255.0 | 300 | disabled |
3723+
+-------------+--------+-------------+---------------+-----------------+----------+
3724+
```
3725+
3726+
**show dhcp_server range**
3727+
3728+
This command is used to show dhcp_server ip range.
3729+
- Usage
3730+
```
3731+
show dhcp_server ipv4 range [<range_name>]
3732+
```
3733+
3734+
- Example
3735+
```
3736+
show dhcp_server ipv4 range range_1
3737+
+-------------+-------------+-------------+---------+
3738+
|IP Range Name |IP Start |IP End |IP count |
3739+
|--------------+-------------+-------------+---------+
3740+
|range_1 |192.168.0.5 |192.168.0.10 |6 |
3741+
+--------------+-------------+-------------+---------+
3742+
3743+
admin@bjw-can-720dt-2:~$ show dhcp_server ipv4 range range_1
3744+
+---------+-------------+-------------+------------+
3745+
| Range | IP Start | IP End | IP Count |
3746+
+=========+=============+=============+============+
3747+
| range_1 | 192.168.0.2 | 192.168.0.2 | 1 |
3748+
+---------+-------------+-------------+------------+
3749+
3750+
show dhcp_server ipv4 range
3751+
+---------+-------------+--------------+------------+
3752+
| Range | IP Start | IP End | IP Count |
3753+
+=========+=============+==============+============+
3754+
| range_2 | 192.168.0.2 | 192.168.0.25 | 24 |
3755+
+---------+-------------+--------------+------------+
3756+
| range_1 | 192.168.0.2 | 192.168.0.2 | 1 |
3757+
+---------+-------------+--------------+------------+
3758+
| range1 | 192.168.1.2 | 192.168.1.2 | 1 |
3759+
+---------+-------------+--------------+------------+
3760+
```
3761+
3762+
**show dhcp_server option**
3763+
3764+
This command is used to show dhcp_server customized option.
3765+
3766+
- Usage
3767+
```
3768+
show dhcp_server ipv4 option [<option_name>]
3769+
```
3770+
3771+
- Example
3772+
```
3773+
show dhcp_server ipv4 option option_1
3774+
+---------------+-------------+---------+--------+
3775+
| Option Name | Option ID | Value | Type |
3776+
+===============+=============+=========+========+
3777+
| option_1 | 223 | host_1 | string |
3778+
+---------------+-------------+---------+--------+
3779+
3780+
show dhcp_server ipv4 option
3781+
+---------------+-------------+---------+--------+
3782+
| Option Name | Option ID | Value | Type |
3783+
+===============+=============+=========+========+
3784+
| option_1 | 223 | host_1 | string |
3785+
+---------------+-------------+---------+--------+
3786+
| option2 | 222 | 123 | string |
3787+
+---------------+-------------+---------+--------+
3788+
```
3789+
3790+
**show dhcp_server lease**
3791+
3792+
This command is used to show dhcp_server lease.
3793+
- Usage
3794+
```
3795+
show dhcp_server ipv4 lease [<dhcp_interface>]
3796+
```
3797+
3798+
- Example
3799+
```
3800+
show dhcp_server ipv4 lease
3801+
+--------------------+-------------------+-------------+---------------------+---------------------+
3802+
| Interface | MAC Address | IP | Lease Start | Lease End |
3803+
+====================+===================+=============+=====================+=====================+
3804+
| Vlan1000|Ethernet5 | 10:70:fd:b6:10:05 | 192.168.0.8 | 2025-08-19 04:11:39 | 2025-08-19 04:26:39 |
3805+
+--------------------+-------------------+-------------+---------------------+---------------------+
3806+
3807+
show dhcp_server ipv4 lease Vlan1000
3808+
+--------------------+-------------------+-------------+---------------------+---------------------+
3809+
| Interface | MAC Address | IP | Lease Start | Lease End |
3810+
+====================+===================+=============+=====================+=====================+
3811+
| Vlan1000|Ethernet5 | 10:70:fd:b6:10:05 | 192.168.0.8 | 2025-08-19 04:11:39 | 2025-08-19 04:26:39 |
3812+
+--------------------+-------------------+-------------+---------------------+---------------------+
3813+
```
3814+
3815+
**show dhcp_server port**
3816+
3817+
This command is used to show dhcp_server port binding.
3818+
- Usage
3819+
```
3820+
show dhcp_server ipv4 port [<dhcp_interface>]
3821+
```
3822+
3823+
- Example
3824+
```
3825+
show dhcp_server ipv4 port Vlan1000
3826+
+---------------------+--------------+
3827+
| Interface | Bind |
3828+
+=====================+==============+
3829+
| Vlan1000|Ethernet25 | 192.168.0.28 |
3830+
+---------------------+--------------+
3831+
| Vlan1000|Ethernet38 | 192.168.0.41 |
3832+
+---------------------+--------------+
3833+
| Vlan1000|Ethernet7 | 192.168.0.10 |
3834+
+---------------------+--------------+
3835+
| Vlan1000|Ethernet10 | 192.168.0.13 |
3836+
+---------------------+--------------+
3837+
| Vlan1000|Ethernet27 | 192.168.0.30 |
3838+
+---------------------+--------------+
3839+
```
3840+
3841+
### DHCP Server config commands
3842+
3843+
This sub-section of commands is used to add or remove the DHCP Server related configuration
3844+
3845+
**config dhcp_server add**
3846+
3847+
This command is used to add dhcp_server for DHCP interface.
3848+
3849+
- Usage
3850+
```
3851+
config dhcp_server ipv4 add --mode <mode> [--dup_gw_nm] [--lease_time <lease_time>] [--gateway <gateway>] [--netmask <netmask>] <dhcp_interface>
3852+
3853+
Options:
3854+
mode: Specify mode of assign IP, currently only support 'PORT'. [required]
3855+
lease_time: Time that the client can lease IP once. [not required, default value is 900(s)]
3856+
dup_gw_nm: Indicate whether to use gateway and netmask of server interface. [not required if gateway and netmask is given]
3857+
gateway: Gateway of DHCP server. [ignored if dup_gw_nm is given]
3858+
netmask: Netmask of DHCP server. [ignored if dup_gw_nm is given]
3859+
```
3860+
3861+
- Example
3862+
```
3863+
config dhcp_server ipv4 add --mode PORT --dup_gw_nm --lease_time 300 Vlan1000
3864+
config dhcp_server ipv4 add --mode PORT --lease_time 300 --gateway 192.168.0.1 --netmask 255.255.255.0 Vlan1000
3865+
```
3866+
3867+
**config dhcp_server del**
3868+
3869+
This command is used to delete all dhcp_server config for DHCP interface, to be clarify that delete a `enable` dhcp_server is not allowed.
3870+
- Usage
3871+
```
3872+
config dhcp_server ipv4 del <dhcp_interface>
3873+
```
3874+
3875+
- Example
3876+
```
3877+
config dhcp_server ipv4 del Vlan1000
3878+
```
3879+
3880+
**config dhcp_server enable/disable**
3881+
3882+
This command is used to enable or disable dhcp_server for DHCP interface, this state is set to `disable` by default while adding a new dhcp_server.
3883+
- Usage
3884+
```
3885+
config dhcp_server ipv4 (enable | disable) <dhcp_interface>
3886+
```
3887+
3888+
- Example
3889+
```
3890+
config dhcp_server ipv4 enable Vlan1000
3891+
```
3892+
3893+
3894+
**config dhcp_server update**
3895+
3896+
This command is used to update dhcp_server config.
3897+
- Usage
3898+
```
3899+
config dhcp_server ipv4 update --mode <mode> [--dup_gw_nm] [--lease_time <lease_time>] [--gateway <gateway>] [--netmask <netmask>] <dhcp_interface>
3900+
```
3901+
3902+
- Example
3903+
```
3904+
config dhcp_server ipv4 update --mode PORT --dup_gw_nm --lease_time 300 Vlan1000
3905+
```
3906+
3907+
**config dhcp_server range add/del/update**
3908+
3909+
This command is used to config ip range.
3910+
- Usage
3911+
```
3912+
# <ip_end> is not required, if not given, means ip_end is equal to ip_start
3913+
config dhcp_server ipv4 range add <range_name> <ip_start> [<ip_end>]
3914+
config dhcp_server ipv4 range update <range_name> <ip_start> [<ip_end>]
3915+
config dhcp_server ipv4 range del <range_name>
3916+
```
3917+
3918+
- Example
3919+
```
3920+
config dhcp_server ipv4 range add range1 192.168.0.1
3921+
3922+
config dhcp_server ipv4 range update range1 192.168.0.2
3923+
3924+
config dhcp_server ipv4 range del range1
3925+
```
3926+
3927+
**config dhcp_server bind/unbind**
3928+
3929+
This command is used to config dhcp ip per interface.
3930+
- Usage
3931+
```
3932+
config dhcp_server ipv4 bind <vlan_interface> <interface> (--range <ip_range_list> | <ip_list>)
3933+
config dhcp_server ipv4 unbind <vlan_interface> <interface> (--range <ip_range_list> | <ip_list> | all)
3934+
```
3935+
3936+
- Example
3937+
```
3938+
config dhcp_server ipv4 bind Vlan1000 Ethernet1 --range range1
3939+
config dhcp_server ipv4 bind Vlan2000 Ethernet0 192.168.1.5,192.168.1.6
3940+
config dhcp_server ipv4 unbind Vlan2000 Ethernet1 --range range1
3941+
config dhcp_server ipv4 unbind Vlan2000 Ethernet0 192.168.1.5,192.168.1.6
3942+
```
3943+
3944+
**config dhcp_server option add**
3945+
3946+
This command is used to add dhcp option.
3947+
Type field can refer to [Customize DHCP Packet Options](#customize-dhcp-packet-options).
3948+
3949+
- Usage
3950+
```
3951+
config dhcp_server ipv4 option add <option_name> <option_id> [<type>] <value>
3952+
```
3953+
3954+
- Example
3955+
```
3956+
config dhcp_server ipv4 option add option_1 223 string host_1
3957+
```
3958+
3959+
**config dhcp_server option del**
3960+
3961+
This command is used to del dhcp option.
3962+
3963+
- Usage
3964+
```
3965+
config dhcp_server ipv4 option del <option_name>
3966+
```
3967+
3968+
- Example
3969+
```
3970+
config dhcp_server ipv4 option del option_1
3971+
```
3972+
3973+
**config dhcp_server option bind**
3974+
3975+
This command is used to bind dhcp option per dhcp interface.
3976+
- Usage
3977+
```
3978+
config dhcp_server ipv4 option bind <dhcp_interface> <option_list>
3979+
```
3980+
3981+
- Example
3982+
```
3983+
config dhcp_server ipv4 option bind Vlan1000 option_1
3984+
```
3985+
3986+
**config dhcp_server option unbind**
3987+
3988+
This command is used to unbind dhcp option.
3989+
- Usage
3990+
```
3991+
config dhcp_server ipv4 option unbind <dhcp_interface> (--all | <option_name>)
3992+
```
3993+
3994+
- Exampe
3995+
```
3996+
config dhcp_server ipv4 option unbind Vlan1000 --all
3997+
3998+
config dhcp_server ipv4 option unbind Vlan1000 option_1
3999+
```
36864000

36874001
## Drop Counters
36884002

0 commit comments

Comments
 (0)