What it does
Every file in /proc/sys/ is a kernel setting; the dots in the name are slashes: net.ipv4.ip_forward = /proc/sys/net/ipv4/ip_forward. sysctl NAME reads it, sysctl -w NAME=VALUE changes it until reboot. For permanent values put NAME = VALUE lines in a file in /etc/sysctl.d/ and run sysctl --system.
How to write it
sysctl [OPTION]... [NAME[=VALUE]]...
sysctl -p [FILE]
sysctl --systemOptions 14
Most used
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1Read a value
sysctl net.ipv4.ip_forward net.ipv4.ip_forward = 0Same as
cat /proc/sys/net/ipv4/ip_forward.2Change it now
sysctl -w net.ipv4.ip_forward=1Lost at reboot.
3Make it permanent
echo "net.ipv4.ip_forward = 1" > /etc/sysctl.d/90-forward.conf sysctl --systemFiles are read in name order; later wins.
4Only the value
sysctl -n vm.swappiness 60For scripts.
5Search settings
sysctl -a 2>/dev/null | grep -i swappinessOr
sysctl -a -r swap.6Lower swapping on a database server
echo "vm.swappiness = 10" > /etc/sysctl.d/90-swap.conf; sysctl --systemThe kernel keeps more in RAM.
7Network hardening (security)
cat /etc/sysctl.d/90-hardening.conf net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.all.rp_filter = 1 net.ipv4.tcp_syncookies = 1 kernel.kptr_restrict = 2 kernel.dmesg_restrict = 1Common CIS benchmark settings.
8Load one file
sysctl -p /etc/sysctl.d/90-hardening.confTest a new file.
9More open files for big servers
sysctl -w fs.file-max=2097152System-wide limit (per-process limits are in limits.conf/systemd).
10Where does a setting come from?
grep -r swappiness /etc/sysctl.d/ /usr/lib/sysctl.d/ /etc/sysctl.conftuned can also set values (check the tuned profile).
Nothing matches this filter.
Files
/etc/sysctl.d/*.conf- Your permanent settings.
/usr/lib/sysctl.d/- Defaults from packages.
/etc/sysctl.conf- Old main file (still read).
/proc/sys/- The live values.
Exit codes
0 :: Done. 1 :: Error. 255 :: Unknown setting or permission denied.