1.2 IOS User Modes There are two primary modes of operation within the IOS: user mode and privileged mode. When you first connect to the router, you are placed in the user mode. The Cisco documentation refers to this as the user exec mode; I am going to omit "exec" throughout this book. The user mode is indicated by the prompt: Router> The word "Router" is replaced with your router's hostname if the hostname is already configured. The show commands in user mode are limited to a few basic levels. You cannot edit or view configurations at this stage; you can only view the router status and other miscellaneous information. To obtain a basic listing of commands, type a question mark: Router>? Editing the router's configuration requires you to be in the privileged exec mode, which I simply call "privileged mode." Use the enable command to enter this mode: Router>enable Password: Router# Privileged mode prompt You can always tell whether you are in user mode or privileged mode by looking at the prompt. The user mode prompt has a > at the end; the privileged mode prompt always has a # at the end, regardless of the submode. If you are familiar with Unix, you can equate privileged mode to "root" access. You could also equate it to the administrator level in NT or the supervisor in NetWare. In this mode, you have permission to access everything inside the router, including configuration commands. However, you can't type configuration commands directly. Before you can change the router's actual configuration, you must enter a submode of the privileged mode by giving the command configure terminal (see Section 1.3 for a shortcut). This command can be entered only when you are in the privileged mode. Router#configure terminal Enter configuration commands, one per line. End with Ctrl-Z Router(config)# Configuration mode To exit from configuration mode, you can use the command exit or type Ctrl-Z. To exit from enable (privileged) mode, you can use the disable command. So to exit both configuration and enable mode, use the following sequence of commands:
Router(config)#exit Router#disable Router> Privileged mode has several submodes in addition to configuration mode; each has its own prompt. To enter these submodes, you must first enter configuration mode by giving the configure terminal command. Here's a summary of the most common modes and prompts (there are many others): Global configuration mode Prompt: Router(config)# This level allows you to enter commands directly into the router configuration. From this level, you can enter any of the other three levels listed here. Once you are done entering commands into the configuration, use Ctrl-Z, exit, or the end command to return to the privileged prompt. The device's hostname is a good example of a configuration item you would find in the global configuration mode. Interface configuration mode Prompt: Router(config-if)# At this level, you are entering interface-specific commands. To enter this mode from theconfiguration prompt, use the command interface followed by an interface name, such as ethernet0, serial0, or serial1. Interface commands are discussed in Chapter 5. Use the exit command to exit from this prompt and return to the configuration prompt. Line configuration mode Prompt: Router(config-line)# From this prompt, you can enter line-specific commands. To enter this mode from the configuration prompt, use the command line, followed by a line type such as vty, console, tty, or async and a line number. The line configuration commands are discussed in Chapter 4. Once again, use the exit command to exit this mode and return to the configuration prompt. Router configuration mode Prompt: Router(config-router)#
From this prompt, you can enter only routing commands. To enter this mode from the configuration prompt, use the command router, followed by a routing protocol, such as rip or igrp. These commands differ widely depending on the routing protocol being used. Routing configuration commands are discussed in Chapter 8 through Chapter 10. Use the exit command to exit this mode and return to the configuration prompt. Figure 1-1 is a flow chart that illustrates the transitions between the most common command modes and submodes. (This list is not comprehensive.) The arrows are labeled with the commands that cause the transitions between the modes. Figure 1-1. Transitions between IOS command modes Configuration submodes provide a context in which certain commands are legal and others disallowed. It's one way that IOS tries to prevent you from making mistakes when configuring a router. In the quick-reference section, I list each
command with the context (or mode) in which it can be given. Contexts are clearly important on the command line, where the prompt shows the submode you're in. They are equally important in configuration files, where there are no such hints; you just have to know.
1.3 Command-Line Completion Command-line completion makes the IOS interface much more user-friendly. It saves you extra typing and helps out when you cannot remember a command's syntax. In a previous example, we used the command configure terminal: Router#configure terminal But you could have saved wear and tear on your hands by typing: Router#conf t IOS expands the command conf t to configure terminal. Another shortcut is to press Tab after typing "conf"; the router will fill in the best completion, which is "configure". Here is another example: Router#show running-config This long command can be shortened to: Router#sh ru The router knows that "show" is what you wanted because show is the only command that begins with "sh"; likewise, the only subcommand of show that begins with "ru" is running-config. If the router does not understand a command, it repeats the entire command line and places a caret (^) under the point at which it ran into trouble. For example: Router>show itnerface e0 >show itnerface e0 ^ % Invalid input detected at '^' marker. The caret symbol is pointing to the "t" in "itnerface", which is the command the router does not understand. We can quickly fix that by retyping the command: Router>show interface e0 We now get the correct output! Since we also know how to use shortcuts, we can type: Router>sh int e0 With this command we get the same result as its lengthy counterpart. Commandline completion saves a lot of typing, and it helps you keep your sanity when you're working with long commands.
Another form of command-line completion is the use of the Tab key. If you start a command by entering the first few characters, you can hit the Tab key. As long as there is only one match, the router will complete the command: for example, if you type "sh" and hit Tab, the router completes the "sh" with "show". If the router does not complete the command, you can enter a few more letters and try again. 1.4 Get to Know the Question Mark Previously, I said that you can get the available commands by typing? at the prompt. You can also use this trick to find the subcommands of any command. For example, if you know you want to use the copy command but cannot remember which subcommand you need, type: Router#copy? WORD Copy from flash device - format <dev:>[partition:][filename] flash Copy from system flash flh-log Copy FLH log file to server mop Copy from a MOP server rcp Copy from an rcp server running-config Copy from current system configuration startup-config Copy from startup configuration tftp Copy from a TFTP server Another use of the question mark is to find all commands that match what you have typed so far. For example, if you know the first part of a command, type it and then type a question mark. The router will return a list of all the matching commands. In the following example, we remember that the configure command begins with "co", but that's it. The router gives us the matching commands: Router#co? configure connect copy Note the important difference between these two examples. In the first example, there was a space before the question mark, which gave us the next command that complements copy. Had there not been a space, the router would have tried to complete the word "copy" for us, not given us the next available commands. In the next example, we did not add the space, so the router tried to complete "co" with all the commands it could find that start with "co". Another important rule to understand is that the router will return only commands that are relevant to the mode you are currently in. For example, if you are in user mode, you will be given only commands that apply to that mode. 1.5 Command-Line Editing Keys
IOS provides a number of keyboard shortcuts that let you edit the line you're typing. They should be familiar to any user of Unix or Emacs. Table 1-1 lists the command-line editing keys. Ctrl-a Ctrl-b Ctrl-d Ctrl-e Ctrl-f Ctrl-k Ctrl-n Ctrl-p Ctrl-t Ctrl-r Ctrl-u Keys Ctrl-w Ctrl-x Ctrl-y Ctrl-z Tab Up arrow Down arrow Left arrow Right Table 1-1. Command-line editing keys Commands Returns the cursor to the beginning of the current line. Moves the cursor back one character. (Equivalent to the left arrow key.) Deletes the character to the left of the cursor. Moves the cursor to the end of the line. Moves the cursor forward one character. (Equivalent to the right arrow key.) Deletes all the characters from the current cursor position to the end of the line. Goes to the next command in the session history. (Equivalent to the down arrow key.) Goes to the previous command in the session history. (Equivalent to the up arrow key.) Switches the current character with the character to the left of the cursor. Redraws or redisplays the current line. Clears the line. Deletes the word to the left of the cursor. Deletes from the cursor position to the beginning of the line. Pastes the most recently deleted characters to the current cursor position. Exits the current configuration mode and returns to the previous configuration mode. Tries to finish the current command. (Command completion.) Moves back through the history of commands. Moves forward through the history of commands. Moves the cursor to the left. Moves the cursor to the right.
Keys arrow Ctrl-^, then x Table 1-1. Command-line editing keys Commands Aborts the sequence. Breaks out of any executing command.