Glen Turner (vk5tu) wrote,
Glen Turner
vk5tu

Attaching to a router's serial console from Linux, or udev rules for USB serial adapters

Let's say you've got a modern Linux distribution and you want to step back in time and use it like a VT-100 terminal. For example, routers often have serial consoles. For that you need some cables, Minicom, and a serial dongle.

When you plug in the serial dongle Linux will give it a name like /dev/ttyUSB0 and then NetworkManager will probe it for a modem. This can suck:

  • The device at the other end of the cable may not appreciate being probed with AT modem command sequences.

  • If you also have a 3G modem plugged in then there will be a whole forest of ttyUSBs, and so you'll have to reconfigure Minicom with the correct serial port every time.

A udev rule can fix both of these things. In this example I'm using a Keyspan USA-19HS RS-232/USB dongle with USB identifier 06cd:0121. Adjust the following for your own results from lsusb.

Create a new file for your own udev rules, I like /etc/udev/rules.d/99-local.rules. Edit it to add:

KERNEL=="ttyUSB[0-9]*", SUBSYSTEMS=="usb", ATTRS{idVendor}=="06cd", ATTRS{idProduct}=="0121", SYMLINK+="router", ID_MM_PORT_BLACKLISTED=1

Now when you plug in the serial dongle Linux will give it a name like /dev/ttyUSB0. udev will create a symbolic link /dev/router to point to that name. udev will instruct NetworkManager not to probe the port.

Start Minicom in setup mode with sudo minicom -s and configure Minicom to use the serial port /dev/router, at 9600bps, 8 data bits, no parity, one stop bit, hardware handshaking, delete any dial strings. Save the configuration as router.

For every user who you want to use that serial connection, add them to the group dialout with a command like:

$ sudo usermod --append --groups dialout glen

Restart udev (sudo systemctl restart udev.service or sudo restart udev). Login again to grab your additional group membership (use id to display those).

When you want to use a RS-232 dongle to connect to the serial console of a router, then plug in the serial dongle and start Minicom with minicom router. No need to be root. No need to reconfigure Minicom depending if you plugged a 3G modem in first or not, no line noise from NetworkManager probing for a modem.

Errata

Always the way, you upgrade the massively old Linux box you've been using as a VT100 to find that everything has changed. For a serial dongle connected to a router's console port to have a stable name, to be usable by all, and to be ignored by ModemManager then /etc/udev/rules.d/99-local.rules should read like this on a recent distribution:

SUBSYSTEM=="tty", ATTRS{idVendor}=="06cd", ATTRS{idProduct}=="0121", GROUP="users", MODE="0660", SYMLINK+="router"
ACTION=="add|change", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="06cd", ATTRS{idProduct}=="0121", ENV{ID_MM_DEVICE_IGNORE}="1"

Note that I am also putting the device into the "users" group, so that anyone can access the serial dongle to the router.

After editing the file you can reload udev with the command udevadm control --reload-rules. You can see udev's view of things with udevadm info --query=all --name=/dev/router --attribute-walk.

Tags: linux
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments