Skip to content

sysctl Command Cheat Sheet

sysctl is used to modify kernel parameters at runtime. The parameters available are those listed under /proc/sys/.


Synopsis

sysctl [options] [variable[=value] ...]

Basic Usage

List All Parameters (-a)

sysctl -a
# Output:
# kernel.hostname = myhost
# net.ipv4.ip_forward = 1
# ...

Read a Specific Parameter

sysctl net.ipv4.ip_forward

Filter Output

sysctl -a | grep ipv6

Modifying Parameters

Temporary Change (Lost on Reboot)

Enable IP Forwarding:

sudo sysctl -w net.ipv4.ip_forward=1

Permanent Change

  1. Edit /etc/sysctl.conf (or usage file in /etc/sysctl.d/).
  2. Add: net.ipv4.ip_forward = 1
  3. Reload:

sudo sysctl -p
(Load settings from default file).


Common Tunables

Swappiness

Control how aggressive the kernel swaps memory (0-100).

sysctl vm.swappiness
sudo sysctl -w vm.swappiness=10

Max Open Files

sysctl fs.file-max

Network Stack Tuning

# Allow more connections
sysctl -w net.core.somaxconn=1024

Notes

  • Danger: Changing random kernel parameters can panic the system.
  • Hierarchy: Separated by dots (.). e.g., net.ipv4 vs kernel..