Configuration Management

SONiC manages configuration in a RedisDB instance called ConfigDB. The ConfigDB acts as a single source of truth for SONiC configuration (https://github.com/sonic-net/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md)

The SONiC configuration is represented in a .json file located at /etc/sonic/config_db.json. When the device boots up, SONiC loads the startup configuration from /etc/sonic/config_db.json into the Redis ConfigDB and configures the device.

It is important to note that subsequent changes in the Redis ConfigDB are not automatically written into /etc/sonic/config_db.json. Instead, a user can initiate a write by issuing a sudo config save -y command.

Configuration actions can be performed using one of these methods:

  • Command Line Interface (CLI) commands in the Linux shell
  • Using JSON files
  • vty shell in FRR

CLI commands

Configuration commands

These commands are used to modify the configuration of the device. Configuration commands begin with the config keyword and can be used to configure various router parameters, such as interface configuration, routes, and ACLs.

These commands must be executed with root privileges by using sudo.

Configuration commands directly change the state of the ConfigDB in the Redis container in SONiC. To ensure the configuration state persists across reboots, update the /etc/sonic/config_db.json file using the sudo config save -y command.

For example, to set the hostname of the device:

admin@sonic:~$ sudo hostname R1

Save this configuration using the config save command.

admin@R1:~$ sudo config save -y
Running command: /usr/local/bin/sonic-cfggen -d --print-data > /etc/sonic/config_db.json
admin@R1:~$

Show commands

Show commands are used to display the device's operational state and associated data and begin with the show keyword. Unlike configuration commands, most of these commands can be executed by the default user.

Useful show commands

  • View the interface summary of the device using the show interfaces status command.
admin@sonic:~$ show interfaces status
  Interface                                    Lanes    Speed    MTU    FEC    Alias    Vlan    Oper    Admin    Type    Asym PFC
-----------  ---------------------------------------  -------  -----  -----  -------  ------  ------  -------  ------  ----------
  Ethernet0  2304,2305,2306,2307,2308,2309,2310,2311     400G   9100    N/A     etp0  routed    up       up     N/A         N/A
  Ethernet8  2320,2321,2322,2323,2324,2325,2326,2327     400G   9100    N/A     etp1  routed    up       up     N/A         N/A
 Ethernet16  2312,2313,2314,2315,2316,2317,2318,2319     400G   9100    N/A     etp2  routed    up       up     N/A         N/A
 Ethernet24  2056,2057,2058,2059,2060,2061,2062,2063     400G   9100    N/A     etp3  routed    up       up     N/A         N/A
 Ethernet32  1792,1793,1794,1795,1796,1797,1798,1799     400G   9100    N/A     etp4  routed    up       up     N/A         N/A
 Ethernet40  2048,2049,2050,2051,2052,2053,2054,2055     400G   9100    N/A     etp5  routed    up       up     N/A         N/A
 Ethernet48  2560,2561,2562,2563,2564,2565,2566,2567     400G   9100    N/A     etp6  routed    up       up     N/A         N/A
 Ethernet56  2824,2825,2826,2827,2828,2829,2830,2831     400G   9100    N/A     etp7  routed    up       up     N/A         N/A
 Ethernet64  2832,2833,2834,2835,2836,2837,2838,2839     400G   9100    N/A     etp8  routed    up       up     N/A         N/A
 Ethernet72  2816,2817,2818,2819,2820,2821,2822,2823     400G   9100    N/A     etp9  routed    up       up     N/A         N/A
 Ethernet80  2568,2569,2570,2571,2572,2573,2574,2575     400G   9100    N/A    etp10  routed    up       up     N/A         N/A
 Ethernet88  2576,2577,2578,2579,2580,2581,2582,2583     400G   9100    N/A    etp11  routed    up       up     N/A         N/A
 Ethernet96  1536,1537,1538,1539,1540,1541,1542,1543     400G   9100    N/A    etp12  routed    up       up     N/A         N/A
Ethernet104  1800,1801,1802,1803,1804,1805,1806,1807     400G   9100    N/A    etp13  routed    up       up     N/A         N/A
Ethernet112  1552,1553,1554,1555,1556,1557,1558,1559     400G   9100    N/A    etp14  routed    up       up     N/A         N/A
Ethernet120  1544,1545,1546,1547,1548,1549,1550,1551     400G   9100    N/A    etp15  routed    up       up     N/A         N/A
Ethernet128  1296,1297,1298,1299,1300,1301,1302,1303     400G   9100    N/A    etp16  routed    up       up     N/A         N/A
Ethernet136  1288,1289,1290,1291,1292,1293,1294,1295     400G   9100    N/A    etp17  routed    up       up     N/A         N/A
Ethernet144  1280,1281,1282,1283,1284,1285,1286,1287     400G   9100    N/A    etp18  routed    up       up     N/A         N/A
Ethernet152  1032,1033,1034,1035,1036,1037,1038,1039     400G   9100    N/A    etp19  routed    up       up     N/A         N/A
Ethernet160          264,265,266,267,268,269,270,271     400G   9100    N/A    etp20  routed    up       up     N/A         N/A
Ethernet168          272,273,274,275,276,277,278,279     400G   9100    N/A    etp21  routed    up       up     N/A         N/A
Ethernet176                  16,17,18,19,20,21,22,23     400G   9100    N/A    etp22  routed    up       up     N/A         N/A
Ethernet184                          0,1,2,3,4,5,6,7     400G   9100    N/A    etp23  routed    up       up     N/A         N/A
Ethernet192          256,257,258,259,260,261,262,263     400G   9100    N/A    etp24  routed    up       up     N/A         N/A
Ethernet200                    8,9,10,11,12,13,14,15     400G   9100    N/A    etp25  routed    up       up     N/A         N/A
Ethernet208  1024,1025,1026,1027,1028,1029,1030,1031     400G   9100    N/A    etp26  routed    up       up     N/A         N/A
Ethernet216          768,769,770,771,772,773,774,775     400G   9100    N/A    etp27  routed    up       up     N/A         N/A
Ethernet224          520,521,522,523,524,525,526,527     400G   9100    N/A    etp28  routed    up       up     N/A         N/A
Ethernet232          776,777,778,779,780,781,782,783     400G   9100    N/A    etp29  routed    up       up     N/A         N/A
Ethernet240          512,513,514,515,516,517,518,519     400G   9100    N/A    etp30  routed    up       up     N/A         N/A
Ethernet248          528,529,530,531,532,533,534,535     400G   9100    N/A    etp31  routed    up       up     N/A         N/A
  • View the platform specific information using the show platform commands.
admin@sonic:~$ show platform -h
Usage: show platform [OPTIONS] COMMAND [ARGS]...

  Show platform-specific hardware info

Options:
  -h, -?, --help  Show this message and exit.

Commands:![image](https://wwwin-github.cisco.com/storage/user/17458/files/f6029e2d-d8eb-4342-9296-bc76e9fbb3dc)

  current      Show device current information
  eth-switch   Show ethernet switch information
  fabric       Show platform fabric
  fan          Show fan status information
  firmware     Show firmware information
  idprom       Show Platform Idprom Inventory
  inventory    Show Platform inventory
  npu          Show NPU
  obfl         Show Platform obfl logging
  pcieinfo     Show Device PCIe Info
  psustatus    Show PSU status information
  rdma-config  Show Platform RDMA config
  ssdhealth    Show SSD Health information
  summary      Show hardware platform information
  syseeprom    Show system EEPROM information
  temperature  Show device temperature information
  versions
  voltage      Show device voltage information
  • View the fan status using the show platform fan command:
admin@sonic:~$ show platform fan
  Drawer    LED            FAN    Speed    Direction    Presence    Status          Timestamp
--------  -----  -------------  -------  -----------  ----------  --------  -----------------
     N/A    N/A      PSU0.fan0      50%          N/A     Present        OK  20241210 03:00:33
     N/A    N/A      PSU1.fan0      50%          N/A     Present        OK  20241210 03:00:33
fantray0  green  fantray0.fan0      26%       intake     Present        OK  20241210 03:00:31
fantray0  green  fantray0.fan1      28%       intake     Present        OK  20241210 03:00:31
fantray1  green  fantray1.fan0      26%       intake     Present        OK  20241210 03:00:31
fantray1  green  fantray1.fan1      27%       intake     Present        OK  20241210 03:00:31
fantray2  green  fantray2.fan0      26%       intake     Present        OK  20241210 03:00:32
fantray2  green  fantray2.fan1      27%       intake     Present        OK  20241210 03:00:32
fantray3  green  fantray3.fan0      25%       intake     Present        OK  20241210 03:00:32
fantray3  green  fantray3.fan1      27%       intake     Present        OK  20241210 03:00:32
fantray4  green  fantray4.fan0      26%       intake     Present        OK  20241210 03:00:32
fantray4  green  fantray4.fan1      27%       intake     Present        OK  20241210 03:00:32
fantray5  green  fantray5.fan0      25%       intake     Present        OK  20241210 03:00:32
fantray5  green  fantray5.fan1      28%       intake     Present        OK  20241210 03:00:32
  • View the PSU status using the show platform psustatus command:
admin@sonic:~$ show platform psustatus
PSU    Model          Serial         HW Rev  Voltage (V)    Current (A)    Power (W)    Status    LED
-----  -------------  -----------  --------  -------------  -------------  -----------  --------  -----
PSU 1  PSU1.4KW-ACPI  XXXXXXXXXXX      0.00  N/A            N/A            N/A          NOT OK    amber
PSU 2  PSU1.4KW-ACPI  XXXXXXXXXXX      0.00  12.001         23.0           275.5        OK        green
  • Additionally, while the SONiC startup configuration can be accessed through /etc/config_db.json, the simplest way to get the running configuration is through the CLI with the show runningconfiguration command. You can choose to view the entire configuration or a specific subsection, as shown in this example.
admin@sonic:~$ show runningconfiguration -h
Usage: show runningconfiguration [OPTIONS] COMMAND [ARGS]...

  Show current running configuration information

Options:
  -?, -h, --help  Show this message and exit.

Commands:
  acl         Show acl running configuration
  all         Show full running configuration
  bgp         Show BGP running configuration Note: multi-asic can run 'show...
  interfaces  Show interfaces running configuration
  ntp         Show NTP running configuration
  ports       Show ports running configuration
  snmp        Show SNMP running configuration
  syslog      Show Syslog running configuration

JSON files

Configuration can also be applied using JSON files. You can specify configuration items as per SONiC JSON configuration schema in a json file and apply it. You can apply these configurations in two ways:

Apply JSONs using config load or config reload

  • You can apply JSON configuration using the config load command. This command attempts to add to the running configuration or modify the parameters in the running configuration. This command cannot remove existing configuration and can only be used to add or modify the configuration. It can be used in two ways:
config load <target_config.json>

In this case the contents of target_config.json will be added to the running configuration.

config load

In this case, the contents of /etc/sonic/config_db.json will be added to the running configuration.

For example:

admin@sonic:~$ vim ip_config.json
admin@sonic:~$ cat ip_config.json
{

     "INTERFACE": {
        "Ethernet0": {},
        "Ethernet0|192.1.2.2/30": {},
        "Ethernet8": {},
        "Ethernet8|192.1.2.6/30": {},
        "Ethernet16": {},
        "Ethernet16|192.1.2.10/30": {},
        "Ethernet24": {},
        "Ethernet24|192.1.2.14/30": {}
    },
    "MGMT_INTERFACE": {
        "eth0|192.168.1.2/16": {
            "gwaddr": "192.168.0.1"
        }
    }
}
admin@sonic:~$ sudo config load
Load config from the default config file(s) ? [y/N]: y
Running command: /usr/local/bin/sonic-cfggen -j /etc/sonic/config_db.json --write-to-db
admin@sonic:~$ show ip interfaces
Interface    Master    IPv4 address/mask    Admin/Oper    BGP Neighbor    Neighbor IP
-----------  --------  -------------------  ------------  --------------  -------------
Ethernet0              192.1.2.2/30         up/down       N/A             N/A
Ethernet8              192.1.2.6/30         up/down       N/A             N/A
Ethernet16             192.1.2.10/30        up/down       N/A             N/A
Ethernet24             192.1.2.14/30        up/down       N/A             N/A
docker0                240.127.1.1/24       up/down       N/A             N/A
eth0                   192.168.1.2/16       up/up         N/A             N/A
lo                     127.0.0.1/16         up/up         N/A             N/A
admin@sonic:~$
  • Alternatively, you can use the config reload command. This command clears all the contents of the redis ConfigDB and loads the contents of specified json file into the redis ConfigDB. This command can be used in two ways as well:

It can be used in two ways:

  • In this first method the content of target_config.json will replace the running configuration.
admin@sonic:~$ config reload <target_config.json>
  • In the second method, the contents of /etc/sonic/config_db.json will replace the running configuration.
admin@sonic:~$ config reload

sonic-cfggen

The sonic-cfggen is a utility to read SONiC config from various input types and then write the config to the config database in Redis, print as a JSON or render a jinja2 config template.

To configure the device, sonic-cfggen can be used to make changes directly to the running configuration. sonic-cfggen validates adherence to the standard json schema but does not validate configDB parameters.

For example, the following workflow sets the IP addresses of several interfaces at once defined in the ip_config.json file:

root@R1:/home/cisco# cat ip_config.json
{

     "INTERFACE": {
        "Ethernet0": {},
        "Ethernet0|192.1.2.2/30": {},
        "Ethernet8": {},
        "Ethernet8|192.1.2.6/30": {},
        "Ethernet16": {},
        "Ethernet16|192.1.2.10/30": {},
        "Ethernet24": {},
        "Ethernet24|192.1.2.14/30": {}
    },
    "MGMT_INTERFACE": {
        "eth0|192.168.1.2/16": {
            "gwaddr": "192.168.0.1"
        }
    }
}
root@R1:/home/cisco# sonic-cfggen -j ip_config.json --write-to-db

To verify that our changes were successfully applied:

root@R1:/home/cisco# show ip interfaces
Interface    Master    IPv4 address/mask    Admin/Oper    BGP Neighbor    Neighbor IP
-----------  --------  -------------------  ------------  --------------  -------------
Ethernet0              192.1.2.2/30         up/down       N/A             N/A
Ethernet8              192.1.2.6/30         up/down       N/A             N/A
Ethernet16             192.1.2.10/30        up/down       N/A             N/A
Ethernet24             192.1.2.14/30        up/down       N/A             N/A
docker0                240.127.1.1/24       up/down       N/A             N/A
eth0                   192.168.1.2/16       up/up         N/A             N/A
lo                     127.0.0.1/16         up/up         N/A             N/A
root@R1:/home/cisco#

To save our changes to the /etc/sonic/config_db.json file (to persist changes across reboots)

config save -y

vty shell in FRR

SONiC uses FRR as for it's routing stack. FRR runs as a docker container on SONiC and has an interactive shell that can be used to configure routing parameters. This interactive shell is a vty shell and it functions as FRR's command line interface (CLI).

Execute the command to drop into the vty shell.

vtysh

For example:

admin@sonic:~$ vtysh

Hello, this is FRRouting (version 8.5.1).
Copyright 1996-2005 Kunihiro Ishiguro, et al.

sonic#

From this vty shell, you can execute commands, configure routing protocols as well and get operational data about the routing state.

For example, to configure a BGP Autonomous System and a neighbor:

root@sonic:/home/admin# vtysh

Hello, this is FRRouting (version 8.5.1).
Copyright 1996-2005 Kunihiro Ishiguro, et al.

sonic# configure
sonic(config)# router bgp 65000
sonic(config-router)# neighbor 10.10.10.1 remote-as 65000
sonic(config-router)#

And to view BGP summary from the vty shell:

root@sonic:/home/admin# vtysh

Hello, this is FRRouting (version 8.5.1).
Copyright 1996-2005 Kunihiro Ishiguro, et al.

sonic# show bgp summary

IPv4 Unicast Summary (VRF default):
BGP router identifier 1.1.1.1, local AS number 65000 vrf-id 0
BGP table version 0
RIB entries 0, using 0 bytes of memory
Peers 1, using 725 KiB of memory

Neighbor        V         AS   MsgRcvd   MsgSent   TblVer  InQ OutQ  Up/Down State/PfxRcd   PfxSnt Desc
10.10.10.1      4      65000         0         0        0    0    0    never      Connect        0 N/A

Total number of neighbors 1
sonic#