In this tutorial, we will guide you through the process of setting up and using ser2net
to remotely access a serial terminal on a Linux computer. This setup is particularly useful for managing embedded systems, IoT devices, or any device that communicates over a serial interface.
Prerequisites
- A Linux computer with a serial port (e.g.,
/dev/ttyS0
or/dev/ttyUSB0
). - Basic knowledge of Linux command-line operations.
- We will assume a Ubuntu/Debian style system, instructions might need adaptation for other distributions.
Installation
Installing Ser2net
ser2net
is a simple TCP-to-serial port redirector. To install ser2net
, use the following command:
sudo apt-get install ser2net
Getting started
ser2net
uses a configuration file to define the mappings. This configuration file can hold a large number of exposed connections, but we will stick to the minimal case of one here.
Create a Configuration File
Create the configuration file for ser2net
. The expected location is /etc/ser2net/ser2net.yaml
.
sudo nano /etc/ser2net/ser2net.yaml
Add Configuration Entries
Add entries to the configuration file to define the mappings. For example:
connection: &ttyUSB0
accepter: tcp,2000
options:
banner: mybox - ttyUSB0
connector: serialdev,/dev/ttyUSB0,115200n81,local
This entry maps TCP port 2000
to /dev/ttyUSB0
with a baud rate of 115200
, 8 data bits, no parity, and 1 stop bit. The banner
option displays a message when a connection is established.
Test ser2net
Start the ser2net
service:
sudo ser2net -d
This starts ser2net
in non-detached mode, so you can see eventual error messages. This is particularly helpful when working on the configuration file.
From a remote machine, use telnet
to connect to the exposed serial port:
telnet <linux_computer_ip or hostname> 2000
You should see the configured banner message and be able to interact with the serial port. telnet
can be closed by entering command mode with Ctrl-]
and then issueing quit
.
Permanently enable ser2net
Once you are done with setting the correct configuration up, you can have the ser2net
service started automatically. Enable ser2net
to start on boot:
sudo systemctl enable ser2net
And if you want to use it right away without rebooting, you can also start the service with:
sudo systemctl start ser2net
Accessing the serial terminal remotely
From a remote machine, use a terminal emulator like telnet
to connect to the Linux computer:
telnet <linux_computer_ip or hostname> 2000
Alternative tools are nc
or socat
, depending on the specific use case.
Further Resources
By following this tutorial, you should be able to set up and use ser2net
to remotely access a serial terminal on a Linux computer. This setup provides a flexible and powerful way to manage serial communications over a network.