Wednesday, October 9, 2019

Creating a Lab Terminal Server Using a Cisco Router

     In this post I will be setting up a terminal server for my networking lab using a Cisco 2811 router, an HWIC-16A card, and a Cisco octal cable.  Not only is this a handy thing to do when setting up a networking lab to study for your CCNA, CCNP, or any other networking exam, but it will also lead into my next post where I will be using a Raspberry Pi and some relays to remotely power-on and power-off individual routers and switches in my lab.

The Hardware


As I mentioned, I will be using a Cisco 2811 router, because the HWIC-16A card I am using only works with 2800, 2900, 3800, and 3900 series routers, and I just happen to have both lying around (some people collect stamps).  Cisco does make an HWIC-8A card that will also work with an 1800 model router if you are trying to save a little money.

The cable I will be using is an CAB-HD8-ASYNC, commonly referred to as an octal cable.  It has a Cisco proprietary connector on one end, and 8 RJ45 connectors on the other end, which will plug into the console ports of the individual routers and switches in the lab.

All of this can get a bit expensive, so I highly recommend checking out ebay, or any other online seller of used electronics before looking to purchase any of this new.  Of course, if you've already put together a networking lab, you've probably already found an affordable source for this sort of thing.

The last thing I will mention is that if you are following along with this tutorial, and you want your port numbers to match mine, you will want to put your HWIC-16A card in HWIC slot 0 on your router.  If you use a different slot, then your port numbers will vary, which is perfectly acceptable, but I just wanted to make you aware.

The Configuration


To simplify things I am going to start with a default configuration, so if you are following along, go ahead and wipe the nvram clean with a write erase, followed by a reload.  Since we are starting with no interfaces configured, we will need to do the initial configuration from the console port.  Obviously, feel free to use your own usernames, secrets/passwords, and IP addresses that suit your home network.

enable
conf t
line con 0
    logging synchronous
    exit
hostname Lab_Term_Serv
int fa 0/0
    ip addr 172.31.0.9 255.255.255.0
    no shut
    exit
username james secret CCNA
line vty 0 4
    login local
    transport output telnet
    exit
enable secret CCNA

Once you reach this point in the configuration, you can telnet in from a remote machine to finish the rest of the configuration.  Of course if it is just as easy for you to stay connected to the console port, that will work as well.

line 0/0/0 0/0/15
    transport input telnet
    exec-timeout 0 0
    no exec
    exit
int loopback0
    ip addr 172.30.1.1 255.255.255.255
    exit
ip host R1 2002 172.30.1.1
ip host R2 2003 172.30.1.1
ip host R3 2004 172.30.1.1
ip host R4 2005 172.30.1.1
ip host R5 2006 172.30.1.1
ip host Sw1 2007 172.30.1.1
ip host Sw2 2008 172.30.1.1
ip host Sw3 2009 172.30.1.1
logging monitor 7
end
copy run start


And that's it.  Typically when I post code or configuration I go heavy on the comments to explain exactly what each section does, but in this case, since we are creating a networking lab, I am assuming anyone following along has a basic understanding of Cisco IOS, and does not require a detailed explanation.  That being said, I did want to touch on just a couple of things.

First, I was not familiar with the line logging monitor 7 until I started using this setup, and realized I was not getting the console logging messages I would typically receive when connected to the console.  This command, similar to the terminal monitor command, allows those logs to be sent over a terminal session.  Seven is the highest level of logging, and this is what we want so that we will be sure to see any debugs we request during our labs.

Next, towards the end of the configuration, you will see seven lines starting with ip host R1 2002 172.30.1.1.  These lines create a shortcut to open each console connection by simply telnetting to the hostname (R1 in this case).  The value 2002 on this line represents the TCP port associated with that specific TTY line.  Depending on which port you plug your HWIC-16A card into, this port may vary.  To determine which port number you should use, you will need to look at the output of the show line command.


Here you can see the output of show line on my terminal server, and in the TTY column you can see the ports on my HWIC-16A card represented by 0/0/0 through 0/0/15.  Each one of those ports corresponds to a value in the LINE column.  In this case, 0/0/0 corresponds to 2, 0/0/1 corresponds to 3, and so on.  If you add 2000 to the value in the LINE column, you will get the corresponding TCP port number.  For instance, since 0/0/0 corresponds to 2, the TCP port will be 2002.  In this way you can determine the port numbers for your HWIC-16A connections regardless of which slot you use, or which router model you are using.

Connecting from the Terminal Server


To connect to the devices in our lab, we are actually using a reverse telnet session to log into the console.  Since we configured our terminal server with host names referring to the corresponding ports and a loopback IP address, and since using the hostname alone will imply the telnet command, all we need to do is type the hostname of the device to which we would like to connect.

R1

Provided that the octal cable end labeled P0 is plugged into Router 1 in our lab, the above command should result in giving us a prompt from Router 1's console.

Once we are done using Router 1 there are two ways to return to our terminal server.  To close the session completely we can simply type exit and we will be returned to our terminal server interface.

If we want to return to the terminal server interface without closing our session to Router 1, we will need to use <ctrl><shift>6, x.  That is to say, press and hold <ctrl>, then press and hold <shift>, then press 6 while still holding <ctrl> and <shift>.  Then let go of all three keys and press x.  Why did Cisco make the escape sequence this complicated?  It's hard to say.

Now you are back on your terminal server, but the session you established to Router 1 is still in effect.  In fact if you hit <enter> at the terminal server's prompt it will take you right back into Router 1.  To see the sessions you have open, use the following command:

show session

To restart any of these sessions you can simply type the line number of the session and you will find yourself back at the console of the corresponding device.  If you would like to disconnect a session, use the command disconnect followed by the line number of the session like so:

disconnect 1

If all this seems slightly tedious, and not an incredibly efficient way to navigate around your lab, I agree with you.  To me it is important to know how to navigate to your lab directly from the terminal server in order to test all connections and troubleshoot if necessary.  In the last section below I will show you how to connect directly to the devices in your lab without first connecting to the server.

Connecting to the Lab Directly


Now that we have a Terminal Server set up and working properly, we will find that we no longer need to log into the Terminal Server directly.  Instead we can use our reverse telnet to connect through the server, directly to the lab equipment.

If you are using Windows to connect to your Networking Lab, my favorite way to do so is to use PuttyCM (aka Putty Connection Manager) because it allows you to open an individual connection to every device in your lab with one click, and then use tabbed windows to switch between them.  Unfortunately PuttyCM is no longer maintained, and although there are still places to download it, I can't vouch for any of them, so I won't link them here.  If you are interested, a quick Google search will find it for you.

In lieu of Putty CM, plain old Putty will work just fine, or feel free to use the terminal emulator of your choice.  When you connect, use the IP address of your Terminal Server, select Telnet as your connection type, but change the port number to the TCP port determined above using the show line command.  You can use the host table you built on your Terminal Server as a reference.


To save time connecting to your lab in the future, you can name your sessions and save them so they can be quickly opened with a double-click in the future.  You can also open several Putty sessions at the same time so you can easily switch between devices in your lab.

Of course, if you are connecting to your lab from a Linux computer, you can connect directly from the terminal using the telnet command.  You can specify the port by typing it immediately following the IP address as shown in the image above.  You can then open several terminal windows at the same time to be able to easily switch between sessions.


Conclusion


And that's all there is to it.  You can now access all of the devices in your networking lab directly via their console ports.  If you have a VPN server on your home network, you can use that to connect to your networking lab remotely so you can practice or experiment from anywhere.  (Here is a link to my post on how to set up a VPN server on a Raspberry Pi if you are interested.)

In my next post, I will show you how I used a Raspberry Pi and some relays to remotely control the power to my networking lab.  This allows me to turn on/off my switches and routers individually, or as a group, so that I can work on my lab remotely without having to leave it powered up 24/7.

Until next time, have fun, and keep building!

No comments:

Post a Comment