The sysctl command reads and modifies kernel parameters at runtime on Linux and other Unix-like systems. You use it to view current settings, change them temporarily, or make changes permanent across reboots. This article gives you concrete, copy-pasteable examples for the most common tasks, then explains how the command works, where settings live, and how to avoid breaking your system.
What Is sysctl?
sysctl is a command-line utility that interfaces with the kernel’s parameter system. On Linux, these parameters live under /proc/sys/. Each file in that directory tree corresponds to one kernel setting. For example, /proc/sys/net/ipv4/ip_forward controls whether the kernel forwards IP packets between interfaces.
The sysctl command simply reads and writes those files. When you run sysctl net.ipv4.ip_forward, it reads that file. When you run sysctl -w net.ipv4.ip_forward=1, it writes “1” to it. The dots in the parameter name map to slashes in the file path.
Changes made with -w are immediate but temporary — they revert when you reboot. To make changes permanent, you add them to /etc/sysctl.conf or a file in /etc/sysctl.d/.
Viewing Current Settings
The simplest use is to read a value:
sysctl net.ipv4.ip_forward
To see all settings at once:
sysctl -a
That output can be thousands of lines. To filter it, pipe to grep:
sysctl -a | grep tcp
You can also read multiple parameters in one command:
sysctl net.ipv4.ip_forward net.ipv4.tcp_syncookies
To see only values that have been changed from defaults (on systemd systems):
sysctl --system
This applies all config files and shows what’s being set. It’s useful for debugging why a setting isn’t taking effect.
Changing Values Temporarily
The -w flag writes a new value immediately:
sysctl -w net.ipv4.ip_forward=1
You can set multiple values at once:
sysctl -w net.ipv4.ip_forward=1 net.ipv4.tcp_syncookies=1
Some parameters are read-only. For example, kernel.hostname cannot be changed with sysctl — you must use the hostname command. If you try, you’ll get an error like “sysctl: cannot set /proc/sys/kernel/hostname: Read-only file system.”
Changes made this way are lost on reboot. That’s fine for testing, but for persistent changes you need the next section.
Making Changes Permanent
To keep a setting across reboots, add it to a config file. The traditional file is /etc/sysctl.conf. On modern distributions, it’s cleaner to create a file in /etc/sysctl.d/:
echo 'net.ipv4.ip_forward = 1' | sudo tee /etc/sysctl.d/99-forwarding.conf
Then apply it without rebooting:
sudo sysctl --system
or for just that file:
sudo sysctl -p /etc/sysctl.d/99-forwarding.conf
Note that the config file syntax uses spaces around the equals sign, while the command line doesn’t require them. Both work.
Files in /etc/sysctl.d/ are read in alphabetical order. Later files override earlier ones. The 99- prefix ensures your file is read last, so it wins over distribution defaults.
Common Use Cases with Examples
Here are practical examples you’ll actually use:
- Enable IP forwarding (for routers, VPNs):
sysctl -w net.ipv4.ip_forward=1 - Enable TCP SYN cookies (basic DoS protection):
sysctl -w net.ipv4.tcp_syncookies=1 - Reduce swap usage:
sysctl -w vm.swappiness=10(default is often 60) - Increase file descriptor limit:
sysctl -w fs.file-max=100000 - Set the kernel hostname (temporary):
sysctl -w kernel.hostname=myhost— this works but resets on reboot - Disable IPv6 on all interfaces:
sysctl -w net.ipv6.conf.all.disable_ipv6=1 - Increase the maximum number of pending connections:
sysctl -w net.core.somaxconn=1024 - Enable packet forwarding for IPv6:
sysctl -w net.ipv6.conf.all.forwarding=1
Each of these can be made permanent by adding the line to a file in /etc/sysctl.d/.
How to List All Parameters and Find What You Need
To see every parameter:
sysctl -a
To search for a keyword:
sysctl -a | grep -i memory
To see parameters for a specific subsystem, like IPv4:
sysctl -a | grep net.ipv4
You can also list just the names, not values:
sysctl -aN
This is useful for scripting. For example, to count all parameters:
sysctl -aN | wc -l
On a typical Linux system, that number is in the thousands. Don’t try to memorize them — grep is your friend.
Loading and Reloading Config Files
After editing a config file, you can reload it without rebooting:
sudo sysctl -p /etc/sysctl.conf
To load all files in /etc/sysctl.d/ plus the main file:
sudo sysctl --system
This is what runs at boot. It reads files in order, applies each setting, and reports any that fail. If you get an error, it usually means the parameter name is wrong or the value is out of range.
Safety and Pitfalls
Changing kernel parameters can make your system unstable. Here are the key rules:
- Never set a value you don’t understand. For example, setting
vm.overcommit_memory=2can cause the kernel to refuse to allocate memory, crashing applications. - Test temporary first. Use
sysctl -wbefore writing to a config file. If the system misbehaves, reboot to revert. - Some parameters are dangerous to change on a running system. For instance,
kernel.pid_maxcan only be increased, not decreased, and changing it requires a reboot to take full effect. - Read-only parameters exist. You can’t change
kernel.ostypeorkernel.version. Trying to will just fail. - Values are often in different units.
vm.swappinessis a percentage (0-100), butfs.file-maxis a count.net.core.rmem_maxis in bytes. Always check the unit before setting.
If you’re unsure about a parameter, search for its documentation in the kernel docs or online. The man sysctl page covers the command itself, but not every parameter.
Frequently Asked Questions
How do I see all sysctl settings?
Run sysctl -a. This prints every parameter and its current value. To filter, pipe to grep, e.g., sysctl -a | grep net.core.
How do I make a sysctl change permanent?
Add the line to a file in /etc/sysctl.d/ with the format parameter = value. Then run sudo sysctl --system to apply it immediately. The change will also be applied at every boot.
What’s the difference between sysctl and /proc/sys?
They’re the same thing. sysctl is a user-friendly interface to the files in /proc/sys/. Writing to those files directly works too, but sysctl handles the path mapping and provides a consistent interface.
Why does my sysctl change revert after reboot?
Because you only used sysctl -w, which changes the running kernel but doesn’t persist. To make it permanent, add the setting to a config file as described above.
Can I use sysctl on macOS or FreeBSD?
Yes. sysctl exists on all BSD systems and macOS. The parameters differ, but the command syntax is the same. For example, sysctl hw.machine shows the CPU architecture on macOS.
Is it safe to change kernel parameters?
Generally yes, if you know what the parameter does. Always test with a temporary change first, and be especially careful with memory and network settings. If something breaks, reboot to restore defaults.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Google Keep Features You Must Try
- TV Unboxing Settings: Why Filmmakers Care
- Dead Websites: Why You Need the Wayback Machine
- 8K HDMI Ports: Do You Always Need Them?
- Open Source: Best and Worst for Tech?
- Gaming Better Off Without These Kinds of Games?