Screen command set baud rate for terminal communication

See all UNIX related articles/faq
I need to create router or network switch configuration via a console port such as COM1 (ttyS0 under Linux). How do I use the screen command for a serial terminal emulator network with different baud rates under UNIX or Linux operating systems?

See all GNU/Linux related FAQ
Screen command provides different window types. The first parameter to the screen command defines which type of window is created. If a tty name (e.g. “/dev/ttyS0”) is specified as the first parameter to the screen command, the window is directly connected to this device. An optional parameter is allowed consisting of a comma-separated list of flags in the notation as follows.
Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Linux or Unix terminal
Category Network Utilities
OS compatibility BSD Linux macOS Unix
Est. reading time 3 minutes

Screen Command: Set Baud Rate

The syntax is:
$ screen /dev/ttySX baud_rate,cs8|cs7,ixon|-ixon,ixoff|-ixoff,istrip|-istrip
## OR ##
$ screen /dev/{console_port} 115200

Where,

  • /dev/ttySX: Linux serial port (e.g., /dev/ttyS0 [COM1] )
  • baud_rate: Usually 300, 1200, 9600 (default), 19200, or 115200. This affects transmission as well as receive speed.
  • cs8 or cs7: Specify the transmission of eight (or seven) bits per byte.
  • ixon or -ixon: Enables (or disables) software flow-control (CTRL-S/CTRL-Q) for sending data.
  • ixoff or -ixoff: Enables (or disables) software flow-control for receiving data.
  • istrip or -istrip: Clear (or keep) the eight bit in each received byte.

How to list serial ports under Linux

We use the dmesg command as follows:
$ dmesg | grep tty ## use grep command/egrep command as filter ##
$ sudo setserial -g /dev/ttyS[0123]

/dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4
/dev/ttyS1, UART: 16550A, Port: 0x02f8, IRQ: 3
/dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4
/dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3

Installing screen

Before we can use screen to connect to the serial console install it as per your version of Linux/Unix system:
## Debian/Ubuntu use apt command/apt-get command: ##
$ sudo apt install screen
## RHEL/CentOS/Oracle Linux users use the yum command ##
$ sudo yum install screen
## Fedora Linux users try the dnf command ##
$ sudo dnf install screen

Setting up baud rate with screen command on Linux or Unix

In this example, I’m connecting to my Soekris based embedded router using /dev/ttyS0 with 19200 baud rate and cs8:
$ screen /dev/ttyS0 19200,cs8

Fig.01: Screen command set baud rate for terminal communication

Fig.01: Screen command in action

Using screen to connect to the serial console with 300 baud rate

We set a different baud rate as follows:
$ screen /dev/ttyS1 300

How Do I See My Serial Port Status and Info?

Simply type CTRL + A + i

Fig.02: Getting terminal info

Fig.02: Getting terminal info

How Do I Exit From the Screen Session?

To close the screen session after you finish the router / switch configuration, press CTRL + A + k. To kill all screen session press CTRL + A + \. See our quick screen command tutorial for more information.

Conclusion

You learned how to use screen command to set up baud rate and other settings for serial communication with routers and other devices. See

Also, do read the following manual pages using the man command or help command:
$ man screen

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

2 comments… add one
  • Reza Aug 25, 2020 @ 22:56

    Great quick article, to the point. Used it as a reference. Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.