Table Of Contents
Using the Command-Line Interface
Accessing the Command Line Interface
Using the CLI
Using CLI Command Modes
Changing Command Modes
Listing the Commands Used with Each Command Mode
CLI Command Hierarchy
EXEC Mode Commands
Configuration Mode Commands
Using Commands
Listing Commands and Syntax
Entering Command Sequences
Undoing or Reverting to Default Values or Conditions
Using Keyboard Shortcuts
Using CLI Variables
User-Defined Persistent CLI Variables
Using Command Aliases
Defining Command Aliases
Command Scripts
Executing Commands Specified in a Script
Setting the Delay Time
Using the Command-Line Interface
This chapter describes the command-line interface (CLI) and CLI command modes. It includes the following sections:
•
Accessing the Command Line Interface
•
Using the CLI
•
Using Commands
•
Using CLI Variables
•
Using Command Aliases
•
Defining Command Aliases
•
Command Scripts
Accessing the Command Line Interface
You can connect to the switch using a terminal plugged into the console port. See "Console Settings" section for information on how to set console port parameters.
You can also connect to the switch with Telnet or SSH. The switch supports up to eight simultaneous Telnet and SSH connections. To connect with Telnet or SSH, you need to know the hostname or IP address of the switch.
To establish a Telnet connection to the switch, perform this task:
| |
Command
|
Purpose
|
Step 1
|
telnet {hostname | ip_addr}
|
Establishes a Telnet connection from your host to the switch that you want to access.
|
Step 2
|
Login: admin
Password: password
|
Initiates authentication.
Note If no password has been configured, press Return.
|
Step 3
|
switch# exit
|
Exits the session when finished.
|
Alternatively, to make an SSH connection to the switch, use the following command:
Command
|
Purpose
|
ssh {hostname | ip_addr}
|
Makes an SSH connection from your host to the switch that you want to access.
|
Using the CLI
This section includes the following topics:
•
Using CLI Command Modes
•
CLI Command Hierarchy
•
EXEC Mode Commands
•
Configuration Mode Commands
Using CLI Command Modes
The switch supports two main command modes: user EXEC mode and configuration mode. The commands available to you depend on the mode you are in. To obtain a list of available commands in either mode, type a question mark (?) at the system prompt.
Table 3-1 lists and describes the two commonly used modes, how to enter the modes, and the resulting system prompts. The system prompt helps you identify which mode you are in and the commands that are available to you in that mode.
Table 3-1 Frequently Used switch Command Modes
Mode
|
Description
|
How to Access
|
Prompt
|
EXEC mode
|
Enables you to temporarily change terminal settings, perform basic tests, and display system information.
Note Changes made in this mode are generally not saved across system resets.
|
At the switch prompt, enter the required EXEC mode command.
|
switch#
|
Configuration mode
|
Enables you to configure features that affect the system as a whole.
Note Changes made in this mode are saved across system resets if you save your configuration.
|
From EXEC mode, enter the configure terminal command.
|
switch(config)#
|
You can abbreviate commands and keywords by entering just enough characters to make the command unique from other commands. For example, you can abbreviate the configure terminal command to conf t.
Changing Command Modes
Configuration mode, also known as terminal configuration mode, has several submodes. Each of these submodes places you further down in the prompt hierarchy. When you type exit, the switch backs out of the current level and returns you to the previous level. When you type end, the switch backs out to the user EXEC level. You can also press Ctrl-Z in configuration mode as an alternative to typing end.
Listing the Commands Used with Each Command Mode
You can display the commands available in any command mode by typing a question mark (?) at the switch prompt.
CLI Command Hierarchy
CLI commands are organized hierarchically, with commands that perform similar functions grouped under the same level. For example, all commands that display information about the system, configuration, or hardware are grouped under the show command, and all commands that allow you to configure the switch are grouped under the configure terminal command.
To execute a command, you enter the command by starting at the top level of the hierarchy. For example, to configure an interface, use the config terminal command. Once you are in configuration mode, enter the interface command. When you are in the interface submode, you can query the available commands.
The following example shows how to query the available command in the interface submode:
switch# configure terminal
switch(config)# interface ethernet 1/1
switch(config-if)# ?
bandwidth Set bandwidth informational parameter
cdp Configure CDP interface parameters
channel-group Configure port channel parameters
delay Specify interface throughput delay
description Enter description of maximum 80 characters
duplex Enter the port duplex mode
errdisable Configure error disable parameters
exit Exit from command interpreter
flowcontrol Configure interface flowcontrol
lldp Configure Interface LLDP parameters
logging Configure logging for interface
mac MAC configuration commands
no Negate a command or set its defaults
pop Pop mode from stack of restore from name
priority-flow-control Enable/Disable PFC
push Push current mode to stack or save it under name
service-policy Configure service policy for an interface
shutdown Enable/disable an interface
snmp Modify SNMP interface parameters
spanning-tree Spanning Tree Subsystem
speed Enter the port speed
storm-control Configure Interface storm control
switchport Configure switchport parameters
where Shows the cli context you are in
EXEC Mode Commands
When you start a session on the switch, you begin in EXEC mode. From EXEC mode, you can enter configuration mode. Most of the EXEC commands are one-time commands, such as show commands, which display the current configuration status.
The following commands are available in EXEC mode:
attach Connect to a specific linecard
callhome Callhome commands
cd Change current directory
checkpoint Create configuration rollback checkpoint
clock Manage the system clock
configure Enter configuration mode
copy Copy from one file to another
debug Debugging functions
debug-filter Enable filtering for debugging functions
delete Delete a file or directory
dir List files in a directory
echo Echo argument back to screen (useful for scripts)
ethanalyzer Configure cisco fabric analyzer
event Event Manager commands
exit Exit from command interpreter
find Find a file below the current directory
gunzip Uncompresses LZ77 coded files
gzip Compresses file using LZ77 coding
mkdir Create new directory
no Negate a command or set its defaults
ping Test network reachability
ping6 Test IPv6 network reachability
pop Pop mode from stack of restore from name
push Push current mode to stack or save it under name
pwd View current directory
reload Reboot the entire box
rollback Rollback configuration
routing-context Set the routing context
run-script Run shell scripts
send Send message to open sessions
setup Run the basic SETUP command facility
show Show running system informationn
show Show running system information
sleep Sleep for the specified number of seconds
ssh SSH to another system
ssh6 SSH to another system using IPv6 addressing
system System management commands
tac-pac Save tac info in a compressed .gz file at specific location
tail Display the last part of a file
telnet Telnet to another system
telnet6 Telnet6 to another system using IPv6 addressing
terminal Set terminal line parameters
traceroute Traceroute to destination
traceroute6 Traceroute6 to destination
undebug Disable Debugging functions (See also debug)
where Shows the cli context you are in
write Write current configuration
Configuration Mode Commands
Configuration mode allows you to make changes to the existing configuration. When you save the configuration, these commands are saved across switch reboots. Once you are in configuration mode, you can enter interface configuration mode, zone configuration mode, and a variety of protocol-specific modes. Configuration mode is the starting point for all configuration commands.
The following commands are available in configuration mode:
switch# configure terminal
switch(config)# ?
aaa Configure aaa functions
access-list Configure access control list parameters
banner Configure banner message
boot Configure boot variables
callhome Enter the callhome configuration mode
cdp Configure CDP parameters
class-map Configure a class map
cli Configure CLI commands
clock Configure time-of-day clock
exit Exit from command interpreter
fcoe_mgr Config commands for Fcoe_mgr
feature Command to enable/disable features
hostname Configure system's host name
hw-module Enable/Disable OBFL information
interface Configure interfaces
ipv6 Configure IPv6 features
lacp Config commands for LACP
license Modify license features
line Configure a terminal line
lldp Configure global LLDP parameters
logging Modify message logging facilities
lst Lst configuration commands
mac MAC configuration commands
mac-address-table MAC Address Table
monitor Configure Ethernet SPAN sessions
no Negate a command or set its defaults
object-group Configure ACL object groups
password Password for the user
policy-map Configure a policy map
pop Pop mode from stack of restore from name
port-channel Configure port channel parameters
push Push current mode to stack or save it under name
radius Configure RADIUS configuration
radius-server Configure RADIUS related parameters
resequence Resequence a list with sequence numbers
route-map Create route-map or enter route-map command mode
snmp-server Configure snmp server
spanning-tree Spanning Tree Subsystem
ssh Configure SSH parameters
switchname Configure system's host name
system System config command
system System management commands
table-map Configure a table map
username Configure user information.
vrf Configure VRF parameters
where Shows the cli context you are in
Using Commands
You can configure the CLI to function in two ways: configure it interactively by entering commands at the CLI prompt or create an ASCII file containing switch configuration information (use the CLI to edit and activate the file).
Listing Commands and Syntax
In any command mode, you can obtain a list of available commands by entering a question mark (?).
To see a list of commands that begin with a particular character sequence, type those characters followed by a question mark (?). Do not include a space before the question mark.
switch# co?
configure copy
To list keywords or arguments, enter a question mark in place of a keyword or argument. Include a space before the question mark. This form of help is called command syntax help because it reminds you which keywords or arguments are applicable based on the commands, keywords, and arguments you have already entered.
switch# configure ?
<CR>
terminal Configure the system from terminal input
Tip
If you are having trouble entering a command, check the system prompt and enter the question mark (?) for a list of available commands. You might be in the wrong command mode or using incorrect syntax.
Entering Command Sequences
In any command mode, you can begin a particular command sequence, then immediately press the Tab key to complete the rest of the command:
switch(config)# ro<Tab>
switch(config)# role <Tab>
switch(config)# role name
This form of help is called command completion because it completes a word for you. If several options are available for the typed letters, all options that match those letters are displayed.
Undoing or Reverting to Default Values or Conditions
You can enter the no form of any command to perform the following actions:
•
Disable a feature
If you want to disable a feature that was enabled:
switch # configure terminal
switch(config)# feature fip-snooping
switch(config)# no feature fip-snooping
•
Use the no form of a command in EXEC mode
If you enter a command, you can undo the results:
switch # blink interface ethernet 1/20
switch# no blink interface ethernet 1/20
•
Revert to the default value
If you want to revert to the default value, you can undo the results:
switch# configure terminal
switch(config)# banner motd #Welcome to the switch#
switch(config)# show banner motd
switch(config)# no banner motd
switch(config)# show banner motd
Using Keyboard Shortcuts
You can execute an EXEC mode command from a configuration mode or submode prompt. You can enter this command from any submode within the configuration mode. The command is executed at the EXEC level, and the prompt resumes its current mode level, as in the following example.
switch(config)# terminal session-timeout 0
switch(config)#
In the preceding example, terminal session-timeout is an EXEC mode command:
Table 3-2 lists some useful command keys that can be used in both EXEC and configuration modes.
Table 3-2 Useful Command Keys
Command
|
Description
|
Ctrl-P
|
Up history
|
Ctrl-N
|
Down history
|
Ctrl-X-H
|
List history
|
Alt-P
|
History search backwards
Note The difference between Tab completion and Alt-P or Alt-N is that pressing Tab completes the current word, while Alt-P and Alt-N completes a previously entered command.
|
Alt-N
|
History search forwards
|
Ctrl-G
|
Exit
|
Ctrl-Z
|
End
|
Ctrl-L
|
Clear session
|
Table 3-3 describes the commonly used configuration submodes.
Table 3-3 Common Configuration Submodes
Submode Name
|
From Configuration Mode, Enter:
|
Submode Prompt
|
Call home
|
callhome
|
switch(config-callhome)#
|
Interface configuration
|
interface type slot/port
|
switch(config-if)#
|
Line console
|
line console
|
switch(config-console)
|
Virtual terminal line
|
line vty
|
switch(config-line)#
|
Role
|
role name
|
switch(config-role)#
|
VLAN
|
vlan
|
switch(config-vlan)#
|
Using CLI Variables
The switch CLI parser supports the definition and use of variables in CLI commands. CLI variables can be used as follows:
•
Entered directly on the command line.
•
Passed to the child script initiated using the run-script command.
The variables defined in the parent shell are available for use in the child run-script command process (see the "Executing Commands Specified in a Script" section).
•
Passed as command line arguments to the run-script command (see the "Executing Commands Specified in a Script" section).
CLI variables have the following characteristics:
•
You cannot reference a variable through another variable using nested references.
•
You can define persistent variables that are available across switch reloads.
•
You can reference only one predefined system variable, which is the TIMESTAMP variable.
User-Defined Persistent CLI Variables
You can define CLI session variables to persist only for the duration of your CLI session using the cli var name command in EXEC mode. CLI session variables are useful for scripts that you execute periodically.
The following example shows how to create a user-defined CLI session variable:
switch# cli var name testinterface ethernet 1/20
You can reference a variable using the syntax $(variable). The following example shows how to reference a user-defined CLI session variable.
switch# show interface $(testinterface)
Ethernet1/20 is down (SFP not inserted)
Hardware: 1000/10000 Ethernet, address: 0005.ad00.37b7 (bia 0005.ad00.37b7)
MTU 1500 bytes, BW 10000000 Kbit, DLY 10 usec,
reliability 255/255, txload 1/255, rxload 1/255
unknown enum 3-duplex, 10 Gb/s
Input flow-control is off, output flow-control is off
Switchport monitor is off
Last clearing of "show interface" counters never
1 minute input rate 0 bits/sec, 0 packets/sec
1 minute output rate 0 bits/sec, 0 packets/sec
0 input packets 1773583844 unicast packets 775822475 multicast packets
1375018549 broadcast packets 10904942378 jumbo packets 3782510632 storm supp
0 output packets 0 multicast packets
0 broadcast packets 8644443928 jumbo packets
0 input error 0 short frame 0 watchdog
0 no buffer 0 runt 2743974619 CRC 0 ecc
0 overrun 0 underrun 0 ignored 0 bad etype drop
0 bad proto drop 0 if down drop 0 input with dribble
0 output error 0 collision 0 deferred
0 late collision 0 lost carrier 0 no carrier
Use the show cli variables command to display user-defined CLI session variables. The following example displays user-defined CLI session variables.
switch# show cli variables
VSH Variable List
-----------------
TIMESTAMP="2009-08-03-21.18.38"
testinterface="ethernet 1/20"
Use the cli no var name command to remove user-defined CLI session variables. The following example removes a user-defined CLI session variable.
switch# cli no var name testinterface
Using Command Aliases
Command alias support has the following characteristics:
•
Command aliases are global for all user sessions.
•
Command aliases are saved across reboots.
•
Commands being aliased must be typed in full without abbreviation.
•
Command alias translation always takes precedence over any keyword in any configuration mode or submode.
•
Command alias configuration takes effect for other user sessions immediately.
•
You cannot override the default command alias alias, which aliases the show cli alias command.
•
Nesting of command aliases is permitted to a maximum depth of 1. One command alias can refer to another command alias that must refer to a valid command, not to another command alias.
•
A command alias always replaces the first command keyword on the command line.
•
You can define command aliases for commands in any configuration submode or the EXEC mode.
Defining Command Aliases
You can define command aliases using the cli alias name command in configuration mode.
The following example shows how to define command aliases:
switch# configure terminal
switch(config)# cli alias name eth interface ethernet
switch(config)# cli alias name shintbr show interface brief
switch(config)# cli alias name shethintup shintbr | include up | include ethernet
You can display the command aliases defined on the switch using the alias default command alias.
The following example shows how to display the command aliases defined on the switch:
switch# alias
CLI alias commands
==================
alias :show cli alias
gigint :interface gigabitethernet
shintbr :show interface brief
shethintup :shintbr | include up | include ethernet
Command Scripts
This section includes the following topics:
•
Executing Commands Specified in a Script
•
Setting the Delay Time
Executing Commands Specified in a Script
The run-script command executes the commands specified in a file. To use this command, be sure to create the file and specify commands in the required order.
Note
You cannot create the script file at the switch prompt. You can create the script file on an external machine and copy it to the bootflash: directory. This section assumes that the script file resides in the bootflash: directory.
The syntax for this command is run-script filename.
The following example displays the CLI commands specified in a test file that resides in the bootflash: directory:
switch# show file bootflash:testfile
show interface ethernet 1/20
This file output is in response to the run-script command executing the contents in the test file:
switch# show file bootflash:testfile
show interface ethernet 1/20
switch# run-script bootflash:testfile
`interface ethernet 1/20`
`show interface ethernet 1/20`
Hardware: 1000/10000 Ethernet, address: 0005.ad00.3e4f (bia 0005.ad00.3e4f)
MTU 1500 bytes, BW 10000000 Kbit, DLY 10 usec,
reliability 255/255, txload 1/255, rxload 1/255
full-duplex, 10 Gb/s, media type is 10g
Input flow-control is off, output flow-control is off
Switchport monitor is off
Last link flapped 00:29:47
Last clearing of "show interface" counters never
1 minute input rate 0 bits/sec, 0 packets/sec
1 minute output rate 0 bits/sec, 0 packets/sec
188 input packets 0 unicast packets 190 multicast packets
0 broadcast packets 0 jumbo packets 0 storm suppression packets
188 output packets 188 multicast packets
0 broadcast packets 0 jumbo packets
0 input error 0 short frame 0 watchdog
0 no buffer 0 runt 0 CRC 0 ecc
0 overrun 0 underrun 0 ignored 0 bad etype drop
0 bad proto drop 0 if down drop 0 input with dribble
0 output error 0 collision 0 deferred
0 late collision 0 lost carrier 0 no carrier
Setting the Delay Time
The sleep command delays an action by a specified number of seconds.
The syntax for this command is sleep seconds:
You will see the switch prompt return after 30 seconds. This command is useful within scripts. For example, if you create a command script called test-script.
switch# show file bootflash:test-script
discover scsi-target remote
sleep 10
show scsi-target disk
switch# run-script bootflash:test-script
When you execute the test-script command script, the switch software executes the discover scsi-target remote command, and then waits for 10 seconds before executing the show scsi-target disk command.