Getting Started: A Quick Tour of the CLI
The following topics can help you get started with the Junos OS CLI to perform configuration changes, switch between operational mode and configuration mode, create a user account, and execute some of the basic commands.
If you need a basic introduction to Junos OS, see the Getting Started Guide for Junos OS. For more in-depth information, as well as to learn how to use Junos OS with Juniper Networks devices, see the Overview for Junos OS. This Junos OS CLI Guide generally assumes you are at least familiar with the content in the other two guides, as well as Junos OS concepts and operation principles in general.
Getting Started with the Junos OS Command-Line Interface
This topic shows you how to start the Junos OS CLI, view the command hierarchy, and make small configuration changes. The related topics listed at the end of this topic provide more detailed information about using the CLI.
Before you begin, make sure your device hardware is set up and Junos OS is installed. You must have a direct console connection to the device or network access using SSH or Telnet. If your device is not set up, follow the installation instructions provided with the device before proceeding.
To log in to a device and start the CLI:
- Log in as root.
The root login account has superuser privileges, with access to all commands and statements.
- Start the CLI:root# cliroot@>
The > command prompt shows you are in operational mode. Later, when you enter configuration mode, the prompt will change to #.
If you are using the root account for the first time on the device, remember that the device ships with no password required for root, but the first time you commit a configuration, you must set a root password. Root access is not allowed over a telnet session. To enable root access over an SSH connection, you must configure the system services ssh root-login allow statement.
The CLI includes several ways to get help about commands. This section demonstrates some examples showing how to get help:
- Type ? to show the top-level commands available
in operational mode.
root@> ?
Possible completions: clear Clear information in the system configure Manipulate software configuration information diagnose Invoke diagnose script file Perform file operations help Provide help information monitor Show real-time debugging information mtrace Trace multicast path from source to receiver ping Ping remote target quit Exit the management session request Make system-level requests restart Restart software process set Set CLI properties, date/time, craft interface message show Show system information ssh Start secure shell on another host start Start shell telnet Telnet to another host test Perform diagnostic debugging traceroute Trace route to remote host
- Type file ? to show all possible completions
for the file command.
root@> file ?
Possible completions: <[Enter]> Execute this command archive Archives files from the system checksum Calculate file checksum compare Compare files copy Copy files (local or remote) delete Delete files from the system list List file information rename Rename files show Show file contents source-address Local address to use in originating the connection | Pipe through a command
- Type file archive ? to show all possible completions
for the file archive command.
root@> file archive ?
Possible completions: compress Compresses the archived file using GNU gzip (.tgz) destination Name of created archive (URL, local, remote, or floppy) source Path of directory to archive
See also
Switching Between Junos OS CLI Operational and Configuration Modes
When you monitor and configure a device running Junos OS, you may need to switch between operational mode and configuration mode. When you change to configuration mode, the command prompt also changes. The operational mode prompt is a right -angle bracket (>) and the configuration mode prompt is a pound or hash sign (#).
To switch between operational mode and configuration mode:
- When you log in to the device and type the cli command, you are automatically in operational mode:
--- JUNOS 17.2B1.8 built 2018-05-09 23:41:29 UTC % cli user@host>
- To enter configuration mode, type the configure command or the edit command from the CLI operational
mode. The prompt in brackets ([edit]), also known as a banner, shows that you are in configuration edit mode
at the top of the hierarchy. For example:
user@host> configure Entering configuration mode [edit] user@host#
The CLI prompt changes from user@host> to user@host# and a banner appears to indicate the hierarchy level.
You can return to operational mode in one of the following ways:
To commit the configuration and exit:
[edit]user@host# commit and-quitcommit completeExiting configuration modeuser@host>To exit without committing:
[edit]user@host# exitExiting configuration modeuser@host>
- To display the output of an operational
mode command, such as show, while in configuration
mode, issue the run configuration mode command and then
specify the operational mode command:[edit]user@host# run operational-mode-command
For example, to display the currently set priority value of the Virtual Router Redundancy Protocol (VRRP) primary device while you are modifying the VRRP configuration for a backup device:
[edit interfaces xe-4/2/0 unit 0 family inet vrrp-group 27]user@host# showvirtual-address [ 192.168.1.15 ];[edit interfaces xe-4/2/0 unit 0 family inet vrrp-group 27]user@host# run show vrrp detailPhysical interface: xe-5/2/0, Unit: 0, Address: 192.168.29.10/24Interface state: up, Group: 10, State: backupPriority: 190, Advertisement interval: 3, Authentication type: simplePreempt: yes, VIP count: 1, VIP: 192.168.29.55Dead timer: 8.326, Master priority: 201, Master router: 192.168.29.254[edit interfaces xe-4/2/0 unit 0 family inet vrrp-group 27]user@host# set priority ...
See also
Using Keyboard Sequences to Move Around and Edit the Junos OS CLI
You can use keyboard sequences in the Junos OS command-line interface (CLI) to move around and edit the command line. You can also use keyboard sequences to scroll through a list of recently executed commands. The following table lists some of the CLI keyboard sequences. They are the same as those used in Emacs.
Table 1: CLI Keyboard Shortcuts
Keyboard sequence | Action |
---|---|
Ctrl+b | Move the cursor back one character. |
Esc+b or Alt+b | Move the cursor back one word. |
Ctrl+f | Move the cursor forward one character. |
Esc+f or Alt+f | Move the cursor forward one word. |
Ctrl+a | Move the cursor to the beginning of the command line. |
Ctrl+e | Move the cursor to the end of the command line. |
Ctrl+h, Delete, | Delete the character before the cursor. |
Ctrl+d | Delete the character at the cursor. |
Ctrl+k | Delete the all characters from the cursor to the end of the command line. |
Ctrl+u or Ctrl+x | Delete the all characters from the command line. |
Ctrl+w, Esc+Backspace, | Delete the word before the cursor. |
Esc+d or Alt+d | Delete the word after the cursor. |
Ctrl+y | Insert the most recently deleted text at the cursor. |
Ctrl+l | Redraw the current line. |
Ctrl+p | Scroll backward through the list of recently executed commands. |
Ctrl+n | Scroll forward through the list of recently executed commands. |
Ctrl+r | Search the CLI history incrementally in reverse order for lines matching the search string. |
Esc+/ or Alt+/ | Search the CLI history for words for which the current word is a prefix. |
Esc+. or Alt+ | Scroll backward through the list of recently entered words in a command line. |
Esc+number sequence | Specify the number of times to execute a keyboard sequence. |
See also
Configuring a User Account on a Device Running Junos OS
This topic describes how to log on to a device running Junos OS using a root account and configure a new user account. You can configure an account for your own use or create a test account.
To configure a new user account on the device:
- Log in as root and enter configuration mode:root@host> configure[edit]root@host#
The ([edit]) prompt banner shows that you are in configuration edit mode at the top of the hierarchy.
- Change to the [edit system login] section of
the configuration:[edit]root@host# edit system login[edit system login]root@host#
The prompt in brackets changes to [edit system login] to show that you are at a new level in the hierarchy.
- Now add a new user account:[edit system login]root@host# edit user nchen
This example adds an account nchen (for Nathan Chen).
Note In Junos OS Release 12.2 and later, user account names can contain a period (.) in the name. For example, you can have a user account named nathan.chen. However, the username cannot begin or end with a period.
- Configure a full name for the account. If the name includes
spaces, enclose the entire name in quotation marks (" " ):[edit system login user nchen]root@host# set full-name "Nathan Chen"
- Configure an account class. The account class sets the
user access privileges for the account:[edit system login user nchen]root@host# set class super-user
- Configure an authentication method and password for the
account:[edit system login user nchen]root@host# set authentication plain-text-passwordNew password:Retype new password:
When the new password prompt appears, enter a clear-text password that the system can encrypt, and then confirm the new password.
- Commit the configuration:[edit system login user nchen]root@host# commitcommit complete
Configuration changes are not activated until you commit the configuration. If the commit is successful, a commit complete message appears.
- Return to the top level of the configuration, and then
exit:[edit system login user nchen]root@host# top[edit]root@host# exitExiting configuration mode
- Log out of the device:root@host> exit% logout Connection closed.
- To test your changes, log back in with the user account
and password you just configured:login: nchenPassword: password---JUNOS 17.2B1.8 built 2018-05-09 23:41:29 UTCnchen@host>
When you log in, you should see the new username at the command prompt.
You have successfully used the CLI to view the device status and perform a simple configuration change. See the related topics listed in this section for more information about the Junos OS CLI features.
For complete information about the commands to issue to configure your device, including examples, see the Junos OS configuration guides.
Using the CLI Editor in Configuration Mode
This topic describes some of the basic commands that you can use to enter configuration mode in the command-line interface (CLI) editor, navigate through the configuration hierarchy, get help, and commit or revert the changes that you make during the configuration session.
Task | Command/Statement | Example |
---|---|---|
Edit Your Configuration | ||
Enter configuration mode. When you start the CLI, the device is in operational mode. You must explicitly enter configuration mode. When you do, the CLI prompt changes from user@host> to user@host# and the hierarchy level appears in square brackets. | configure | user@host> configure [edit] user@host# |
Create a statement hierarchy. You can use the edit command to simultaneously create a hierarchy and move to that new level in the hierarchy. You cannot use the edit command to change the value of identifiers. | edit hierarchy-level value | [edit] user@host# edit security zones security-zone myzone [edit security zones security-zone myzone] user@host# |
Create a statement hierarchy and set identifier values. The set command is like edit except that your current level in the hierarchy does not change. | set hierarchy-level value | [edit] user@host# set security zones security-zone myzone [edit] user@host# |
Navigate the Hierarchy | ||
Navigate down to an existing hierarchy level. | edit hierarchy-level | [edit] user@host# edit security zones [edit security zones] user@host# |
Navigate up one level in the hierarchy. | up | [edit security zones] user@host# up [edit security] user@host# |
Navigate to the top of the hierarchy. | top | [edit security zones] user@host# top [edit] user@host# |
Commit or Revert Changes | ||
Commit your configuration. | commit | [edit] user@host# commit commit complete |
Roll back changes from the current session. Use the rollback command to revert all changes from the current configuration session. When you run the rollback command before exiting your session or committing changes, the software loads the most recently committed configuration onto the device. You must enter the rollback statement at the edit level in the hierarchy. | rollback | [edit] user@host# rollback load complete |
Exit Configuration Mode | ||
Commit the configuration and exit configuration mode. | commit and-quit | [edit] user@host# commit and-quit user@host> |
Exit configuration mode without committing your configuration. You must navigate to the top of the hierarchy using the up or top commands before you can exit configuration mode. | exit | [edit] user@host# exit The configuration has been changed but not committed Exit with uncommitted changes? [yes,no] (yes) |
Get Help | ||
Display a list of valid options for the current hierarchy level. | ? | [edit ] user@host# edit security zones ? Possible completions: <[Enter]> Execute this command > functional-zone Functional zone > security-zone Security zones | Pipe through a command [edit] |
See also
Checking the Status of a Device Running Junos OS
In operational mode, you can use show commands to check the status of the device and monitor the activities on the device.
To help you become familiar with show commands:
Type show ? to display the list of show commands you can use to monitor the router:
root@> show ?
Possible completions: accounting Show accounting profiles and records aps Show Automatic Protection Switching information arp Show system Address Resolution Protocol table entries as-path Show table of known autonomous system paths bfd Show Bidirectional Forwarding Detection information bgp Show Border Gateway Protocol information chassis Show chassis information class-of-service Show class-of-service (CoS) information cli Show command-line interface settings configuration Show current configuration connections Show circuit cross-connect connections dvmrp Show Distance Vector Multicast Routing Protocol info dynamic-tunnels Show dynamic tunnel information information esis Show end system-to-intermediate system information firewall Show firewall information helper Show port-forwarding helper information host Show hostname information from domain name server igmp Show Internet Group Management Protocol information ike Show Internet Key Exchange information ilmi Show interim local management interface information interfaces Show interface information ipsec Show IP Security information ipv6 Show IP version 6 information isis Show Intermediate System-to-Intermediate System info l2circuit Show Layer 2 circuit information l2vpn Show Layer 2 VPN information lacp Show Link Aggregation Control Protocol information ldp Show Label Distribution Protocol information link-management Show link management information llc2 Show LLC2 protocol related information log Show contents of log file mld Show multicast listener discovery information mpls Show Multiprotocol Label Switching information msdp Show Multicast Source Discovery Protocol information multicast Show multicast information ntp Show Network Time Protocol information ospf Show Open Shortest Path First information ospf3 Show Open Shortest Path First version 3 information passive-monitoring Show information about passive monitoring pfe Show Packet Forwarding Engine information pgm Show Pragmatic Generalized Multicast information pim Show Protocol Independent Multicast information policer Show interface policer counters and information policy Show policy information ppp Show PPP process information rip Show Routing Information Protocol information ripng Show Routing Information Protocol for IPv6 info route Show routing table information rsvp Show Resource Reservation Protocol information sap Show Session Announcement Protocol information security Show security information services Show services information snmp Show Simple Network Management Protocol information system Show system information task Show routing protocol per-task information ted Show Traffic Engineering Database information version Show software process revision levels vpls Show VPLS information vrrp Show Virtual Router Redundancy Protocol information
Use the show chassis routing-engine command to view the Routing Engine status:
root@> show chassis routing-engine
Routing Engine status: Slot 0: Current state Master Election priority Master (default) Temperature 31 degrees C / 87 degrees F CPU temperature 32 degrees C / 89 degrees F DRAM 768 MB Memory utilization 84 percent CPU utilization: User 0 percent Background 0 percent Kernel 1 percent Interrupt 0 percent Idle 99 percent Model RE-2.0 Serial ID b10000078c10d701 Start time 2005-12-28 13:52:00 PST Uptime 12 days, 3 hours, 44 minutes, 19 seconds Load averages: 1 minute 5 minute 15 minute 0.02 0.01 0.00
Use the show system storage command to view available storage on the device:
root@> show system storage
Filesystem Size Used Avail Capacity Mounted on /dev/ad0s1a 865M 127M 669M 16% / devfs 1.0K 1.0K 0B 100% /dev devfs 1.0K 1.0K 0B 100% /dev/ /dev/md0 30M 30M 0B 100% /packages/mnt/jbase /dev/md1 158M 158M 0B 100% /packages/mnt/jkernel-9.3B1.5 /dev/md2 16M 16M 0B 100% /packages/mnt/jpfe-M7i-9.3B1.5 /dev/md3 3.8M 3.8M 0B 100% /packages/mnt/jdocs-9.3B1.5 /dev/md4 44M 44M 0B 100% /packages/mnt/jroute-9.3B1.5 /dev/md5 12M 12M 0B 100% /packages/mnt/jcrypto-9.3B1.5 /dev/md6 25M 25M 0B 100% /packages/mnt/jpfe-common-9.3B1.5 /dev/md7 1.5G 196K 1.4G 0% /tmp /dev/md8 1.5G 910K 1.4G 0% /mfs /dev/ad0s1e 96M 38K 88M 0% /config procfs 4.0K 4.0K 0B 100% /proc /dev/ad1s1f 17G 2.6G 13G 17% /var
See also
Rolling Back Junos OS Configuration Changes
This topic shows how to use the rollback command to return your uncommitted but revised configuration to the state of the most recently committed Junos OS configuration. The rollback command is useful if you make configuration changes and then decide not to keep them.
The following procedure shows how to configure an SNMP health monitor on a device running Junos OS and then return to the most recently committed configuration that does not include the health monitor. When configured, the SNMP health monitor provides the network management system (NMS) with predefined monitoring for file system usage, CPU usage, and memory usage on the device.
Enter configuration mode:
user@host> configureentering configuration mode[edit]user@host#Show the current configuration (if any) for SNMP:
[edit]user@host# show snmpNo snmp statements appear because SNMP has not been configured on the device.
Configure the health monitor:
[edit]user@host# set snmp health-monitorShow the new configuration:
[edit]user@host# show snmphealth-monitor;The health-monitor statement indicates that SNMP health monitoring is configured on the device.
Enter the rollback configuration mode command to return to the most recently committed configuration:
[edit]user@host# rollbackload completeShow the configuration again to make sure your change is no longer present:
[edit]user@host# show snmpNo snmp configuration statements appear. The health monitor is no longer configured.
Enter the commit command to activate the configuration to which you rolled back:
[edit]user@host# commitExit configuration mode:
[edit]user@host# exitExiting configuration mode
You can also use the rollback command to return to earlier configurations.
Configuring a Routing Protocol
This topic provides a sample configuration that describes how to configure an OSPF backbone area that has two SONET interfaces.
The final configuration looks like this:
Shortcut
You can create a shortcut for this entire configuration with the following two commands:
Longer Configuration
This section provides a longer example of creating the previous OSPF configuration. In the process, it illustrates how to use the different features of the CLI.
- Enter configuration mode by issuing the configure command:user@host> configureentering configuration mode[edit]user@host#
Notice that the prompt has changed to a pound or hash sign (#) to indicate configuration mode.
- To create the above configuration, you start by editing
the protocols ospf statements:[edit]user@host# edit protocols ospf[edit protocols ospf]user@host#
- Now add the OSPF area:[edit protocols ospf]user@host# edit area 0.0.0.0[edit protocols ospf area 0.0.0.0]user@host#
- Add the first interface:[edit protocols ospf area 0.0.0.0]user@host# edit interface so0[edit protocols ospf area 0.0.0.0 interface so-0/0/0]user@host#
You now have four nested statements.
- Set the hello and dead intervals.
[edit protocols ospf area 0.0.0.0 interface so-0/0/0]
user@host# set hello-interval 5
user@host# set dead-interval 20
user@host#
- You can see what is configured at the current level with
the show command: [edit protocols ospf area 0.0.0.0 interface so-0/0/0]user@host# showhello-interval 5;dead-interval 20;[edit protocols ospf area 0.0.0.0 interface so-0/0/0]user@host#
- You are finished at this level, so return up a level and
view what you have done so far:[edit protocols ospf area 0.0.0.0 interface so-0/0/0]user@host# up[edit protocols ospf area 0.0.0.0]user@host# showinterface so-0/0/0 {hello-interval 5;dead-interval 20;}[edit protocols ospf area 0.0.0.0]user@host#
The interface statement appears because you have moved to the area statement.
- Add the second interface:[edit protocols ospf area 0.0.0.0]user@host# edit interface so-0/0/1[edit protocols ospf area 0.0.0.0 interface so-0/0/1]user@host# set hello-interval 5[edit protocols ospf area 0.0.0.0 interface so-0/0/1]user@host# set dead-interval 20[edit protocols ospf area 0.0.0.0 interface so-0/0/1]user@host# up[edit protocols ospf area 0.0.0.0]user@host# showinterface so-0/0/0 {hello-interval 5;dead-interval 20;}interface so-0/0/1 {hello-interval 5;dead-interval 20;}[edit protocols ospf area 0.0.0.0]user@host#
- Move up to the top level and review what you have:[edit protocols ospf area 0.0.0.0]user@host# top[edit]user@host# showprotocols {ospf {area 0.0.0.0 {interface so-0/0/0 {hello-interval 5;dead-interval 20;}interface so-0/0/1 {hello-interval 5;dead-interval 20;}}}}[edit]user@host#
This configuration now contains the statements you want.
- Before committing the configuration (and thereby activating
it), verify that the configuration is correct:[edit]user@host# commit checkconfiguration check succeeds[edit]user@host#
- Commit the configuration to activate it on the device:[edit]user@host# commitcommit complete[edit]user@host#
Making Changes to a Routing Protocol Configuration
Suppose you decide to use different dead and hello intervals on interface so-0/0/1. You can make changes to the configuration.
- Go directly to the appropriate hierarchy level by typing
the full hierarchy path to the statement you want to edit:[edit]user@host# edit protocols ospf area 0.0.0.0 interface so-0/0/1[edit protocols ospf area 0.0.0.0 interface so-0/0/1]user@host# showhello-interval 5;dead-interval 20;[edit protocols ospf area 0.0.0.0 interface so-0/0/1]user@host# set hello-interval 7[edit protocols ospf area 0.0.0.0 interface so-0/0/1]user@host# set dead-interval 28[edit protocols ospf area 0.0.0.0 interface so-0/0/1]user@host# top[edit]user@host# showprotocols {ospf {area 0.0.0.0 {interface so-0/0/0 {hello-interval 5;dead-interval 20;}interface so-0/0/1 {hello-interval 7;dead-interval 28;}}}}[edit]user@host#
- If you decide not to run OSPF on the first interface,
delete the statement:[edit]user@host# edit protocols ospf area 0.0.0.0[edit protocols ospf area 0.0.0.0]user@host# delete interface so-0/0/0[edit protocols ospf area 0.0.0.0]user@host# top[edit]user@host# showprotocols {ospf {area 0.0.0.0 {interface so-0/0/1 {hello-interval 7;dead-interval 28;}}}}[edit]user@host#
Everything inside the statement you deleted was deleted with it. You can also eliminate the entire OSPF configuration by simply entering delete protocols ospf while at the top level.
- If you decide to use the default values for the hello
and dead intervals on your remaining interface but you want OSPF to
run on that interface, delete the hello and dead interval timers:[edit]user@host# edit protocols ospf area 0.0.0.0 interface so-0/0/1[edit protocols ospf area 0.0.0.0 interface so-0/0/1]user@host# delete hello-interval[edit protocols ospf area 0.0.0.0 interface so-0/0/1]user@host# delete dead-interval[edit protocols ospf area 0.0.0.0 interface so-0/0/1]user@host# top[edit]user@host# showprotocols {ospf {area 0.0.0.0 {interface so-0/0/1;}}}[edit]user@host#
You can set multiple statements at the same time as long as they are all part of the same hierarchy (the path of statements from the top inward, as well as one or more statements at the bottom of the hierarchy). This feature can reduce considerably the number of commands you must enter.
- To go back to the original hello and dead interval timers
on interface so-0/0/1, enter: [edit]user@host# edit protocols ospf area 0.0.0.0 interface so-0/0/1[edit protocols ospf area 0.0.0.0 interface so-0/0/1]user@host# set hello-interval 5 dead-interval 20[edit protocols ospf area 0.0.0.0 interface so-0/0/1]user@host# exit[edit]user@host# showprotocols {ospf {area 0.0.0.0 {interface so-0/0/1 {hello-interval 5;dead-interval 20;}}}}[edit]user@host#
- You also can recreate the other interface, as you had
it before, with only a single entry:[edit]user@host# set protocols ospf area 0.0.0.0 interface so-0/0/1 hello-interval 5 dead-interval 20[edit]user@host# showprotocols {ospf {area 0.0.0.0 {interface so-0/0/0 {hello-interval 5;dead-interval 20;}interface so-0/0/1 {hello-interval 5;dead-interval 20;}}}}[edit]user@host#