Linux – Prevent kernel messages from appearing in dmesg

dmesgkernellinuxlogging

Is it possible to prevent kernel messages from appearing in dmesg output?

E.g. I am running software that terminates PPPoE tunnels. One of the features it provides is the ability to set custom interface names.

However this results in messages in dmesg such as:

... 
[Mon May 28 09:50:06 2018] ifname.3: renamed from pppoe3 
[Mon May 28 11:07:40 2018] ifname.4: renamed from pppoe4 
[Mon May 28 11:11:37 2018] ifname.5: renamed from pppoe5 
[Mon May 28 11:18:26 2018] ifname.6: renamed from pppoe6 
[Mon May 28 11:40:46 2018] ifname.7: renamed from pppoe7
...

I tracked the function responsible for it to be netdev_info:
https://github.com/torvalds/linux/blob/v4.16/net/core/dev.c#L1204

The problem with these messages it is that they fill the buffer and override any other important messages (driver crashes, iptable warnings, etc.).

Is it possible to supress this specific message from appearing in dmesg output?

I tried setting sysctl kernel.printk but it seems to have no effect, and messages appear in dmesg output regardless of the settings.

Thank you.

Best Answer

Well that function is netdev_info is printing kernel messages via printk at the INFO level. I believe you can adjust your kernel.printk to control the level of messages that actually get logged. So you could adjust downwards from a level of INFO to the less noisy WARN or ERR levels.

I generally like to go with this 3 4 1 3 as a default

# /etc/sysctl.d/printk.conf
# Uncomment the following to stop low-level messages on console
kernel.printk = 3 4 1 3

See these links for more details about kernel.printk

This will suppress more then just that specific message. If you have other information being logged at the INFO level that you actually want or need to see, this may not be a good solution.

If you only care about what is getting logged into you syslog managed logs, then you should be able to apply filters depending on what syslog daemon you are running.