Nokia SR Linux: CLI Basics and gNMI Configuration - 夜莺博客

Nokia SR Linux: CLI Basics and gNMI Configuration

Nokia SR Linux is different from a classic router OS in one important way: the CLI is a thin client over a model-driven configuration store, and everything the CLI does can be done over gNMI with the same YANG paths. Engineers moving from IOS or Junos usually lose time on three things - finding where a command lives in the hierarchy, understanding that changes are staged in a candidate datastore until committed, and discovering that the flat set / syntax is often faster than the nested tree. This article covers that workflow end to end.

The SR Linux CLI Model

The hierarchy is context-based. From the top level you enter a context, and the prompt shows where you are:

--{ running }--[  ]--
A:srl1# enter candidate
--{ candidate }--[  ]--
A:srl1# set / interface ethernet-1/1 admin-state enable
A:srl1# set / interface ethernet-1/1 subinterface 0 ipv4 admin-state enable
A:srl1# set / interface ethernet-1/1 subinterface 0 ipv4 address 10.1.1.1/30
A:srl1# info
A:srl1# commit now

Key points: enter candidate copies the running config into a private candidate; diff shows what would change; info prints the candidate; commit now applies. discard throws the candidate away, which makes the CLI safe for exploratory work without any session timeout games.

Network Instances, Interfaces and Routing

A:srl1# set / network-instance default interface ethernet-1/1.0
A:srl1# set / network-instance default protocols bgp admin-state enable
A:srl1# set / network-instance default protocols bgp autonomous-system 65001
A:srl1# set / network-instance default protocols bgp router-id 10.0.0.1
A:srl1# set / network-instance default protocols bgp group ibgp peer-as 65001
A:srl1# set / network-instance default protocols bgp neighbor 10.0.0.2 peer-group ibgp
A:srl1# commit now

The CLI is tab-completion driven - the tree command shows the children of the current context, which is faster than guessing YANG paths. Use info flat to export the whole configuration as a reproducible set script, and store that script as your startup configuration file.

Show Commands and State

A:srl1# show version
A:srl1# show interface ethernet-1/1
A:srl1# show network-instance default protocols bgp neighbor
A:srl1# show network-instance default route-table ipv4-unicast summary
A:srl1# tools netstat -rn

SR Linux separates configuration from state: show reads state, info reads configuration. Any state path can also be streamed over gNMI, which is the point of the next section.

Enabling gNMI

A:srl1# enter candidate
A:srl1# set / system grpc-server mgmt admin-state enable
A:srl1# set / system grpc-server mgmt network-instance mgmt
A:srl1# set / system grpc-server mgmt port 57400
A:srl1# set / system grpc-server mgmt tls-profile my-profile
A:srl1# set / system tls server-profile my-profile key /etc/opt/srlinux/certs/server.key
A:srl1# set / system tls server-profile my-profile certificate /etc/opt/srlinux/certs/server.crt
A:srl1# commit now

With the server up, any gNMI client reads or writes the same datastore the CLI uses:

gnmic -a 10.0.0.1:57400 --skip-verify -u admin -p admin \
  -e json_ietf get --path /system/name/host-name
gnmic -a 10.0.0.1:57400 --skip-verify -u admin -p admin \
  set --update-path /interface ethernet-1/2/admin-state --update-value enable

Because paths are model paths, the same subscription can feed a streaming telemetry collector with no screen scraping. For the collector side, compare dial-in and dial-out designs in gNMI streaming telemetry: dial-in vs dial-out, and for SR OS (the classic Nokia OS) see Nokia SR OS IS-IS configuration.

Practical Habits That Save Time

  • Always enter candidate before editing; never work in running context.
  • Use diff and info flat before commit now - both are free.
  • Export config as flat CLI text and keep it in git; it is the cleanest backup format on SR Linux.
  • Use commit save semantics by writing to startup with save startup after committing.

原文链接:https://documentation.nokia.com/srlinux/23-10/books/config-basics/management-servers.html