SONiC OS CLI Cheat Sheet: 50 Essential Commands - 夜莺博客

SONiC OS CLI Cheat Sheet: 50 Essential Commands

SONiC (Software for Open Networking in the Cloud) is the open-source network OS used across Microsoft Azure and a growing list of data center operators, but its CLI is unlike IOS or Junos - it is built on Linux tools, Redis-backed config databases, and a Klish-based management shell. If you are new to SONiC, the first hurdle is simply knowing which command to type. This cheat sheet collects 50 essential SONiC commands, grouped by task, that cover daily show, configuration, interface, VLAN, port-channel, routing and troubleshooting operations.

Show Commands (Read-Only)

show version
show hostname
show system health
show interfaces status
show interfaces counters
show interfaces description
show interface Ethernet0
show interface Ethernet0 flap
show vlan brief
show mac
show lldp neighbors
show ip route
show ip route 10.0.0.0/8
show ipv6 route
show bgp summary
show bgp neighbors
show ip prefix-list
show arp
show ndp
show ntp
show logging
show environment

Configuration Commands (Klish)

config interface ip add Ethernet0 10.0.0.1/24
config interface ip remove Ethernet0 10.0.0.1/24
config interface startup Ethernet0
config interface shutdown Ethernet0
config interface speed Ethernet0 100000
config vlan add 10
config vlan del 10
config vlan member add 10 Ethernet4
config vlan member del 10 Ethernet4
config portchannel add PortChannel1
config portchannel del PortChannel1
config portchannel member add PortChannel1 Ethernet8
config portchannel member del PortChannel1 Ethernet8
config bgp add-neighbor 10.0.0.2
config bgp del-neighbor 10.0.0.2
config ntp add 192.168.1.1
config hostname dc-leaf-01
config password admin

Save and Reload

config save -y
config load /etc/sonic/config_db.json
config reload -y
config load_minigraph
config replace /etc/sonic/config_db.json

config save -y writes the running configuration to /etc/sonic/config_db.json - always run it after changes, because SONiC does not auto-persist.

Linux-Level Commands You Will Actually Use

docker ps
docker exec -it bgp sh
docker exec -it swss sh
sonic-cfggen -d --print-data
sonic-cfggen -H -k x86_64-mlnx_msn2700 --print-data
redis-cli -n 4 keys '*'
redis-cli -n 4 hgetall 'VLAN|Vlan10'
show int status | grep Eth | wc -l

SONiC runs services in containers (bgp, swss, syncd, pmon); docker exec is how you get into them. The Redis database instance 4 holds the configuration tables.

Troubleshooting Commands

show logging
show interface Ethernet0 counters
show watermarks
show queue counters
show pfc counters
show buffer_pool watermark
show memory
show processes cpu
show platform
show platform syseeprom
show reboot-cause
show techsupport
sonic-installer list

Quick Reference Table

Task Command
Check interfaces show interfaces status
Add IP to interface config interface ip add Ethernet0 10.0.0.1/24
Create VLAN config vlan add 10
Save config config save -y
Reload config config reload -y
Check BGP show bgp summary
Collect support bundle show techsupport

More SONiC reading: SONiC quick start: install via ONIE and SONiC troubleshooting: packet drops and link issues.

原文链接:https://github.com/sonic-net/SONiC/wiki