How to build a Raspberry Pi Serial Console Server with ser2net

If you’ve ever built a Cisco CCNA lab or some other hardware lab that has serial console ports, there is a good chance you sat within a few feet of the gear with a serial cable to your computer while working on it. How fun was that?!?

Recently a friend started studying for the CCNA exam and I started thinking that there had to be a way to use a Raspberry Pi to put the console ports on the network. Sure you could log in to the pi, then run telnet from the pi, but what if I don’t want to login? Sure enough, there is a project called ser2net that does just that. So I ordered a multi-port serial adapter and dug out an old Pi2 B+ to make it happen!

The Hardware

You can probably use any Raspberry Pi model, so long as it has USB ports, I had a Raspberry Pi 2 B+ sitting around so that’s what I’m using. (Don’t forget a power supply and case too.)

You will also need a USB to serial adapter. I went with the UGREEN 4 port model that is pretty cheap. You could also do one or more single port adapters, but keep in mind the Pi’s limited USB power budget.

My Hardware setup

Lastly you will need Cisco Console cables, or EMC Serial Cables, or whatever cables are required for your device.

The Software

I’m using Raspbian, mostly right out of the box. In fact we only need to add one piece of software to make this project work.

To update your Pi and install ser2net use the commands below:

sudo apt update
sudo apt upgrade -y
sudo apt install ser2net -y

Serial Port discovery

Before we can configure ser2net we need to figure out where our serial adapters are listening. Normally serial ports are /dev/ttyS0 or ttyS1, but because we are using USB adapters the may show up as /dev/ttyUSB0 and ttyUSB1 etc.

Use this command to search for yours:

dmesg | grep tty

You’ll see something like this:

discovered USB to Serial ports

As you can see I have my 4 port adapter plugged in, as well as my Adafruit USB to TTL Serial Cable too. With this information we can configure our ser2net.conf file.

Configuration

When you install ser2net via apt it puts the configuration file in /etc. To edit it you can use nano with is already on your Pi.

sudo nano /etc/ser2net.conf

Inside you will find some default configuration lines at the bottom of the config file. We can easily edit these to meet our needs.

For my 4 port serial adapter, going to Cisco routers and switches (which use 9600 8N1 serial parameters), my file looks like this.

3000:telnet:600:/dev/ttyUSB0:9600 8DATABITS NONE 1STOPBIT banner
3001:telnet:600:/dev/ttyUSB1:9600 8DATABITS NONE 1STOPBIT banner
3002:telnet:600:/dev/ttyUSB2:9600 8DATABITS NONE 1STOPBIT banner
3004:telnet:600:/dev/ttyUSB3:9600 8DATABITS NONE 1STOPBIT banner

Here is a screenshot too (note that the ttyUSB4 is my adafruit adapter.

ser2net.conf for cisco hardware

So this configuration will let us telnet to our raspberry pi on the ports specified. Those telnet sessions will be forwarded to our serial ports.

So on my mac I can type

telnet raspberrypi.local 3000

It will connect me to whatever serial device is listening on /dev/ttyUSB0!

Conclusion

You can use this setup for anything that has a serial connection. IPMI servers, Routers, Switches, PLC’s, etc etc…

The only downside that I have seen, which isn’t a big deal in a lab, is that there is no authentication involved. So anyone who knows the connection parameters (telnet IPAddress Port) will have access to the serial device listening.

If security is a concern then I would just skip the ser2net program, and ssh into the pi, and run screen or cu directly to /dev/ttyUSB0 or something.

Happy Homelabing!

Share This Post

Leave a Reply