Earlier in the chapter you learned that you can telnet into a Cisco device running IOS to manage it. It is also possible to telnet from a Cisco IOS device to another device. This can be useful when troubleshooting across multiple devices. In this section you will learn to initiate and manage telnet connections from IOS CLI.

To telnet to another device from IOS, use the telnet command as shown below:

myRouter#telnet 192.168.1.7
Trying 192.168.1.7 … Open

Username: admin
Password:

Switch>

Remember that if the remote device is an IOS device, it should have a line password and an enabled password/secret configured. Without these, you will not be able to telnet in or get into the privilege exec mode.

When you exit the telnet session using logout or exit command on the remote device, you will be back to the prompt of the device from where the session was initiated, as shown below:

Switch#logout

[Connection to 192.168.1.7 closed by foreign host]
myRouter#

You can telnet to multiple devices simultaneously. For that, you will first need to toggle back to the local device prompt form the remote prompt using Crtl+Shift+6 followed by the X key. For example, in the output below, I first telnet to the switch like before and enter its privilege exec mode. Then I press the Ctrl+Shift+6 sequence following by X. The whole sequence will not be seen in the output but you will notice that I am back to the prompt of myRouter:

myRouter#telnet 192.168.1.7
Trying 192.168.1.7 … Open

Username: admin
Password:

Switch>enable
Password:
Switch# [I pressed Crtl+Shift+6 X here]
myRouter# [Notice the change in prompt. I am back to myRouter]

Though you are back to the first device, the telnet session to the remote device is still active, but in the background. Now you can initiate another telnet session to another device as shown below:

myRouter#telnet 192.168.1.137
Trying 192.168.1.137 … Open

User Access Verification

Username: admin
Password:

Switch2>

You can again leave this session active and go back to the prompt of the first device using the Ctrl+Shift+6 X sequence as shown below:

 Switch2> [I pressed Ctrl+Shift+6 X here]
myRouter# 

Now you have two telnet sessions active from the first device. You can see all active telnet sessions using the show sessions command:

 myRouter#show sessions
Conn Host                Address               Byte  Idle  Conn Name
1 192.168.1.7        192.168.1.7              0      7  192.168.1.7
*  2 192.168.1.137      192.168.1.137        0      1  192.168.1.137 

The asterisk (*) sign next to a session shows the most recent session. You can return to that session by pressing Enter twice. You can return to any session by typing the number of the session and pressing Enter. In the output below, I toggle between the two sessions. Notice how pressing enter twice or just entering the session number as a command takes me back to the telnet sessions. Also notice that I can toggle between the sessions and the first device using Ctrl+Shift+6 X sequence.

myRouter# [Here I pressed Enter twice]
[Resuming connection 2 to 192.168.1.137 … ]

Switch2> [Here I pressed Crtl+Shift+6 X]
myRouter#1
[Resuming connection 1 to 192.168.1.7 … ]

Switch# [Here I pressed Crtl+Shift+6 X]
myRouter#2
[Resuming connection 2 to 192.168.1.137 … ]

Switch2> [Here I pressed Crtl+Shift+6 X]
myRouter#

You can end a telnet session from the remote device using the logout or exit command. You can also close the telnet session from the originating device using the disconnect <session_id> command.

In the output below, I close the first session using the logout command on the remote device whereas I close the second session using the disconnect command:

myRouter#1
[Resuming connection 1 to 192.168.1.7 … ]

Switch#logout

[Connection to 192.168.1.7 closed by foreign host]

myRouter#show sessions
Conn Host                Address             Byte  Idle Conn Name
*  2 192.168.1.137      192.168.1.137         0     4 192.168.1.137

myRouter#disconnect 2
Closing connection to 192.168.1.137 [confirm]
myRouter#show sessions
% No connections open

While managing a device, you can see who is connected to the device using the show users command as shown below:

 

myRouter#show users

Line       User       Host(s)              Idle       Location

*194 vty 0     admin      idle                 00:00:00 10.1.10.228

195 vty 1     admin      idle                 00:00:00 10.1.10.18

The above output shows that two users are connected to the device using Telnet. The asterisks (*) sign denotes the connection where the show users command was executed. The first connection is using line 194 and vty line 0 and the second is using line 195 and vty line 1. It is possible to disconnect someone’s session from the device using the clear line <line number> command. In the output below, I have disconnected the second connection from the first session:

myRouter#show users
Line       User       Host(s)              Idle       Location
*194 vty 0     admin      idle                 00:00:00 10.1.10.10
195 vty 1     admin      idle                 00:04:12 10.1.10.10

Interface    User               Mode         Idle     Peer Address

myRouter#clear line 195
[confirm]
[OK]
myRouter#show users
Line       User       Host(s)              Idle       Location
*194 vty 0     admin      idle                 00:00:00 10.1.10.10

Interface    User               Mode         Idle     Peer Address