Top 5 IOS CLI Speed Tips

The proliferation of the Graphical User Interface (GUI) in general purpose operating systems such as Windows, MacOS or iOS have not eradicated entirely its predecessor, the Command Line Interface (CLI). This is particularly true when working with network operating systems implemented on switches and routers, the best example of which would be Juniper Networks’ Junos and Cisco IOS.

When working with IOS,Cisco professionals and experts use a number of CLI techniques and shortcuts which allow them to quickly collect information for diagnostic purposes. Assuming that you are familiar with basic exec modes and context sensitive help of iOS, here is a list of five tips I find very useful while working with Cisco network equipment.

  1. Increase the size of the command history buffer.
  2. Use CLI editing features and common shortcuts.
  3. Use the ‘do’ keyword in any context in combination with the ‘show’ and ‘debug’ commands in any IOS context (‘config’, ‘interface’, ‘router’, etc.)
  4. Use pipe ‘|’ with available arguments to display and/or redirect only required sections of your configuration and/or ‘show’ command output.
  5. Use TCL script for ping connectivity test if multiple destination IP addresses are involved.

TIP 1 – Command History Buffer Size

A router or a switch keeps your last issued commands in the buffer. By default, the system remembers only the last 10 or 20 commands you type in (the size is contingent on the platform you use). Bear in mind though, that the buffer will be cleared if you terminate your console/vty session. You can change the buffer size for the duration of the session with your switch or router. The buffer can accept between 0-256 commands to be stored in order to invoke them later. In order to see what is in the buffer, use the ‘show history’ command. In order to verify what the current size of history buffer is, issue the command: show terminal.

Pic. 1 – Command History Buffer Size (default)

If you want your system to store more than 10 or 20 commands (with a maximum of 256 commands that could be stored), use the command presented in Pic. 2.

Pic. 2 – Command History Buffer Size Configuration

If you store more commands, in some situations it is easier to re-create what you have done with the device during a particular session. This may come in handy when you have already forgotten what you have done since some configurations involve a lot of commands to enable or disable certain features.

The caveat with changing the buffer size is that it only works for the duration of your console or vty session. If you log in to your device again, the buffer size goes back to the default value.

TIP 2 – CLI Editing Features and Common Shortcuts

Cisco IOS uses CLI as the primary user interface for configuring, monitoring and maintaining devices. Commands are typed one per line and will be executed in RAM memory as long as the following are both true:

  1. It has proper syntax, which means that the spelling and all mandatory arguments are specified by the administrator.
  2. It is accepted by hitting the Enter key.

In order to be quick and use the CLI efficiently, an administrator must get familiar with basic navigation techniques. The chart below lists the most commonly used shortcuts every professional must know:

Table 1 – CLI Editing Shortcuts

Key Stroke Function
Left Arrow or CTRL-B Moves the character one character to the left.
Right Arrow or CTRL-F Moves the character one character to the right.
CTRL-A Moves the cursor to the beginning of the line (helpful when you want to remove the statement and need to use the ‘no’ keyword.
CTRL-E Moves the cursor to the end of the line.
ESC, B Moves the cursor back one word.
ESC, F Moves the cursor forward one word.
Delete or Backspace Deletes the character to the left of the cursor.
CTRL-D Deletes the character at the cursor.
CTRL-U or CTRL-X Deletes all characters from the cursor to the beginning of the command line.
CTRL-K Deletes all characters from the cursor to the end of the command line.
CTRL-W Deletes the word to the left of the cursor.
ESC-D Deletes from the cursor to the end of the word.
CTRL-Y Recalls the most recent entry in the buffer.

Apart from these shortcuts, Cisco allows us to use following while using CLI:

  1. Command Abbreviation
  2. Command Auto-Completion

Command abbreviation allows an administrator to type in any command using only a few letters instead of typing the whole keyword. However, the system must be able to uniquely identify the command in the given context.

Let’s see this IOS feature in a practical example. For instance, if I want to display the running configuration of a router, I normally use the command ‘show running-config’, but I can also use the abbreviated version: ‘show run‘. The result is the same and I save a lot of time. However, if I type in: ‘show r’, the system is going to display an error: % Ambiguous command: “show r”. This is due to the fact that the router/switch has more than one command in the privileged exec mode that starts with ‘show r’. Look at the screenshot below:

Pic. 3 – Command Abbreviation Error

Here, the system does not know if we mean ‘show radius’, or ‘show region’ or perhaps ‘show resources’, which all start with ‘show r’. However, if I type in ‘show run’, IOS has only one command in this context starting with ‘run’.

The command auto-completion is similar to the one you find on Unix/Linux and also on recent MS Windows implementations. All you have to do is to type in enough letters to uniquely identify the command in a given context and use the TAB key on your keyboard. IOS will then display the whole keyword on your screen.

TIP 3 – The ‘do’ Keyword

Monitoring, maintaining and troubleshooting Cisco devices requires not only working knowledge of the technologies, but also how to properly verify and interpret the output of ‘show’ and ‘debug’ commands provided by Cisco IOS. Originally these two diagnostic commands, with hundreds of options available, were executed in two IOS contexts: the user exec mode (prompt shows the ‘>’ character) and the privileged exec mode (prompt displays ‘#’ character).

In IOS 12.1(11b)E version, Cisco added the ‘do’ keyword allowing users to execute the ‘show’ and ‘debug’ commands in the global configuration mode or in other configuration modes such as interface ‘(config-if)#’, routing protocol ‘(config-router)#’ etc. The same keyword can be applied when using tools and utilities such as ping, telnet, ssh and others. All an administrator has to do is to precede the commands with the do keyword.

Let’s see how this works in practice. In my example I would like to display the running-configuration of the router. In order to do it I must be in the the right context which is the ‘privileged exec mode‘. Look what happens when you use this keyword in other mode (here: global configuration mode):

Pic. 4 – Example of ‘show’ command without the ‘do’ keyword

As you can see, the system shows an invalid input at the ‘^‘ character. IOS can only recognize the first two letters ‘sh’, for ‘shutdown’ command. Now, look what happens when I use the ‘do’ keyword with the same command:

Pic. 5 – The ‘’do’ command

This time, the system obliges and displays the running configuration as requested.

What is wrong with going back to privileged mode to check the results of our configurations?

Applying configurations using CLI will typically require numerous steps to be carried out. It is essential to check your configuration every step of the way rather than implement the whole solution and then realize that things are not working as expected. After typing in thirty or more commands, it will be much harder to find out what we have missed or misconfigured in the process. If we use the appropriate ‘show’ commands more often and without moving back to privileged mode, we can isolate a potential problem much faster, and as a result of that, decrease downtime and save money for our company.

TIP 4 – Filtering and Redirecting Output with the Pipe Character ‘|’

Daily network maintenance and occasional troubleshooting of Cisco devices often involves collecting a lot of information from routers and switches. IOStools such as the ‘show’ commands will, at times, provide a tremendous amount of information, not all of which is necessarily useful in some situations. The ability to filter the output in order to focus on the right pieces of information is the mark of a networking professional.

Be the first to hear of new free tutorials, training videos, product demos, and more. We'll deliver the best of our free resources to you each month, sign up here:

Imagine that you are managing the BGP routers working for your local ISP. As of writing this article, a BGP table contains around five hundred thousand entries. If your terminal displays twenty four (default) or so lines at any given time, how long do you think it will take you to go to the bottom of the output to find the appropriate prefixes? Also, your configurations may be several screens long. Pressing the spacebar numerous times to get down to the interesting pieces of information can take some time. What if you work as technical support engineer and must help your customer bring the network up after some failure? You must be able to collect enough information by displaying only what is relevant in a given situation.

Collecting the right information requires that a network engineer can do the following quickly:

  1. Use the right ‘show’ command(s).
  2. Filter the output of the show command(s) in order to single out the relevant pieces of information.

As far as the second point is concerned, the ‘show argument’ commands can be followed by the ‘|’ (pipe) character and available keywords. Here is how I can check what pipe options are allowed on my router (in my example I will use ‘show interface’ command, where interface is one of numerous arguments that show can take):

Pic. 6 – Router Redirection Options

Let’s look at some practical examples of using some of the options listed.

Notice!

The pipe character is separated by space on both sides.Also, the words used for filtering are case sensitive. You must provide them as shown in the unfiltered output.

Example 1: Display OSPF configuration of a router.

Pic. 7 – Example 1

Example 2: Display only IP-enabled interfaces of a router.

Pic. 8 – Example 2

Example 3: Display all switch interfaces with ‘CRC’ and ‘duplex’ keywords .

Pic. 9 – Example 3

In example 3, notice that I have used additional pipe characters WITHOUT space. They serve as the logical ‘or’ statements. Well known regular expressions can also be used to further filter the output of show commands.

Look at the summary of some commonly used regular expressions:

Table 2 – Regular Expressions

Character Special Meaning
. (dot) Matches any single character, including white space.
* Matches 0 or more sequences of the pattern.
+ Matches 1or more sequence of the pattern.
? Matches 0 or 1 occurrence of the pattern.
^ Matches the beginning of the string.
$ Matches the end of the string
_ (underscore) Matches a comma (,), left brace ({), right brace (}), left parenthesis ( ( ), right parenthesis ( ) ), the beginning of the string, the end of the string, or a space.
[] Matches any single character in the brackets.
() Matches the multi-character expression in the parenthesis.

Example 4: Display all the interfaces with 172.16.215 addresses and 10.0 (compare with Example 2).

Pic. 10 – Example 4

These are only a few examples illustrating how to use the feature. Other options such as ‘append’, ‘tee’, ‘redirect’ can be used to redirect the output of the commands to some external URL. This could be ftp: or tftp: which indicates FTP and TFPT servers, respectively. These options may require additional parameters such as the IP address of the destination server, and in the case of an FTP server, user name and password will also need to be provided.

Tip 5 – TCL Scripting for Ping Connectivity Test

IOS is also equipped with a scripting language called Tcl (Tool Command Language) pronounced as tickle) created by John Ousterhout. It is a fully fledged scripting language but in this article, I am only going to present a very simple script which is often used by administrators to check the connectivity from a router to multiple destinations.

Let’s imagine that you are about to introduce a new router into the existing network. After you have configured basic security, routing protocol, etc., the router learns the entire destination network or subnet addresses and populates its routing table. However, the number of prefixes in the routing table is significant and we cannot be sure that all destinations have been learned properly. A good practice is to create a file with all of the router’s IP addresses to use for basic connectivity tests with the ping utility. The easy way to create this file is to log in to every router in the network and issue the ‘show ip alias’ command. Take a look at the example below:

Pic. 11 – The ‘show ip alias’ command

If your terminal software supports marking of columns (mine uses the CTRL key to accomplish that), you can highlight the addresses as shown in the picture above (pic. 11) and copy these to a text file. Repeat the same process on all routers in your network to save all the addresses. Then, use Tcl to ping multiple IP addresses in one shot in order to test if the router can reach them all. Your test could look like the one presented below (in my example, only a few addresses are added to the script).

Tcl – Ping Test Script

foreach address {
10.0.1.1
172.16.12.1
172.16.111.1
172.16.123.1
172.16.215.1
192.0.2.1
} { ping $address}

In order to apply the script and test connectivity, you must first enter the Tcl shell on your router. The command that allows it is: tclsh. You must enter this command in the privileged exec mode. Pay attention to the prompt change!

Pic. 12 – Enter Tcl Shell

Once you have entered the Tcl shell, all you have to do is to paste it in the script and hit Enter. If the destination addresses are reachable, you will see the success output (exclamation marks) on your screen. In case of failure, dots are displayed.

Take a look at the example below. Once the test has finished, it is imperative that you leave the Tcl shell by typing in: R1(tcl)#tclquit.

Pic. 13. – Ping Test Results

I hope you find the tips described useful and that they will contribute to a more efficient utilization of your time and resources when using Cisco IOS.

The following two tabs change content below.

Jarek Rek

Jarek Rek is a networking professional with over 12 years of experience. He worked for Cisco Partner Companies providing their customers with networking solutions, technical support and training. Currently, he has been working as Cisco Trainer in the areas of routing and switching, service provider and security. He has also achieved the Cisco Sirius Award – Top Quality Trainer for constant high achievement in Cisco delivery in 2012. In his spare time he maintains routing blog at http://hackingcisco.blogspot.com designed to help beginners, intermediate, and advanced students hone their technical skills.

Latest posts by Jarek Rek (see all)