Cisco IOS Tips

16 Mar 2008

Keyboard shortcuts

These shortcuts can be used to speed up operating with the CLI:

Ctrl+B or LeftMove the cursor one character to the left
Ctrl+F or RightMove the cursor one character to the right
Esc, BMove the cursor one word to the left
Esc, FMove the cursor one word to the right
Ctrl+AMove cursor to the beginning of the line
Ctrl+EMove cursor to the end of the line
Ctrl+P or UpRetrieve last command from history
Ctrl+N or DownRetrieve next command from history
Ctrl+TSwap the current character with the one before it
Ctrl+WErase one word
Ctrl+UErase the entire line
Ctrl+LReprint the line
Ctrl+CExit configuration mode
Ctrl+ZApply the current command and exit configuration mode

Filter output

Most show commands support filtering with the pipe (|) character, allowing a user to display only the information he's looking for.

Switch# show interface status | include notconnect
Gi1/0/7                         notconnect   1          auto   auto 10/100/1000BaseTX
Gi1/0/9                         notconnect   1          auto   auto 10/100/1000BaseTX
Gi1/0/22                        notconnect   1          auto   auto 10/100/1000BaseTX

Filter options are include, exclude, and begin. The remaining characters after one of these filter types is processed as a regular expression, which could be a simple string (as in the example above) or something a bit more complex. The example below demonstrates filtering for interface numbers and any assigned IP addresses.

Switch# show run | inc ^interface|ip address
interface FastEthernet0
 ip address 192.168.0.1 255.255.255.0
interface FastEthernet1
interface FastEthernet2
 ip address 192.168.1.1 255.255.255.0
 ip address 192.168.2.1 255.255.255.0 secondary
interface FastEthernet3

You can also filter by section. Thanks to Carl Baccus to reminding me to include this.

R1# show run | section bgp
router bgp 100
 no synchronization
 redistribute connected
 neighbor 172.16.0.2 remote-as 200
 neighbor 172.16.0.9 remote-as 300
 no auto-summary

Skip through the configuration

You can begin viewing a configuration with the begin filter:

Router# show run | begin interface
interface FastEthernet0/0
 no ip address
 shutdown
...

You can also skip forward to a certain line once you've already begun viewing the configuration by hitting / at the --More-- prompt, followed by the string you want to match:

Router# sh run
Building configuration...

Current configuration : 601 bytes
!
version 12.4
...
!
!
/interface
filtering...
interface FastEthernet0/0
 no ip address
 shutdown
...

Do the do

Exec commands can be issued from within configuration mode via the do command. This can be handy for double-checking the current configuration before applying any changes.

Switch(config-if)# do show run int f0
Building configuration...

Current configuration : 31 bytes
!
interface FastEthernet0
 description Internal LAN
 ip address 172.16.0.1 255.255.0.0
end

Insert question marks

You can insert question marks into literal strings (such as interface descriptions) by typing CTRL+V immediately before the question mark. This acts as an escape character and prevents the command line from summoning the help menu.

Switch(config-if)# description Where does this go[ctrl+v]?

The interface description will appear as "Where does this go?"

Disable domain lookup on typos

Don't you hate it when this happens?

Switch# shrun
Translating "shrun"...domain server (255.255.255.255)
% Unknown command or computer name, or unable to find computer address

You can disable automatic DNS lookups with no ip domain-lookup, which will remove the delay before returning a new console prompt. However, this will also prevent you from referencing remote hosts by name, for example when telneting.

Switch(config)# no ip domain-lookup
...
Switch#shrun
Translating "shrun"
% Unknown command or computer name, or unable to find computer address

Synchronous logging

When logging to the console is enabled, a Cisco device will often dump messages directly to the screen. This can become irritating when it interrupts you in the midst of typing a command. (FYI, you can continue typing normally and the command will still take, but this still throws some people off.)

Synchronous logging can be enabled to "clean up" the CLI when this happens, outputting a fresh prompt below the message, along with any partially completed command.

Switch(config)# line con 0
Switch(config-line)# logging synchronous
Switch(config-line)# line vty 0 15
Switch(config-line)# logging synchronous

Revert a configuration to its default

The default command, called from global configuration, can be used to revert any part of a configuration to its default value (which is often nothing). For example, it can be used to remove all configuration from a particular interface:

Switch(config)# default g1/0/5
Interface GigabitEthernet1/0/5 set to default configuration
Switch(config)# ^Z
Switch# show run int g1/0/5
Building configuration...

Current configuration : 38 bytes
!
interface GigabitEthernet1/0/5
end

Show only applied access lists

For reasons unknown to me, IOS doesn't include a command to view what interfaces have ACLs applied. The closest we can get is drudging through the entire output of show ip interface. But, with a little ingenuity and the help of regular expressions, we can summon an efficient view of where our ACLs are applied.

Switch# sh ip int | inc line protocol|access list is [^ ]+$
FastEthernet0 is up, line protocol is down
FastEthernet1 is up, line protocol is up
  Inbound  access list is prohibit-web
FastEthernet2 is up, line protocol is up
  Inbound  access list is 42
FastEthernet3 is up, line protocol is down
FastEthernet4 is up, line protocol is up

For those curious, the regex above matches a line which either a) contains the string "line protocol", or b) contains the string "access list is " followed by a single word. This matches an ACL number or name (which can't contain spaces) but not "not set".

Speed up running-config display

When the show running-config command is issued, the output has to be assembled from numerous values in memory into the human-friendly display you see on the CLI. Unfortunately, the longer your configuration is, the more time this takes. IOS 12.3T introduced a feature to cache the running configuration text for quicker output:

Router(config)# parser config cache interface

Hat tip to Jeremy Cioara for blogging this!

Colby commented on 14 Apr 2008 at 2:19 a.m.

Very useful..Thanks!

Naresh commented on 15 Apr 2008 at 9:42 a.m.

Thanks.. Need to look at once..

Paul commented on 1 May 2008 at 4:30 p.m.

Regarding the section above on Synchronous logging: You can also hit the Tab key if your command is interrupted by a logging message. This will drop you to a new line with your command intact. Great site by the way.

yasser commented on 14 Jun 2008 at 2:06 a.m.

thanks bro great job

Mar Apuhin commented on 25 Jun 2008 at 4:47 p.m.

Hi, there is a another way to do away with the typos.

line con 0 transport preferred none

Using this, you can still use your router to do the DNS resolution without being bothered by the "typos".

Carl Baccus commented on 17 Jul 2008 at 9:52 p.m.

Very Cool! Another cool trick I learned the other day is:

Router# show run | sec mgcp
mgcp
mgcp call-agent X.X.X.X XXXX service-type mgcp version 0.1
mgcp dtmf-relay voip codec all mode out-of-band
mgcp rtp unreachable timeout 1000 action notify
...

The "sec" stands for "section", and only seems to be available in 12.4 series IOS, but still really useful also. Just thought I would throw that in there.

Arun Kaushik commented on 24 Jul 2008 at 1:45 p.m.

Man, You people are doing a very fine job. I love you techies. The contents are awesome... Please keeps it up.

Leo commented on 27 Jul 2008 at 6:25 a.m.

I like these tips thanks man

daniel fortin commented on 24 Sep 2008 at 6:40 p.m.

Men this site is very helpfull, especialy the part where you talk about the regular expressions! Verry usefull! Keep up the good work

Dan

Yuri Laskin commented on 23 Oct 2008 at 12:57 p.m.

sh int | i proto|input rate

Useful when looking for broadcast storm.

Syed Nabi commented on 18 Nov 2008 at 11:20 p.m.

Very helpful and useful site..Thanks for all your effort

Leave a comment

(optional, will not be published)
(optional)

Comment Tips

  • You can use Markdown syntax for decoration. (Cheat sheet)
  • Links: [Google](http://google.com) or <http://google.com>
  • Use backticks around commands: `ip address 127.0.0.1`
  • Use indentations (tabs) for preformatted text (code blocks)