sysctl

From RaySoft

sysctl is used to modify kernel parameters at runtime. The parameters available are those listed under /proc/sys. procfs is required for sysctl support in Linux. You can use sysctl to both read and write sysctl data.[1]

Documentation

Syntax

sysctl [PARAMETER ...] [VARIABLE[=VALUE]]

Parameters

-a
Display all values currently available.
-A
Display all values currently available in table form.
-n
Use this option to disable printing of the key name when printing values.
-p FILE
Load in sysctl settings from the FILE specified or /etc/sysctl.conf if none given. Specifying - as FILE means reading data from standard input.
-w
Use this option when you want to change a sysctl setting.

Examples

Set IP forwarding in the kernel
sysctl -w 'net.ipv4.ip_forward=1'
Test if a kernel parameter is set
if [[ $(${SYSCTL} -n 'net.ipv4.ip_forward') -eq 0 ]]; then
  echo "Kernel parameter 'net.ipv4.ip_forward' is set!"
fi

References

  1. man 8 'sysctl'