loader-logo
Packet6 is now a Juniper Networks partner!

Configuring Your Raspberry Pi As A Console Server

You get very excited once you get your own physical lab of routers and switches going. You just can’t wait to start managing and configuring switchport security, spanning-tree, etc. And then you get tired of having to move the console cable from one switch to the other. And you don’t have the ability to play with your lab remotely. Ugh.

Initially, I was going to buy into some sort of console server. Either utilize an old 2500 router or look at OpenGear. But why not use an RPi which would cost less than $100! That just made me happy. And from there I could access my lab anywhere!

My tutorial is very similar and I’ve included my experience below.

What you will need:

I purchased my USB to serial cable on Amazon. Wasn’t cheap but it works.

USB to Serial

To get started, I installed Raspbian. Download the latest Raspbian image and extract the zip file. You can use win32diskimager-v0.9-binary to load the image to your SD card.

Go through the initial setup of Raspbian and be sure to enable SSH. Before accessing the RPi server remotely, I had to configure the Ethernet interface:

sudo nano /etc/network/interfaces

This is my following static configuration:

iface eth0 inet static
address 10.1.10.250
gateway 10.1.10.1
netmask 255.255.255.0
network 10.1.10.0
broadcast 10.1.10.255

Save that sucker and reboot for good measure

sudo reboot

I’d like to change the hostname from raspberrypi to CONSOLE:

sudo nano /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.1.1 CONSOLE

Then modify the hostname file:

sudo nano /etc/hostname
CONSOLE

Now moving on to the actual console portion of this project. We’ll use Ser2net which allows you access the serial ports via telnetting into the RPi.

wget http://downloads.sourceforge.net/project/ser2net/ser2net/ser2net-2.9.1.tar.gz
 tar -xzvf ser2net-2.9.1.tar.gz
 cd ser2net-2.9.1/
 ./configure
 make
 sudo make install
 make clean

Now lets find out where our USB to Serial is connected:

pi@CONSOLE ~ $ dmesg | grep tty
 [ 0.000000] Kernel command line: dma.dmachans=0x7f35 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708.boardrev=0xe bcm2708.serial=0x43e1602e smsc95xx.macaddr=B8:27:EB:E1:60:2E sdhci-bcm2708.emmc_clock_freq=100000000 vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
 [ 0.000000] console [tty1] enabled
 [ 0.585230] dev:f1: ttyAMA0 at MMIO 0x20201000 (irq = 83) is a PL011 rev3
 [ 0.916712] console [ttyAMA0] enabled
 [ 6.574040] usb 1-1.3: FTDI USB Serial Device converter now attached to ttyUSB0
 [ 7.049168] usb 1-1.3: FTDI USB Serial Device converter now attached to ttyUSB1
 [ 7.232239] usb 1-1.3: FTDI USB Serial Device converter now attached to ttyUSB2
 [ 7.392448] usb 1-1.3: FTDI USB Serial Device converter now attached to ttyUSB3

My RPi recognized all the connectors but the actual device is connected to ttyUSB0.

Let’s edit the ser2net configuration to get things going. The following is my configuration for each serial connection:

sudo nano /etc/ser2net.conf

BANNER:banner:CONSOLE LAB Terminal Server TCP port p device d serial parms srn

TRACEFILE:tr1:/var/log/ser2net/p-Y-M-D-H:i:s.U
4001:telnet:0:/dev/ttyUSB0:9600 8DATABITS NONE 1STOPBIT banner tr=tr1 timestamp

TRACEFILE:tr2:/var/log/ser2net/p-Y-M-D-H:i:s.U
4002:telnet:0:/dev/ttyUSB1:9600 8DATABITS NONE 1STOPBIT banner tr=tr2 timestamp

TRACEFILE:tr3:/var/log/ser2net/p-Y-M-D-H:i:s.U
4003:telnet:0:/dev/ttyUSB2:9600 8DATABITS NONE 1STOPBIT banner tr=tr3 timestamp

TRACEFILE:tr4:/var/log/ser2net/p-Y-M-D-H:i:s.U
4004:telnet:0:/dev/ttyUSB3:9600 8DATABITS NONE 1STOPBIT banner tr=tr4 timestamp

ser2net-config
Save that file and lets make sure Ser2Net starts up automatically:

sudo nano /etc/rc.local

Add the following above exit 0

/usr/local/sbin/ser2net -n -c /etc/ser2net.conf

Create a log directory for ser2net sessions:

sudo mkdir /var/log/ser2net

The ser2net.conf file follows the following format:

<TCP port>:<state>:<timeout>:<device>:<options>

The Banner statement follows this format:

BANNER:<banner name>:banner
This will create a banner, if the banner name is given in the
options of a line, that banner will be printed. This takes the
standard “C” x characters (r is carraige return, n is newline,
etc.). It also accepts d, which prints the device name, p,
which prints the TCP port number, and s which prints the serial
parameters (eg 9600 N81), and a large number of date related
items. See the man page for details.. Banners can span lines if
the last character on a line is ”. Note that you *must* use
rn to start a new line.

The TRACEFILE statement creates a log for each session, as you can see here:

pi@CONSOLE /var/log/ser2net $ ls
 4001-2013-Nov-11-10:05:58.981929

What does the log look like?

pi@CONSOLE /var/log/ser2net $ sudo cat 4001-2013-Nov-11-10:05:58.981929 4001-2013-Nov-11-10:05:58.981929
 2013/11/11 10:05:58 OPEN (x.x.x.x:57481)
P1-CORE-SW1>
 P1-CORE-SW1>en
 Password:
 Password:
 P1-CORE-SW1#
 P1-CORE-SW1#conf t
 Enter configuration commands, one per line. End with CNTL/Z.
 P1-CORE-SW1(config)#
 P1-CORE-SW1(config)#int f0/1
 P1-CORE-SW1(config-if)#
 P1-CORE-SW1(config-if)#switchport acc vlan 10
 % Access VLAN does not exist. Creating vlan 10
 P1-CORE-SW1(config-if)#
 P1-CORE-SW1(config-if)#exit
 P1-CORE-SW1(config)#
 P1-CORE-SW1(config)#exit
 P1-CORE-SW1#
 P1-CORE-SW1#wr
 Building configuration...
 [OK]
 P1-CORE-SW1#
 P1-CORE-SW1#
 *Mar 4 20:13:49.321: %SYS-5-CONFIG_I: Configured from console by console
 P1-CORE-SW1#2013/11/11 10:05:58 OPEN (x.x.x.x:57481)
P1-CORE-SW1>
 P1-CORE-SW1>en
 Password:
 Password:
 P1-CORE-SW1#
 P1-CORE-SW1#conf t
 Enter configuration commands, one per line. End with CNTL/Z.
 P1-CORE-SW1(config)#
 P1-CORE-SW1(config)#int f0/1
 P1-CORE-SW1(config-if)#
 P1-CORE-SW1(config-if)#switchport acc vlan 10
 % Access VLAN does not exist. Creating vlan 10
 P1-CORE-SW1(config-if)#
 P1-CORE-SW1(config-if)#exit
 P1-CORE-SW1(config)#
 P1-CORE-SW1(config)#exit
 P1-CORE-SW1#
 P1-CORE-SW1#wr
 Building configuration...
 [OK]
 P1-CORE-SW1#
 P1-CORE-SW1#
 *Mar 4 20:13:49.321: %SYS-5-CONFIG_I: Configured from console by console
 P1-CORE-SW1#pi@CONSOLE /var/log/ser2net $

Test out your console server. My console server IP address is 10.1.10.250. The ports I have configured for each console connection is 4001, 4002, 4003, 4004, respectively.

telnet 10.1.10.250 4001
 CONSOLE LAB Terminal Server TCP port 4001 device /dev/ttyUSB0 serial parms 9600 N81
P1-CORE-SW1#
 P1-CORE-SW1#

Caveats

I only noticed one thing. After consoling in, each new line is done twice. So far I haven’t seen it submit any commands twice but I’m still looking into why this is happening.

My Setup

raspberry pi console server

-1 Points


6 thoughts on “Configuring Your Raspberry Pi As A Console Server”

  1. John says:

    works great. THANKS!
    I followed the directions and it worked great.

  2. Malcolm Kelly says:

    Does the mapping of TTYUSB* to the actual device stay the same after a reboot? I found that deviceA would by ttyUSB0 and deviceB would be ttyUSB1. But if you restart there’s a 50/50 chance they’ve swapped around.

    1. Hi Malcom,

      I’ve had the mapping actually stay the same after reboot with the configuration I have. Now I haven’t tried it with the new Raspberry Pi’s. I’ll have to test that out once I get a new one.

  3. viju says:

    Hi Rowell Dionicio,

    Thanks for your post. I am following your steps for serial mapping in raspberry pi2. Actually I am new to linux and ser2net concept. Now I have created a ser2net.conf file inside /etc. I restarted ser2net and trying to access from my host PC but its failed.

    I have copied my ser2net.conf file here. If you have any idea please let me know.Thanks.

    BANNER:banner1:this is ser2net TCP port p device d serial parms srn

    # Don’t do this by default

    #CONTROLPORT:23

    2000:telnet:20:/dev/ttyUSB0:115200 8DATABITS NONE 1STOPBIT banner

    2001:telnet:20:/dev/ttyUSB1:115200 8DATABITS NONE 1STOPBIT banner

  4. viju says:

    Wow… works great.. Thanks for ur post. 🙂

  5. Nawir says:

    I want to use ssh instead of telnet to the raspbeery, so that
    ssh ip:2001=usb com1
    ssh ip:2002=usb com2
    usb console (not serial console) connected to Cisco or Aruba
    Is that possible

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.