Updating Kernel Parameters

Use the sysctl command to update kernel system parameters that are defined in the /proc/sys virtual file system.

  1. Use the sysctl -w command to set the value for a kernel parameter.

    for example, to change the value of the net.ipv4.ip_forward setting to enabled, use the following command format:

    sudo sysctl -w net.ipv4.ip_forward=1

    Changes that you make in this way remain in force only until the system is rebooted.

  2. To make configuration changes persist after the system is rebooted, add them to the /etc/sysctl.d directory as a configuration file.

    Any changes that you make to the files in this directory take effect when the system reboots or if you run the sysctl --system command, for example:

    echo 'net.ipv4.ip_forward=1' | sudo tee /etc/sysctl.d/ip_forward.conf
    grep -r ip_forward /etc/sysctl.d
    /etc/sysctl.d/ip_forward.conf:net.ipv4.ip_forward=1
  3. To reset the system to use only the values that are configured to load at boot time, use the sysctl --system command.
    sudo sysctl --system
    * Applying /usr/lib/sysctl.d/00-system.conf ...
    net.bridge.bridge-nf-call-ip6tables = 0
    net.bridge.bridge-nf-call-iptables = 0
    net.bridge.bridge-nf-call-arptables = 0
    * Applying /usr/lib/sysctl.d/50-default.conf ...
    kernel.sysrq = 16
    kernel.core_uses_pid = 1
    net.ipv4.conf.default.rp_filter = 1
    net.ipv4.conf.all.rp_filter = 1
    net.ipv4.conf.default.accept_source_route = 0
    net.ipv4.conf.all.accept_source_route = 0
    net.ipv4.conf.default.promote_secondaries = 1
    net.ipv4.conf.all.promote_secondaries = 1
    fs.protected_hardlinks = 1
    fs.protected_symlinks = 1
    * Applying /etc/sysctl.d/99-sysctl.conf ...
    * Applying /etc/sysctl.d/ip_forward.conf ...
    net.ipv4.ip_forward = 1
    * Applying /etc/sysctl.conf ...
    

    Note that any configuration entries that you added to /etc/sysctl.d are read by the system and applied.