IOS Console Customization

This article offers a few tips to customize the behavior of a Cisco IOS router's VTY and console lines.

Set a Custom Escape Character

The default IOS escape sequence is ctrl-^x, or "control-shift-6, x", as we can see from the output of show terminal:

Router# show terminal
Line 6, Location: "", Type: "xterm"
Length: 25 lines, Width: 120 columns
Baud rate (TX/RX) is 9600/9600
Status: PSI Enabled, Ready, Active, No Exit Banner, Automore On
  Notify Process
Capabilities: none
Modem state: Ready
Special Chars: Escape  Hold  Stop  Start  Disconnect  Activation
                ^^x    none   -     -       none         
Timeouts:      Idle EXEC    Idle Session   Modem Answer  Session   Dispatch
                never         never                        none     not set
...

This obscure sequence probably has some historical significance, but it is most commonly used on IOS today to interrupt a ping or traceroute command. We can set a custom escape character to something more convenient, such as ctrl-c (which is the ASCII character 3):

Router(config)# line vty 0 15
Router(config-line)# escape-character ?
  BREAK            Cause escape on BREAK
  CHAR or   Escape character or its ASCII decimal equivalent
  DEFAULT          Use default escape character
  NONE             Disable escape entirely
  soft             Set the soft escape character for this line

Router(config-line)# escape-character 3

We can now simply use ctrl-c in place of ctrl-shift-6. The "x" generally isn't necessary.

Alternatively, a temporary custom escape character can be defined for the current session only using the terminal escape-character EXEC command.

Increase the History Size

By default, the terminal history (which records recently used commands and is invoked with the up arrow) is limited to the last 20 commands. We can increase the history size under line configuration or via the terminal command:

Router(config)# line vty 0 15
Router(config-line)# history size ?
    Size of history buffer

Router(config-line)# history size 100

show history can be used to inspect the contents of the history buffer.

Infinite Terminal Length

Often you'll need to copy a good amount of text from the console (e.g. the output of show run or show tech-support). Depending on the terminal emulator in use, you may notice the copied or saved text has been polluted with lines reading "--More--" followed by unprintable characters (^H), which were inserted by the IOS CLI pager. A handy solution for this is to temporarily set the terminal length to zero, which effectively sets an infinite terminal length and disables terminal paging.

Router# terminal length ?
    Number of lines on screen (0 for no pausing)

Router# terminal length 0

To return the terminal length, use terminal length appended with the desired number of lines (typically 24). If you want to permanently alter the terminal length, use the length command under line configuration.

Include Timestamps on Show Commands

IOS includes an option to automatically timestamp the output of show commands. This can be handy when producing records for documentation or archival purposes.

Router(config)# line vty 0 15
Router(config-line)# exec prompt timestamp
Router(config-line)# ^Z
Router# show ip interface brief
Load for five secs: 0%/0%; one minute: 0%; five minutes: 1%
Time source is hardware calendar, *03:14:21.123 EDT Wed Apr 14 2010

Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0              70.174.182.38   YES DHCP   up                    up      
FastEthernet1              unassigned      YES NVRAM  up                    down
...

Lock the Terminal

A little-known feature that might come in handy: IOS allows you to temporarily lock your console session. First, locking must be enabled under line configuration:

Router#(config)# line console 0
Router#(config-line)# lockable

Simply issue the lock command, and provide and confirm a password of your choosing (it need not be your username's password) to lock the terminal. Provide the password again to unlock the terminal.

Router# lock
Password: 
Again:

Locked

Password: 
Router#

For more tips like these (but not necessarily related to the console itself) check out the IOS Tips wiki page!

 

原帖地址:http://packetlife.net/blog/2010/may/10/ios-console-customization/