The sysctl command reads and modifies Linux kernel parameters from the command line. Changes take effect immediately at runtime but are not persistent, a reboot restores the defaults. To keep changes after a reboot, you write them to configuration files.
View all current kernel parameters:
bashsysctl -a
Check a single parameter:
bashsysctl vm.swappiness
Output: vm.swappiness = 60
All users can view parameters. Only root can modify them.
sysctl reads from /proc/sys — a virtual directory the kernel exposes at runtime. It does not exist on disk. The naming maps directly between the two interfaces: dots in sysctl parameter names become slashes in the /proc/sys path, and the /proc/sys prefix is dropped. Both commands below return the same value:
bashsysctl vm.swappinesscat /proc/sys/vm/swappiness
Set a value with -w:
bashsudo sysctl -w net.ipv4.ip_forward=1
The change takes effect immediately and reverts to the default after a reboot. Set multiple parameters in one command:
bashsudo sysctl -w vm.swappiness=10 net.ipv4.ip_forward=1
You can also write directly to the /proc/sys file:
bashecho 1 | sudo tee /proc/sys/net/ipv4/ip_forward > /dev/null
Both methods are equivalent for runtime changes. Be careful on production systems — some kernel parameter values can cause instability or require a reboot to recover.
Write the parameter to a file in /etc/sysctl.d/:
bashprintf 'net.ipv4.ip_forward = 1\n' | sudo tee /etc/sysctl.d/99-ip-forward.conf > /dev/null
The 99- prefix ensures this file loads last, after other configuration files in the directory.
Reload all sysctl configuration files:
bashsudo sysctl --system
To apply only a specific file without reloading everything:
bashsudo sysctl -p /etc/sysctl.d/99-ip-forward.conf
--system processes all files in canonical load order. -p applies only the file you name.
Use sysctl -a to browse parameters, -w for immediate runtime changes, and /etc/sysctl.d/*.conf with --system to persist them. Leave a comment below if you run into any issues.