Configuring SONiC using CLI or editing JSON

You configure SONiC in one of three ways:

  • Using the SONiC CLI. SONiC includes a broad range of config commands that configure most of the features in the operating system. The CLI commands are applied to a running configuration that does not persist if the switch reboots unless you save the configuration with config save. The Azure GitHub documentation contains a command reference, and you can also run config ? to list all the configuration commands available:
    admin@sonic:~$ sudo config ?
    Usage: config [OPTIONS] COMMAND [ARGS]...
    SONiC command line - 'config' command
     -?, -h, --help  Show this message and exit.
     aaa                    AAA command line
     acl                    ACL-related configuration tasks
     bgp                    BGP-related configuration tasks
     buffer                 Configure buffer_profile
     chassis-modules        Configure chassis-modules options
     console                Console-related configuration tasks
     dropcounters           Drop counter related configuration tasks
  • Editing the SONiC CONFIG_DB JSON configuration file /etc/sonic/config_db.json directly. To apply your changes, reload the configuration with config reload.
  • Create a test JSON configuration file and apply it using the sonic-cfggen command. To apply your changes, reload the configuration with config reload.
    admin@sonic:~$ sonic-cfggen -j test_config.json --write-to-db

The wrong JSON format in /etc/sonic/config_db.json may cause the system to fail until the error is fixed.

Show the Running Configuration

A running configuration is a combination of the startup configuration that loads when you boot the switch, plus any updates that are made to the configuration that are not committed to CONFIG_DB (that is, they’re not saved to the configuration with config save).

The show runningconfiguration all command shows the current running state of the /etc/sonic/config_db.json file.

admin@nba715:~$ show runningconfiguration
Usage: show runningconfiguration [OPTIONS] COMMAND [ARGS]...
 Show current running configuration information
 -h, -?, --help  Show this message and exit.
 acl         Show acl running configuration
 all         Show full running configuration
 bgp         Show BGP running configuration
 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

You can filter the configuration to only show the running configuration for ACLs, BGP, interfaces, NTP, ports, SNMP, or syslog.

admin@nba715:~$ show runningconfiguration bgp
Building configuration...
Current configuration:
frr version 7.5.1-sonic
frr defaults traditional
hostname nba715
no service integrated-vtysh-config
route-map RM_SET_SRC permit 10
 set src
ip protocol bgp route-map RM_SET_SRC
line vty

Latest news