System and processes

The sysctl command

Reads or changes kernel parameters at runtime, the ones under /proc/sys.

Syntax

sysctl [-a] [-w] <clave[=valor]>Try it in the terminal →

Most useful options

-a, --allShows all parameters, except deprecated ones and those that must not be read
-w, --writeForces every argument to be a write. If one cannot be parsed that way, it reports an error
-n, --valuesShows only the value, without the key name. Handy in scripts
-N, --namesShows only the key names, useful with shell tab completion
-p, --load [archivo]Loads settings from a file. Without one, it uses /etc/sysctl.conf. With - it reads standard input
-e, --ignoreShows no error if the key is unknown
-r, --pattern <patrón>Applies or shows only the keys matching the extended regular expression
--systemLoads the settings from all system configuration files, in priority order

Copy-ready examples

$ sysctl -a --pattern forwardlists the keys whose name contains forward.
$ sysctl -n net.ipv4.ip_forwardreads the packet forwarding value, without the name. Read only.
$ sudo sysctl -w vm.swappiness=10changes the value on the running system, without rebooting. The change lasts until the next boot.
$ sudo sysctl -ploads /etc/sysctl.conf again, with no arguments.
$ sudo sysctl --systemloads all system configuration files, in the priority order of the manual.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
sysctl: cannot stat /proc/sys/vm/nokey: No such file or directoryYou read a key that does not exist on this kernel. It may be misspelled, or depend on a module that is not loaded yet.Search for the name with sysctl -a -r word and copy the exact key.
sysctl: "vm.nokey" is an unknown keyYou wrote to a key that does not exist on this kernel. It may be misspelled, or depend on a module that is not loaded yet.Search for the name with sysctl -a -r word and copy the exact key.
sysctl: permission denied on key "vm.swappiness"Writing a parameter requires administrator rights and it was run without them.Run the command again with sudo.

Typical mistakes

  • Changes made with -w are lost on reboot. To make them persist, write them to /etc/sysctl.conf or to a .conf file in /etc/sysctl.d/.
  • sysctl -p with no arguments reads only /etc/sysctl.conf. The files in /etc/sysctl.d/ are loaded with --system.
  • The base_reachable_time and retrans_time parameters are marked as deprecated in the manual, and sysctl does not allow changing them.

Differences from similar commands

  • cat /proc/sys/vm/swappiness: reads the same value unformatted. sysctl uses dotted names, though it also accepts slashes.
  • echo: writing with echo to a file under /proc/sys has the same effect, but sysctl accepts dotted names and reports keys that do not exist.

Security

Changing network or security parameters without knowing their effect can cut the connection or leave the machine more exposed. Note the original value before changing it.

Related commands

FAQ

What does sysctl do?

It shows and changes kernel parameters at runtime. The values are read from /proc/sys, where the kernel exposes them.

How do I make a change survive a reboot?

Write it in a .conf file inside /etc/sysctl.d/ and apply it with sudo sysctl --system. /etc/sysctl.conf is also read, last, so it overrides the others.

How do I find a parameter when I do not know its exact name?

With sysctl -a -r word, which filters the keys with a regular expression. For example, -r forward shows the ones related to forwarding.

More System and processes commands

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course