26

I'm setting up a console server and I need to determine the correct baud rate of my port. I'd like to do this from the command line, if possible. Does anyone know how?

thepocketwade
  • 1,525
  • 5
  • 16
  • 27

3 Answers3

34

setserial is Linux-specific, but you can also use the stty command (available on any Unix) to check the speed and other characteristics of any tty.

stty operates on its standard input, so stty < /dev/ttyXX will give you the information about that particular tty. Alternatively, if you're in a situation where you cannot set the standard input of stty, you can use the -F /dev/ttyXX option.

cjs
  • 1,355
  • 1
  • 12
  • 23
  • 10
    You may need to use `stty -F /dev/ttyXX` – Mark Lakata Oct 25 '12 at 21:47
  • 1
    Note that this doesn't tell you what a particular serial port *should be set to*, based on the actual baudrate of the data coming in, rather, it tells you what you currently _do_ have the baudrate set to, which could be the wrong baudrate. – Gabriel Staples Dec 29 '21 at 19:11
3

The program you're looking for is called "setserial".

http://linux.die.net/man/8/setserial

andrewd18
  • 874
  • 5
  • 8
  • 2
    Can you elaborate? E.g. what would an example command line be? Please respond by [editing (changing) your answer](https://serverfault.com/posts/30529/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Sep 27 '21 at 23:58
3

Since you mention a console server and this question is tagged with linux I will assume you are connecting to a linux server. The server must be configured to use a serial console so there are a couple of places to check.

The kernel setup involves adding the "console" parameter to the command line of your kernel. For example adding "console=ttyS0,9600" tells the kernel to send messages to the first serial port (/dev/ttyS0, COM1 in DOS/Windows terms) at 9600 baud. You can add this to the command line through your boot loader configuration. If using grub this will usually be a file called /boot/grub/grub.conf. Note that you can have multiple console parameters for traditional keyboard/video console (tty0) as well as serial (/dev/ttyS0). For exaxmple: "console=tty0 console=ttyS0,9600"

To provide a login prompt via serial you need to edit /etc/inittab and add/edit a line like the following. s0:12345:respawn:/sbin/agetty 9600 ttyS0 vt100 This line tells the agetty program to spawn a login prompt on /dev/ttyS0 at 9600 baud.

Note you will normally want to match the serial port and baud rate between the kernel and agetty setup. By checking the configurations above you should be able to determine the server baud rate.

  • Unless your Linux doesn't use inittab. My Fedora and Ubuntu systems use /etc/event.d/tty* and /etc/event.d/serial which are part of Upstart (http://en.wikipedia.org/wiki/Upstart). – Dennis Williamson Jun 23 '09 at 22:21