Connecting to a Remote Serial Port over TCP/IP

Ever needed a way to communicate with some RS232 enabled device remotely? Well this is where socat, docker, and shellinabox comes in handy.

On a device that is connected via serial rs232 which will act as a host. Using the following install script one will have the environment setup:


export DOCKERHOST=$(ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v | awk '{ print $2 }' | cut -f2 -d: | head -n1)

sudo apt install docker docker-compose socat

install -d $HOME/shell

cat -> $HOME/shell <<-DOCKERFILE
	# Dockerfile
	FROM sspreitzer/shellinabox:latest
	RUN apt -y install netcat unzip zip unrar-free wget ca-certificates
	ENV SIAB_SHELL=netcat dockerhost:8888

cat -> $HOME/shell/docker/docker-compose.yml <<-DOCKERCOMPOSEYML
    			build: .
    			restart: always
				- 443:4200/tcp
				- "dockerhost:${DOCKERHOST}"

crontab -l | sed '[email protected] bash -c "cd $HOME/shell; sudo docker-compose up -d"' | crontab
crontab -l | sed '[email protected] sudo socat /dev/ttyUSB0,raw,echo=0 tcp-listen:8888,reuseaddr' | crontab
sudo reboot

What this does is install the needed tools, deploys shellinabox via docker so one can visit the IP of the terminal server (raspberry pi or such) and directly access what is connected via com port 1.

Suggested devices


Say one has some old dos systems that they’re running as a bbs, or even a few arduino projects. Instead of trying to build a custom esp232 modem one can use established systems to remotely access devices. This also can be extended into Ham, IoT, and SCADA hacking or just about anything where a serial comms connection is available.

Best part is if one includes zerotier or dyndns then they can create a qr code which on scanning connects directly to that remote machine via a browser.

Additional reading

1 Like

Almost forgot:

dos commands to setup a remote console:

; autoexec.bat
MODE COM1:9600,n,8,1

Besure to include a good menu program. Dos-shell or dosmenu are a good option: So is quarterdeck’s DESQview.

For unix machines there’s getty - and other systems one can use a BBS system of choice.

userport systems would need a custom board made:

prebuilt device available for $35 -

I would just VPN to my home router/firewall (Cisco) then ssh to my CCIE rack’s terminal server router where I could access every device’s serial console port. :slight_smile:

Network geeks do it differently than Linux geeks. :smiley:

1 Like

yeah that is the usual networking admin answer but not all of us are using rs232 for managing routers.

On Plan9 you can run TCP/IP over RS232 and RS232 over TCP/IP with ~zero effort too.:

Scada uses it too:
IoT as well:

Esp and BBSing use it nearly exclusively:

Ham does:

I came up with this as a solution for controlling old vintage/retro machines while also being a good solution for a LoRa, picosat, or APRS/ham lab instead of some ‘cult of the mac’ over engineered ios only design floating around.

Hell, the shell in a box part could just be dropped for haproxy and ftelnet.js instead.