Dec 07

Log kernel messages on a remote machine in Linux (Ubuntu).

Netconsole can be used to transmit the kernel messages on the sender to the receiver. Netconsole is a kernel module that logs kernel printk messages over UDP allowing debugging of problems where disk logging fails.

Prerequisites -

  • IP address of the receiver
  • MAC address of the receiver
  • A port on the receiver
  • IP address of the sender
  • A port on the sender
  • Name of the network interface of the sender

Assumption -

Both sender and receiver are on the same gateway.

To get receiver’s MAC address, either do ifconfig -a on the receiver or do the following:

pet@sender:~$ ping -c 1 > /dev/null
pet@sender:~$ arp -n
 Address                  HWtype  HWaddress           Flags Mask            Iface            ether   08:00:46:d4:1d:82   C                     eth0

Netconsole can either be built-in in the kernel or can be added as a module. Follow the steps below to initialize netconsole at boot time.

Case 1: Netconsole is built-in in the kernel.

  • Add the following kernel boot-time parameter in etc/default/grub:
    netconsole = <local_port>@<sender_ip_addr>/<sender_interface>,<remote_port>@<receiver_ip_addr>/<receiver_mac_addr>
  • Reboot the machine.

Case 2: Netconsole has been built as a module.

  • Append “netconsole” in /etc/modules
  • Append the following in /etc/modprobe.d/netconsole.conf
    options netconsole netconsole = <local_port>@<sender_ip_addr>/<sender_interface>,<remote_port>@<receiver_ip_addr>/<receiver_mac_addr>
  • Reboot the machine.

On the sender side, do the following to set the level at which logging of messages is done to the console.

pet@sender:~$ dmesg -n 8

If the above is not set, netconsole will not transmit anything to the receiver.

On the receiver side to listen to the kernel messages, netcat or nc can be used. Depending on the Ubuntu version, one the following will work:

pet@receiver:~$ nc.traditional -ul -q -1 -p <remote_port>
pet@receiver:~$ nc -ul -q -1 <remote_port>

One can also use syslog-ng on the receiver side to listen to the messages.

For more info, check the netconsole page on Ubuntu wiki:


Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>