Introduction
Have you ever had to drag your laptop with a serial port and cable into an extremely loud, freezing cold (or boiling hot), data center to program a new network device such as a router or firewall? In the time it takes to find the right drivers and COM port for the USB Serial Port adaptor you can make a small network based serial port console server for around $100. This allows you to do the same work on up to 4 devices from anywhere with a network connection.
Don’t be like this guy when you could be working remote over a vpn!
This blog post shows how to use a Raspberry Pi 3 single board computer (SBC) as a network based serial port console server. Connect the Raspberry Pi to an Ethernet or wireless network then use SSH or telnet to open a terminal window. Since the SBC runs a real 64 bit Linux operating system normal applications such as IPERF3, NMAP, and SCREEN work just fine.
Total project cost depends on what parts you already have and what you need to purchase. It takes around 2 hours to download the latest operating system image and copy it to the flash chip during which time you can build the kit and get everything ready.
Alternatives
There are many popular Network Serial Port Console servers available on eBay and Amazon for hundreds of dollars. They have limited feature sets with closed operating systems and cannot be upgraded or expanded.
- $360 – https://www.amazon.com/4-Port-Serial-Console-Terminal-B095-004-1E/dp/B003ELL2KO
- $115 – http://www.ebay.com/itm/B-B-1-Port-RS-232-Mini-Ethernet-Serial-Server-/381717379494
- $15 – use a Pine 64 SBC instead of the Raspberry Pi 3 – https://www.pine64.org/?page_id=1459
Bill of Materials
Here is the list of parts (BOM) needed to complete the build out of the project.
NOTE: a reliable power supply and Micro SD Flash Memory Card are important to the stability of this solution. Skimping on these two items could cause unplanned trips to the data center for troubleshooting this solution which is supposed to save you time, not make things worse.
- Raspberry Pi 3 ~$40
- Case for Raspberry Pi 3 ~ $10 (Optional but recommended)
- Micro SD Card – 8GB or larger ~$20 (get an enterprise grade “type 10” flash chip with fast read write speeds)
- Micro SD to SD Card adapter for your computer ~$10 (used to transfer the OS image)
- USB to Serial Port adapter(s) ~$15 (up to 4 can be used simultaneously if needed)
- USB Power supply (or PoE option below)
- MicroUSB to USB type A power cable ~$5 (same type use by most android phones)
- 5-10 Watt USB Power Supply Adapter ~$5 (2.5 Amps recommended for fully loaded setup) https://www.adafruit.com/products/1995 or…
- IEEE 802.3af Micro USB Active PoE Splitter Power Over Ethernet 48V to 5V 2.4A ~$10
- An “admin” computer to use for testing and setup – Mac, Windows, Linux
- For initial setup you would also need the following:
- HDMI cable
- HDMI capable display monitor 1080p
- USB Keyboard
Setup Process
Follow these steps to build the solution:
- Obtain all the needed components in one place to be assembled later.
- NOTE: this process works for many other SBC besides just raspberry pi – see some here: https://wiki.debian.org/RaspberryPi#Should_I_buy_a_Raspberry_Pi.3F
- For example: here is a Rock64 from Pine for USD$20 on Amazon that runs latest Debian with 4K HDMI support.
- Download the Operating System image to your admin computer.
- Open a web browser to: https://wiki.ubuntu.com/ARM/RaspberryPi and download the latest version. Be sure to check the SHA-256 checksum.
- Insert the MicroSD card into the admin computer.
- Checking microSD Card performance and check whether is counterfeit:
– H2testw 1.4 – Gold Standard In Detecting USB Counterfeit Drives
– F3 – an alternative to h2testw
This will help determine if the Micro SD Card is worth using. - Copy the OS image to the MicroSD card.
- The image file size is over 4.3GB so depending on the write speed of the MicroSD card this can take an hour or so.
- Open a terminal command line interface on the admin computer.
- Here are the steps for Mac OS:
diskutil list diskutil unmountDisk /dev/disk4 sudo dd bs=1m if=~/Downloads/ubuntu-16.04-preinstalled-server-armhf+raspi3.img of=/dev/disk4
Press Ctrl-t to monitor copy progress.
- Instructions for other Operating Systems and images can be found here: https://www.raspberrypi.org/documentation/installation/installing-images/README.md
- While the copy process takes place complete the following…
- Remove the Raspberry Pi from the box and assemble with the case.
- Connect the Raspberry Pi unit to the following:
- Local Area Ethernet Network
- HDMI display
- USB keyboard
- Turn on the display.
- When the copy process on the Admin computer completes you can remove the MicroSD card from the adapter.
- Insert the MicroSD card into the Raspberry Pi 3.
- Use the Micro USB cable to connect the Raspberry Pi 3 device to the power adapter.
- The Raspberry Pi 3 will boot up. You should see the login prompt on the display.
- Login with user and pass ubuntu/ubuntu.
- Run ifconfig to see the local assigned IP address. This assumes there is a DHCP server on the LAN. You can also assign a static IP address if needed.
- You can also use arp from your admin computer to find the IP Address: https://www.raspberrypi.org/forums/viewtopic.php?t=74176
- Open a secure shell session from your admin PC to the IP Address.
- Update the Raspberry Pi and install the tools you need:
sudo apt-get –y update sudo apt-get –y upgrade sudo apt-get –y install iperf3 nmap sendemail
- Note the Ethernet MAC address and make a label to identify the Raspberry Pi 3 when it’s being used in the field. You may want to note the default password and other contact info on the label as well.
- Optionally: Here’s a script that can email you the IP Address when the Raspberry Pi boots up. Edit /etc/rc.local and add a link to this file there.
#/bin/sh now=$(date) IPADDRESS=$(/sbin/ifconfig eth0 | sed -n 's/.*inet addr:\([^ ]*\).*/\1/p') MACADDRESS=$(/sbin/ifconfig eth0 | sed -n 's/.*Link\([^ ]*\):*/\1/p') IPADDRESS="$IPADDRESS\n - $now \n -$MACADDRESS" echo "RaspberryPi3 IP address:\n - $IPADDRESS " | sendemail -o tls=yes username=iben.rodriguez@gmail.com password=qdfqraugzundgjzn -s smtp.gmail.com:587 -f iben.rodriguez@gmail.com -t raspberrypi3@ibenit.com -u "raspberrypi3 IP Address" -q
Here is an example of what the email looks like:
RaspberryPi3 IP address: - 192.168.123.456 - Mon Nov 7 01:15:14 UTC 2016 - encap:Ethernet HWaddr b8:27:eb:12:34:56
- Once the setup steps are completed you can unplug everything and move the Raspberry Pi 3 device to its operational location in the field.
Operating Instructions
Once you have everything ready you can move the solution into place where the device with the serial port resides. For example: a data center with racks of network equipment that needs to have its initial networking configuration applied or changed. The Raspberry Pi 3 has 4 USB ports that can each be used with a standard USB to RS-232 Serial Port adaptor. With a USB hub you could connect even more serial port adapters if needed.
- Connect the serial ports to the serial port adaptors with the cables you’d normally use with your laptop.
- Connect the USB to RS-232 serial port adaptors to the Raspberry Pi 3.
- Make sure the Micro SD Card with the configured Operating System image is seated properly in the Raspberry Pi 3.
- Use the MicroSD USB cable to connect the Raspberry Pi 3 to the power supply adaptor.
- Based on the setup steps above you should know how to find the IP address using the MAC address and the DHCP server, ARP, or the email script.
- Using the IP address of the Raspberry Pi you can now establish an ssh secure shell session from your admin workstation.
ssh ubuntu@192.168.123.456
- Login with the user name and password established during the setup steps.
ubuntu@192.168.123.456's password: P@ss!23456789
- Find the device path to the USB Seral Port(s) with this command:
ls -al /dev/ttyU* crw-rw---- 1 root dialout 188, 0 Nov 6 02:26 /dev/ttyUSB0
With multiple USB to Serial adaptors you will see many tty entries. See this post for more details on this: http://raspberrypi.stackexchange.com/questions/12246/why-does-usb-port-enumeration-change
- Use the “screen” application to connect to the USB Serial Port
screen /dev/ttyUSB0
- Press the enter key to wake up the console device and do your work.
- To quit the screen app, type CTRL-A, then \.
- You can also use the Raspberry Pi 3 as a remote linux administration workstation with commands such as iperf3 and nmap.
USB Device Power Usage
Run this command to see the maximum power utilization budget of the USB devices plugged into your Raspberry Pi 3.
ubuntu@ubuntu:~$ lsusb -v|egrep "^Bus|MaxPower" Bus 001 Device 006: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port MaxPower 100mA Bus 001 Device 005: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port MaxPower 100mA Bus 001 Device 004: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC MaxPower 44mA Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter MaxPower 2mA
Obviously, the more USB devices you connect the more power you will need. Adjust the capacity of the USB power supply adapter accordingly.
Next Steps
On my wishlist of things to try next:
- Setup an LCD Display “hat” to show the IP Address and control basic functions: https://www.adafruit.com/products/2455
- Test PoE adapter – I’ve ordered one off the internet and will update with results.
- Try a USB hub to see how many USB to Serial adapters can be used simultaneously. USB specification theoretically supports up to 128 devices. Thanks to Wim van Laarhoven for sharing this concept:
http://www.uugear.com/portfolio/make_the_crazy_25_port_usb_hub_with_uugear_hub/ - Write some scripts to do the setup work for us. We are still spending hours with putty ssh sessions to login to the new devices over serial – configuring ip addresses, downloading firmware, etc. It would be great to be able to use a runbook automation tool like StackStorm to take care of this for us: https://stackstorm.com/
- Tomer Bar-Shlomo also shared the following options that would be interesting to try out…
- http://www.up-board.org/up/specifications/
- https://store.particle.io/collections/frontpage
- https://www.pine64.org/?product=pine-a64-board-2gb 4GB DDR3L-1600
- https://www.kickstarter.com/projects/874883570/marvell-espressobin-board <– this Marvell board looks super promising with inbuilt GigE switch, 802.11AC WiFi, and SATA interface we could build a full blown super small yet powerful Nagios NRMS probe.
Raspberry Pi 3 Specifications
Raspberry Pi 3 Model B | |
Release date | 29 February 2016 |
Introductory price | US$35 |
Operating system | Raspbian Ubuntu MATE Snappy Ubuntu Core Windows 10 IoT Core[1] RISC OS Debian Arch Linux ARM |
System-on-chip used | Broadcom BCM2837 |
CPU | 1.2 GHz 64/32-bit quad-core ARM Cortex-A53 |
Memory | 1 GB LPDDR2 RAM at 900 MHz[2] |
Storage | MicroSDHC slot |
Graphics | Broadcom VideoCore IV at higher clock frequencies (300 MHz & 400 MHz) than previous that run at 250 MHz |
Power | 800 mA (4.0 W) |
Website | raspberrypi.org |