Create your own Serial Terminal Server

Have you ever had the need to have a terminal server to access your serial devices?  Maybe it’s a Cisco switch, a Juniper router, maybe some HP equipment.  If it is accessed through a serial connection, you can make your own Linux-based serial terminal server, without having to purchase OpenGear or Perle, or building a Cisco terminal access server from an old 2500 octal cable.  All you need is a Linux system, and some serial ports.

Now-a-days, 9-pin serial ports are hard to come by, even on today’s desktop systems.  Even if you are lucky to find an older system, chances are, you’ll have at most, 2 ports.  Here is where USB-to-Serial converters come into play.  Buy some, and plug them in.  Linux will recognize them, and create the serial devices for them.  Don’t have enough USB ports?  Buy a 10-port USB hub! :)

Materials:

  • TRENDnet TU-S9 USB-to-Serial adapter – Ebay – $9.00 new
  • CentOS 5.8 desktop system

Step 1:  Install SER2NET in CentOS/RHEL.  This is a proxy service that allows your network telnet sessions to be redirected to locally attached serial devices

  1. Install Extra Packages for Enterprise Linux (EPEL)

    1. For CentOS/RHEL 5.x

      1. rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
    2. For CentOS/RHEL 6.x

      1. rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
  2. Install ser2net

    1. yum install ser2net

Step 2:  Identify your serial adapters in CentOS

This seems to be a bit of a frustration to some users.  Finding *which* USB port goes to which device.  There are a couple of ways to do this, but the easiest is to plug in one-at-a-time and identify what the Operating System identified it to be.  As you plug in your usb device, within a second or two, you can run the following command:

 

  dmesg | grep tty

This will pull up all the messages associated with the serial ports.  The last line would be the one you just added:

 

     [root@sys1 ~]# dmesg | grep tty 
                serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A 
                00:07: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A 
                usb 4-1: pl2303 converter now attached to ttyUSB0 
                usb 4-2: pl2303 converter now attached to ttyUSB1 
                usb 3-1: pl2303 converter now attached to ttyUSB2 
                usb 2-2: pl2303 converter now attached to ttyUSB3 
                usb 3-2: pl2303 converter now attached to ttyUSB4 

In this case, the last device I added was attached to “ttyUSB4″, which would make the virtual device /dev/ttyUSB4 used in the configuration steps below.

Step 3:  Configure ser2net

The configuration files are located in /etc/ser2net.conf.  Here is a snippet of my configuration:

NOTE: The “##” lines define comments, and are not needed

## This defines a banner called "cisco-sw1". Places some line breaks, tells me a message, and the device I'm connected to
BANNER:cisco-sw1:\r\n\r\n\r\nYou are connected to C-SW1 on device \d \r\n\r\n 
BANNER:cisco-sw2:\r\n\r\n\r\nYou are connected to C-SW2 on device \d \r\n\r\n 
BANNER:cisco-sw3:\r\n\r\n\r\nYou are connected to C-SW3 on device \d \r\n\r\n 
BANNER:juni-sw1:\r\n\r\n\r\nYou are connected to J-SW1 on device \d \r\n\r\n


## This creates a telnet port 4001, with no timeout, to go to /dev/ttyS0 with a speed of 9600 baud and use the banner named "cisco-sw1"
4001:telnet:0:/dev/ttyS0:9600 cisco-sw1 
4002:telnet:0:/dev/ttyUSB0:9600 cisco-sw2
4003:telnet:0:/dev/ttyUSB1:9600 cisco-sw3 
4004:telnet:0:/dev/ttyUSB2:9600 juni-sw1

 

The BANNER is optional, but it tells me what I’ve connected to, once I establish my telnet session.  Be sure to restart ser2net service after changing your configuration file! “service ser2net restart

So, now, I just: “telnet <ip of your server> 4001″ to gain access to the console port of that switch/router.  See below for tweaks.

 

Tweaks:

So, you want to use this in your production environment?  Using Telnet may not be the best way, unencrypted passwords/text and all.  Just use SSH into your system, and telnet to the local host port:

 

     telnet localhost 4001

 

Don’t want to remember all those ports?  Write up a quick alias:

 

     alias SW1="telnet localhost 4001"
        alias SW2="telnet localhost 4002"

 

If you don’t remember what you called an alias, because you are a slacker and haven’t console’d in awhile, just use the “alias” command by itself, and it will list all the entries for you.

 

Share This Page : Share on TwitterShare on FacebookShare on GooglePlusShare on PinterestShare on Linkedin