Serial Port Usage
Contents
Usage possibilities for serial ports in RouterOS
The most obvious (and default) usage is the serial console for RouterOS. On every RouterBoard or other system you will have a RouterOS login prompt. This is one of the ways to do the basic configuration on your RouterOS device after installation (i.e. at least give it an ip address or so).
There are other and more advanced uses for serial ports. I try to sum up those possibilities here. You can use RouterOS to access another device (like a switch, for example) that is connected through a serial cable
- directly from a RouterOS console or telnet/ssh login (i.e. "from within RouterOS")
- by opening a telnet/ssh session that will get you directly on this device (without having to login to RouterOS first)
- as if it were connected to a physical COM port of your PC
Preparations
First you have to have a free serial port to use for this. If you are on a device with only one serial port (like all RouterBoards, WRAP/ALIX boards etc.) you will have to disable the system console on this serial port:
/system console disable 0
This is better than removing this console, as RouterOS will recreate the console after the next reboot when you really remove it.
Attention: By doing this you will loose serial access to your RouterBoard! So please make sure that you have access by WinBox, SSH, mac telnet or the like!
Next you will have to configure your serial port according to the serial port settings of the connected device. Using the following command you will set your serial port to 19200 Baud 8N1. What settings you need to use depends on the device you connect.
/port set serial0 baud-rate=19200 data-bits=8 parity=none stop-bits=1
You can also try to let RouterOS guess the needed baud rate by setting
/port set serial0 baud-rate=auto
I personally did have mixed results with that and try to set fixed values here.
Now's the time to connect your device if not already done. Usually you will have to use a null modem cable (the same thing as a cross-over-cable for Ethernet). Now we're ready to go!
Accessing a serial device from within RouterOS
The easiest way is the serial-terminal command:
/system serial-terminal serial0
This will give you access to the device you connected to port serial0, like a VDSL switch or whatever you connected. Ctrl-A is the prefix key, which means that you will enter a small "menu" by pressing Ctrl-A. The Ctrl-A character will not be sent to your device! If you want to exit the connection to the serial device type Ctrl-A, then Q. This will return you to your RouterOS console. If you really want to send a Ctrl-A character to your serial device you have to type Ctrl-A two times.
Accessing a serial device directly by SSH / telnet / mac-telnet
If you want to access the device directly without logging into RouterOS first, use the special-login command: First create a new user for access to the serial device:!!
/user add name=serial password=secret group=read
Then connect this username to the desired serial port:
/special-login add user=serial port=serial0
Now when you connect to your RouterOS machine using SSH (or telnet/mac-telnet) and use the username/password of the user you just created, you will be connected to your serial directly.
One nice side effect of this is that you could give this login to someone else who can access the serial device, but not RouterOS itself. (Or, if connecting by WinBox, couldn't change anything.)
Acessing a serial device as if it were physically connected to your PCs' COM port
Perhaps you are using a software to access your serial device that can only talk to COM ports like COM1?
Want to use this to access your device when it's located somewhere else?
The usual way would be to purchase something like a LanTronix or Moxa serial server, but you can do this for free with RouterOS, too!
RFC 2217 defines a protocol to transfer data from/to a serial device over TCP. Combine this with a software driver on your PC that presents a "virtual COM port" that is connected to serial0 on your RouterOS machine over the network. Your done!
There are lots of software solutions to this, most commercial. One that works well with RouterOS in my experience is "Serial/IP COM Port Redirector" from Tactical Software (and no, I'm not affiliated with them anyhow ;-) ).
But there's also a free (like in beer) solution that you may even use commercially! It's named VSPE (virtual serial port emulator) and can be obtained from Eterlogic.
First, let's see how to configure the RouterOS part:
/port remote-access add port=serial0 protocol=rfc2217 tcp-port=10000
This will connect an incoming connection on TCP port 10000 to the port serial0.
Now on to the PC part. Install the VPSE software from Eterlogic and start it.
You will see a screen like this:
Clicking on the "Create new device" button will get you here:
Make sure you selected device type "Connector" in the drop-down and press "Next":
Now select a (unused) COM port number which should be your new virtual COM port and press "Finish". Make sure that the application you want to use to access this virtual port can open the COM port number you want to create here. Older applications often only can be configured to use COM1-COM4, so creating COM9 will mean getting yourself into trouble.
Verify that the virtual COM port you created (COM3 in the screenshot) is shown as "Ready":
Next, press the "Create new device" button again and select "TcpClient" as device type:
Press "Next". In the next screen you will have to enter the ip address of your RouterOS machine (192.168.1.254 in the screenshot) and the port number you configured above (10000 in our example). Also make sure that you select the virtual COM port we created just before in the "Source serial port" drop-down:
Clicking on "Finish" will end our work and present you with a screen like this:
If the status of your TCPClient device doesn't show "OK", you either have an error in your RouterOS config, or you cannot reach the configured port on the RouterOS machine from your PC (network cabling? routing? firewall? ...).
If everything went well, you can now start any software and use our freshly created COM3 (in the example) to access your serial device connected to the RouterOS machine. Even if this would be located on another continent!






