SONiC CLI Cheat Sheet: show, config and docker Commands - 夜莺博客

SONiC CLI Cheat Sheet: show, config and docker Commands

SONiC looks like a familiar network OS from the prompt but behaves like a Linux application underneath, and that is exactly what tripped up the first generation of operators. This cheat sheet groups the commands you reach for daily: the show family for state, the config family for change, and the Linux tools behind them for the cases where the CLI has no answer.

Show commands

show version
show interfaces status
show interfaces counters
show ip interfaces
show ip route
show ip bgp summary
show vlan brief
show mac
show lldp neighbors
show platform summary
show environment
show logging

SONiC show output is generated from Redis rather than from a monolithic config file, so a discrepancy between what the CLI reports and what the hardware does usually means the APPL_DB and CONFIG_DB have diverged.

Configuration

config interface speed Ethernet0 40000
config interface startup Ethernet0
config interface mtu Ethernet0 9000
config interface ip add Ethernet0 10.0.0.1/30
config vlan add 100
config vlan member add 100 Ethernet4
config save /etc/sonic/config_db.json
config reload /etc/sonic/config_db.json

config save writes the running configuration into config_db.json; config reload rebuilds the system from it, which briefly interrupts forwarding. Treat reload as a maintenance-window action, not a "fix it quickly" action.

Docker, Redis and the tools behind the CLI

docker ps
docker exec -it bgp sh
docker logs bgp --tail 200
redis-cli -n 4 KEYS 'VLAN*'      # CONFIG_DB is database 4
redis-cli -n 4 HGETALL 'VLAN|100'
show techsupport

Each SONiC feature runs in its own container, so "BGP is down" is answered with docker ps and docker logs bgp far faster than with any routing command. Understanding that CONFIG_DB lives in Redis database 4 and that most show commands read from other databases explains why a hand-edited JSON file is not automatically live.

A safe change workflow

  1. Make the change with config commands, not by editing JSON.
  2. Verify with the matching show command.
  3. config save to persist.
  4. Keep the previous config_db.json under version control so a bad rollout has a one-command rollback.

Related reading: SuzieQ network observability, Geneve vs VXLAN encapsulation, Linux network namespaces and veth.

原文链接:SONiC Command Line Interface Guide (sonic-utilities)