What's the prescribed way to set Linux kernel runtime parameters? I've seen sometimes that people will set these in files such as /etc/rc.local.

Is this really the right way to do this?


You can use sysctl to set some of the kernel parameters, specifically the ones under /proc/sys. These can be set in the file /etc/sysctl.conf or added to a single file (the preferred method on some distro's such as Fedora) in the directory /etc/sysctl.d. On distros that have this directory it's meant for customization's.

excerpt from sysctl's man page

   sysctl - configure kernel parameters at runtime


You can get a partial list of what kernel parameters are currently set using this command:

$ sudo sysctl -a | head -5
abi.vsyscall32 = 1
debug.exception-trace = 1
debug.kprobes-optimization = 1
dev.cdrom.autoclose = 1
dev.cdrom.autoeject = 0

Making a change


Simply add rules to the file sysctl.conf.

# sysctl.conf sample
kernel.domainname = example.com
; this one has a space which will be written to the sysctl!
kernel.modprobe = /sbin/mod probe

You can also use the sysctl.conf command line to make edits to this file without having to edit it directly.

$ sysctl -w kernel.domainname="example.com"

After making any changes be sure to make them active.

$ sysctl -p


To add your override of this parameter simply put it in a file named similarly to the files that are already present in the /etc/sysctl.d directory.

$ ls -l /etc/sysctl.d
total 40
-rw-r--r-- 1 root root   77 Jul 16  2012 10-console-messages.conf
-rw-r--r-- 1 root root  490 Jul 16  2012 10-ipv6-privacy.conf
-rw-r--r-- 1 root root  726 Jul 16  2012 10-kernel-hardening.conf
-rw-r--r-- 1 root root 1184 Jul 16  2012 10-magic-sysrq.conf
-rw-r--r-- 1 root root  509 Jul 16  2012 10-network-security.conf

In a file named something like 99-myparam.conf.

$ more 10-console-messages.conf 

# the following stops low-level messages on console
kernel.printk = 4 4 1 7

Where the name of the parameter is on the left, and it's corresponding value is on the right.

See sysctl's man page for more details.

| improve this answer | |
  • 1
    Which distributions/init systems use /etc/sysctl.conf and /etc/sysctl.d? – Gilles 'SO- stop being evil' Jan 13 '14 at 2:41
  • @Gilles At the very least, systemd 207+ does not read from sysctl.conf any more, it requires sysctl.d. – Chris Down Jan 13 '14 at 3:11
  • @Gilles - Fedora is one. I have both those on my F19 system. – slm Jan 13 '14 at 3:14
  • @Gilles - I've made mention of this difference. I wasn't aware that it wasn't this case on other distros. – slm Jan 13 '14 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.