The CLI is an interface for configuring, monitoring, and maintaining the SR Linux. This chapter describes basic features of the CLI and how to use them.
After the SR Linux device is initialized, you can access the CLI using a console or SSH connection. See the SR Linux hardware documentation for information about establishing a console connection and enabling and connecting to an SSH server.
Use the following command to connect to the SR Linux and open the CLI using SSH:
ssh admin@<IP Address>
Example:
The CLI help functions (? and help) can assist in understanding command usage and indicate which configuration mode you are in.
Enter a question mark (?) after a command to display the command usage. For example, entering a question mark after the command network-instance, shows its usage.
Example:
Enter help at the top level to show the current configuration mode and details on other configuration modes. For more information about configurations, see Configuration modes.
Example:
To reduce keystrokes or aid in remembering a command name, use the CLI auto-complete function.
Enter a tab at any mode or level to auto-complete the next command level. If multiple options are available, a popup will appear.
Use shortcuts to move the cursor on the command line, complete commands, and recall commands previously entered. Shortcuts can also make syntax correction easier. Table 3 lists common shortcuts.
Task | Keystroke |
Move cursor to the beginning of the line | Ctrl+A |
Move cursor to the end of the line | Ctrl+E |
Move cursor one character to the right | Ctrl+F or Right arrow key |
Move cursor one character to the left | Ctrl+B or Left arrow key |
Move cursor forward one word | Esc F |
Move cursor back one word | Esc B |
Transpose the character to the left of the cursor with the character the cursor is placed on | Ctrl+T |
Complete a partial command | Enter the first few letters, then press the Tab key |
Recall previous entry in the buffer | Page up key |
Navigate one level up within a context. For example: --{running}--[interface ethernet-1/1 subinterface 1]-- # exit --{running}--[interface ethernet-1/1]-- | Type: exit |
Return to the root context. For example: --{running}--[interface ethernet-1/1 subinterface 1]-- # exit all --{running}--[ ]-- | Type: exit all |
Close the CLI using one of the following methods:
Configuration modes define how the system is running when transactions are performed. Supported modes are the following:
You can modify the candidate configuration in different modes:
When entering candidate mode, if you specify the exclusive keyword, it locks out other users from making changes to the candidate configuration.
You can enter candidate exclusive mode only under the following conditions:
By default, the candidate configuration is in shared mode. This allows multiple users to modify the candidate configuration concurrently. When the configuration is committed, the changes from all of the users are applied.
A default candidate is defined per user (see Name mode).
Use caution when allowing multiple users access to the candidate configuration at the same time. If one user commits the configuration, that commits the changes made by any other users who have modified the current candidate configuration.
A private candidate allows multiple users to modify a configuration; however when a user commits their changes, only the changes from that user are committed. When a private candidate is created, private datastores are created and a snapshot is taken from the running database to create a baseline.
When starting a private candidate, a default candidate is defined per user with the name ‘private-<username>’ unless a unique name is defined (see Name mode).
Candidate types support an optional name. This allows multiple users to share environments.
When a candidate is created with a name specified, a new entry is created in the /system/configuration/candidate[] list. Other users can enter the same candidate (if the candidate type is shared) using this name.
if no name is specified, then the name ‘default’ is used. This means the global shared candidate can be accessed by entering enter candidate name default or just enter candidate, For private candidates the name ‘default’ is not used (since private candidates share a list with shared candidates). Instead, private candidates are created with the name "private-<username>".
Named candidates are automatically deleted when there are no active sessions present and they are empty, or after 7 days of no session activity. This 7-day default is configurable in the /system/configuration/idle-timeout field.
After logging in to the CLI, you are initially placed in running mode. Table 4 describes the commands to change between modes.
To enter this mode: | Type this command: |
Candidate shared | enter candidate |
Candidate mode for named shared candidate | enter candidate name <name> |
Candidate private | enter candidate private |
Candidate mode for named private candidate | enter candidate private name <name> |
Candidate exclusive | enter candidate exclusive |
Exclusive mode for named candidate | enter candidate exclusive name <name> |
Running | enter running |
State | enter state |
Show | enter show |
For example, to change from running to a shared candidate mode (using the default)’:
The asterisk (*) next to the mode name indicates that the candidate configuration has changes that have not yet been committed.
To switch between candidate shared and candidate exclusive modes, you must first switch to a different configuration mode (for example, running mode) before entering candidate shared or exclusive mode. For example:
To enter candidate mode for a named configuration candidate, you specify the name of the configuration candidate. For example:
When a user enters candidate mode, the system creates two copies of the running datastore: one is modifiable by the user, and the other serves as a baseline. The modifiable datastore and the baseline datastore are collectively known as a configuration candidate.
The baseline command can assist in managing conflicts and uses the following arguments:
Changes made during a configuration modification session do not take effect until a commit command is issued. Use the commit command in candidate mode only.
Option | Action | Permitted additional arguments |
commit now | Apply the changes, exit candidate mode, and enter running mode. | NA |
commit stay | Apply the changes and then remain in candidate mode. | commit stay [save] [comment] [confirmed] |
commit save | Apply the changes and automatically save the commit to the startup configuration. Can be used other arguments except now (e.g., commit stay save). | commit [stay] [checkpoint] save [confirmed] [comment] |
commit checkpoint | Apply the changes and cause an automatic checkpoint after the commit succeeds. | commit [stay] [now] checkpoint [save] [confirmed] |
commit validate | Verify that a propose configuration change passes a management server validation. | NA |
commit comment <comment> | Use with other keywords (except validate) to add a user comment (e.g. commit stay comment <comment> where <comment> is a quoted string, 1-255 characters. | commit [stay] [save] [checkpoint] [confirmed] comment |
commit confirmed
commit confirmed [timeout] commit confirmed [accept | reject] | Apply the changes, but requires an explicit confirmation to become permanent. If the explicit confirmation is not issued within a specified time period, all changes are automatically reverted. The timeout period default is 600 seconds (10 mins.), or can be provisioned with a value of 1-86400 sec.). The timeout parameter cannot be used with the accept or reject parameter. Prior to the timer expiring, the accept parameter explicitly confirms and applies the changes. With no timer running, the reject parameter explicitly rejects the changes. | commit [checkpoint] [save] [stay] [comment] confirmed |
Example:
This example shows the commit stay option:
Example:
This example shows the commit confirmed option with a custom timeout followed by an accept action.
Use the delete command to delete configurations while in candidate mode.
Example:
The following example displays the system banner configuration, deletes the configured banner, then displays the resulting system banner configuration:
To aid in reading a configuration, you can add comments or descriptive annotations. The annotations are indicated by !!! in displayed output.
You can enter a comment either directly from the command line or by navigating to a CLI context and entering the comment in annotate mode.
Examples:
The following example adds a comment to an ACL configuration. If there is already a comment in the configuration, the new comment is appended to the existing comment.
To replace the existing comment, use !!! instead of !! in the command.
The following example adds the same comment to the ACL by navigating to the context for the ACL and entering the comment in annotate mode:
You can enter multiple lines in annotate mode. To exit annotate mode, press Esc, then the Enter key.
In CLI output, the comment is displayed in the context it was entered. For example:
To remove a comment, enter annotate mode for the context and press Esc then Enter without entering any text.
You can discard previously applied configurations with the discard command. Use the discard command in candidate mode only.
Example:
The common administrative CLI commands in this section can help you understand a current configuration and perform routine configuration tasks.
Use the ping (IPv4) or ping6 (IPv6) command to contact an IP address. Use this command in any mode.
Example:
To display the path a packet takes to a destination, use the traceroute (IPv4) or traceroute6 (IPv6) command.
Example:
To trace the route using TCP SYN packets rather than UDP or ICMP echo packets, use the tcptraceroute command.
From within the CLI, use the bash command to enter the bash shell. Use this command in any mode. To exit the bash shell and return to the CLI, enter exit.
Example:
You can use the bash command to enter Linux commands directly from the SR Linux CLI prompt. For example:
To set a command to execute periodically, use the watch command. The watch command can be used with any valid command based on the current context. Output redirection is supported.
When used with a CLI command, the first page of output displays. The command will re-execute every 2 seconds, or you can optionally provision the interval with a value between 1 - 3600 seconds. The command also p”rovides an option to highlight the differences that occur between each commands execution.
To exit the watch command, enter Ctrl-C.
Examples:
To execute the command show system sflow status every 4 seconds, enter the following command. The command must be surrounded by double quotes.
Note in the upper right of the message is an indication of how many times the command has executed.
The info command to display the configuration. Entering the info command from the root context displays the entire configuration, or the configuration for a specified context. Entering the command from within a context limits the display to the configuration under that context. Use this command in candidate or running mode.
Examples:
To display the entire configuration, enter info from the root context:
To display the configuration for a specific context, enter info and specify the context:
From a context, use the info command to display the configuration under that context:
Use the as-json option to display JSON-formatted output:
Use the detail option to display values for all parameters, including those not specifically configured:
Use the flat option to display the output as a series of set statements, omitting indentation for any sub-contexts:
Use the depth option to display parameters with a specified number of sub-context levels:
Use the tree command to display the tree hierarchy for all available nodes you can enter. Entering the tree command from the root context displays the entire tree hierarchy. Entering the command from a context limits the display to the nodes under that context.Use this command in candidate or running mode.
To display the state of the configuration, enter the info from state command in candidate or running mode, or the info command in state mode.
Examples:
To display state information for a specified context from modes that are not state mode:
To display state information for a specified context from state mode:
You can execute configuration statements from a source file consisting of set statements such as those generated by the info flat command (see Displaying configuration details). The SR Linux reads the file and executes each configuration statement line-by-line. You can optionally commit the configuration automatically after the file is read.
Example:
The following example executes a configuration from a specified file:
Use the auto-commit option to commit the configuration after the commands in the source file are executed.
Collect technical support data using the tech-support command. Use this command in any configuration mode.
Example:
You can access the saved file from the bash shell. For example:
You can display output from SR Linux CLI commands in text, JSON, or table format, and you can filter the output using Linux tools such as grep. You can direct filtered output to a specified file in a specified format.
You can display output from SR Linux CLI commands as lines of text, in JSON format, or in a table. By default, output is displayed as lines of text, but you can configure output to be displayed in JSON format by default. See Configuring the CLI output format.
Examples:
The following example displays the output of the show version command as lines of text:
The following example displays the output of the show version command in JSON format:
The following example displays the output of the show version command as a table:
Output from SR Linux CLI commands can be piped to standard Linux tools, including grep, more, head, and tail.
Examples:
The following example pipes the output of the show interface command to grep so that only lines with mgmt0 appear in the output:
The following example pipes the output of the show interface command to more to display one page of output at a time:
The following example pipes the output of the show interface command to head to display only the first 8 lines:
You can direct the output of SR Linux CLI commands to a specified file. The output can be saved as text, in table format, or in JSON format.
Example:
The following example directs the output of the show interface command to a file. The output is saved in JSON format.
Use > to create a new file with the specified filename; if the file already exists, it is replaced. Use >> to append the output to the specified file if it exists.
You can access the file using bash mode. For example:
You can optionally configure the SR Linux CLI environment to change settings such as the command prompt, contents of the bottom toolbar, and the default format for displayed output. You can create aliases for CLI commands. The CLI environment settings can be saved to the default SR Linux configuration or to a specified file and subsequently loaded and applied to the current CLI session.
By default, the SR Linux CLI prompt consists of two lines of text, indicating with an asterisk whether the configuration has been modified, the current mode and session type, the current CLI context, and the host name of the SR Linux device, in the following format:
For example:
You can configure the SR Linux prompt to include information such as the user name or session ID of the CLI session, the number of changes made to the configuration, and the current local time.
Example:
The following example adds the local time and session user name to the SR Linux CLI prompt.
In the example, the local time is configured with the {time} keyword, and the session user name is configured with the {user} keyword. The line break is configured with \n. Use the environment prompt ? command to display the keywords that you can configure in the SR Linux CLI prompt.
After you enter this command, the CLI prompt looks like the following:
By default, the text that appears at the bottom of the terminal window in SR Linux CLI sessions displays the current mode and session type, whether the configuration has been modified, the user name and session ID of the current AAA session, and the local time, in the following format:
For example:
You can configure the bottom toolbar to include information such as the number of changes made to the configuration and the host name.
Example:
The following example adds the number of changes made to the configuration and the host name to the bottom toolbar.
In the example, the number of configuration changes is configured with the {modified_with_change_count} keyword, and the host name is configured with the {host} keyword. Use the environment bottom-toolbar ? command to display the keywords that you can configure in the bottom toolbar.
After you enter this command, the bottom toolbar looks like the following:
The SR Linux features two versions of the CLI engine: advanced and basic. The advanced CLI engine is enabled by default; it includes the following features:
The basic CLI engine includes a limited set of features compared to the advanced version:
If necessary, you can configure the SR Linux to use the basic CLI engine instead of the advanced CLI engine for CLI sessions.
Example:
The following example configures the SR Linux to use the basic CLI engine for CLI sessions:
You can configure the output of CLI commands to be displayed as either text or in JSON format.
Example:
The following example configures CLI command output to be displayed in JSON format.
Subsequent command output is displayed in JSON format by default. For example:
As a shortcut for entering commands in the CLI, you can configure CLI command aliases. The alias can include one or more CLI command keywords and arguments.
Example:
The following example configures the alias display interface for the SR Linux command info interface <name> subinterface <index> | as table:
In the example, the display interface alias consists of the keywords info interface, arguments to specify an interface name and subinterface number, and keywords to display the output as a table. The alias name and aliased command are each enclosed in quotes. The arguments are enclosed in braces ({ }). The argument {} creates an optional unnamed variable for the interface name, and the argument {subinterface} creates an optional parameter named subinterface.
When you enter the alias at the CLI prompt, the output of the aliased command is displayed. For example:
If you omit the optional parameters for the interface and subinterface names, they are treated as wildcards. For example:
By default, if you enter a tab at any mode or level to auto-complete the next command level, a popup appears that displays the available options for that command. See Using the CLI auto-complete function.
You can optionally configure the space bar to provide the same function as the Tab key, so that pressing the space bar auto-completes the command.
Example:
The following example configures the space bar to auto-complete commands in SR Linux CLI sessions:
To display the CLI environment configuration, including any CLI command aliases, use the environment show command.
Example:
You can save the current CLI environment settings to the default SR Linux configuration or to a file, and you can load CLI environment settings from the default SR Linux configuration or from a file.
Examples:
The following example saves the current CLI environment settings to the default SR Linux configuration:
The following example saves the current CLI environment settings to a file:
The following example loads CLI environment settings from the default SR Linux configuration:
The following example loads CLI environment settings from a file: