Skip to content

This document is a WORK IN PROGRESS.
This is just a quick personal cheat sheet: treat its contents with caution!


sysctl

sysctl is a tool for examining and changing kernel parameters at runtime (package procps-ng). sysctl is implemented in procfs, the virtual process file system at /proc/.

Reference(s)

Table of contents


Config

Possible locations for sysctl configuration files are:

  • /etc/sysctl.d/*.conf
  • /run/sysctl.d/*.conf
  • /usr/local/lib/sysctl.d/*.conf
  • /usr/lib/sysctl.d/*.conf
  • /lib/sysctl.d/*.conf
  • /etc/sysctl.conf

Use

  • List all current kernel parameters:

    $ sysctl -a
    
    > See https://www.kernel.org/doc/html/latest/admin-guide/sysctl/index.html for the > documentation about all parameters.

  • List all current kernel parameters of a specific parameters group (e.g. net.ipv6):

    $ sysctl -a --pattern '^net.ipv6'
    
    > See https://www.kernel.org/doc/html/latest/admin-guide/sysctl/net.html for the > documentation about the whole net group.

  • Print a single/specific parameter (e.g. fs.file-max):

    $ sysctl fs.file-max
        > fs.file-max = 3270749
    

  • Apply changes from sysctl config file:

    $ sudo sysctl -p
    

  • Modify a specific kernel parameter (e.g. vm.swappiness):

    $ sysctl -w vm.swappiness=10
    

    The change takes effect immediately, but it is not persistent. After a system reboot, the default value is loaded.

    To set a parameter permanently, you will need to write the settings to the configuration file.

    Another way to change parameters is to write the settings to the files in the /proc/sys directory, e.g.:

    $ echo 1 > /proc/sys/net/ipv4/ip_forward
    


If this cheat sheet has been useful to you, then please consider leaving a star here.