| Tested on | Ubuntu 25.04 (Plucky Puffin) |
|---|---|
| Package | sysctl from procps-ng 4.0.4sysctl from procps-ng 4.0.4 |
| Applies to | Ubuntu, Debian, RHEL, Rocky Linux, AlmaLinux, Fedora |
| Privilege | sudo or root |
| Man page | sysctl(8) |
| Scope | sysctl reads and writes Linux kernel tunables under /proc/sys. Use sysctl -w for temporary changes, drop files in /etc/sysctl.d/, then sysctl -p or sysctl --system to reload without rebooting — except for parameters. |
| Related guides | sysctl command Linux disable IPv6 properly Suppress net.ipv6.conf.all.stable_secret warning Linux commands |
sysctl — quick reference
Read values
| When to use | Command |
|---|---|
| Read one parameter | sysctl net.core.somaxconn |
| Print only the value (scripts) | sysctl -n net.core.somaxconn |
| List every tunable | sysctl -a |
Same as -a |
sysctl --all |
| Read value from proc path directly | cat /proc/sys/net/core/somaxconn |
Write temporary (runtime) values
Changes apply immediately but are lost on reboot unless saved in a .conf file.
| When to use | Command |
|---|---|
| Set a value until reboot | sudo sysctl -w net.core.somaxconn=4096 |
| Write via procfs (same effect) | echo 4096 | sudo tee /proc/sys/net/core/somaxconn |
Load from config files
| When to use | Command |
|---|---|
| Apply one drop-in file | sudo sysctl -p /etc/sysctl.d/99-custom.conf |
Same as -p (long form) |
sudo sysctl --load=/etc/sysctl.d/99-custom.conf |
| Apply all system sysctl directories | sudo sysctl --system |
Legacy: load /etc/sysctl.conf only |
sudo sysctl -p |
| Apply without printing each line | sudo sysctl -q -p /etc/sysctl.d/99-custom.conf |
Search and scripting
| When to use | Command |
|---|---|
| Filter a long list | sysctl -a | grep somaxconn |
| Ignore unknown keys in a file (containers) | sudo sysctl -e -p /path/file.conf |
| Print names only | sysctl -N net.ipv4.tcp_fin_timeout |
| Dry-run: show what would be written | sudo sysctl --dry-run -p /etc/sysctl.d/99-custom.conf |
sysctl — command syntax
Synopsis from sysctl --help on Ubuntu 25.04 (procps-ng 4.0.4):
sysctl [options] [variable[=value] ...]
Options:
-a, --all display all variables
-n, --values print only values of the given variable(s)
-p, --load[=<file>] read values from file
--system read values from all system directories
-w, --write enable writing a value to variable
-q, --quiet do not echo variable set
-e, --ignore ignore unknown variables errors
--dry-run print keys and values but do not writeKernel tunables live under /proc/sys/. Dotted names map to paths (net.core.somaxconn → /proc/sys/net/core/somaxconn). Drop-in files belong in /etc/sysctl.d/ — avoid editing vendor files under /usr/lib/sysctl.d/ directly; override with a lexically later file in /etc/sysctl.d/.
sysctl — command examples
Essential Read the current value of one parameter
Before changing a tunable, capture what the kernel is using now — you need the exact dotted name.
Run the command:
sysctl net.core.somaxconnSample output:
net.core.somaxconn = 4096The same value is visible under procfs:
cat /proc/sys/net/core/somaxconnSample output:
4096Use sysctl -n when a script only needs the number with no label.
Essential Temporary change with sysctl -w
Tune a running system for a test or incident response — the value resets at reboot unless you also write a .conf file.
Run the command:
sudo sysctl -w net.core.somaxconn=256Sample output:
net.core.somaxconn = 256Confirm it took effect:
sysctl net.core.somaxconnSample output:
net.core.somaxconn = 256Revert when finished (restore your site's normal value):
sudo sysctl -w net.core.somaxconn=4096Essential Persistent file in /etc/sysctl.d/ and reload
Make a tunable survive reboot by adding a drop-in file, then load it with sysctl -p.
Create the drop-in (example lab file under /tmp — on a real host use /etc/sysctl.d/):
echo 'net.ipv4.tcp_fin_timeout = 30' | sudo tee /etc/sysctl.d/99-cheatsheet-lab.confReload that file only:
sudo sysctl -p /etc/sysctl.d/99-cheatsheet-lab.confSample output:
net.ipv4.tcp_fin_timeout = 30Verify:
sysctl net.ipv4.tcp_fin_timeoutSample output:
net.ipv4.tcp_fin_timeout = 30Remove the lab file when done: sudo rm /etc/sysctl.d/99-cheatsheet-lab.conf and run sudo sysctl --system to re-apply vendor defaults.
Common Reload every sysctl drop-in with --system
After editing several files, or when you are unsure which file set a value, reload all system sysctl directories in one pass.
Run the command:
sudo sysctl --systemSample output (truncated):
* Applying /usr/lib/sysctl.d/10-bufferbloat.conf ...
* Applying /usr/lib/sysctl.d/50-default.conf ...
* Applying /etc/sysctl.d/99-cheatsheet-lab.conf ...
net.ipv4.tcp_fin_timeout = 30
...Check a parameter you care about:
sysctl net.ipv4.tcp_fin_timeoutsysctl --system is what many admins mean by "sysctl reload without reboot" — it reapplies every configured file without restarting the machine.
Common Find which file sets a parameter
When a value surprises you, search config trees before editing blindly.
Run the command:
sudo grep -r 'net.core.somaxconn' /etc/sysctl.conf /etc/sysctl.d/ /usr/lib/sysctl.d/ 2>/dev/nullSample output:
/usr/lib/sysctl.d/50-default.conf:net.core.somaxconn=4096Override vendor defaults by adding a file in /etc/sysctl.d/ with a later sort order (higher numeric prefix) containing your desired value, then sudo sysctl --system.
Common Undo a runtime-only change
If you used sysctl -w and did not write a file, set the parameter back to the intended production value or reload from disk.
Reload all on-disk settings:
sudo sysctl --systemThen read the parameter again:
sysctl net.core.somaxconnSample output:
net.core.somaxconn = 4096Deleting a drop-in line alone does not always restore old runtime values — reload from files or reboot to pick up removals cleanly.
Advanced Parameters that need a reboot
Many network and VM tunables apply live; some memory reservations only take effect during early boot.
Examples that often need a reboot (or boot-time kernel args) even after sysctl -w:
vm.nr_hugepages
vm.nr_overcommit_hugepages
kernel.shmmax
kernel.shmallYou can still write them at runtime:
sudo sysctl -w vm.nr_hugepages=128Sample output:
vm.nr_hugepages = 128If the kernel cannot allocate the pages because memory is already in use, the value may not stick or may break running workloads — plan hugepage changes for a maintenance window and initramfs/boot config when your distro requires it.
Advanced Script-friendly read with -n
Shell scripts often need the raw number for comparisons — -n drops the name = prefix.
Run the command:
CUR=$(sysctl -n net.core.somaxconn)
echo "somaxconn is $CUR"Sample output:
somaxconn is 4096Pair with sysctl -q -p in automation when you do not want every applied line printed to stdout.
sysctl — when to use / when not
| Use sysctl when | Use something else when |
|---|---|
|
|
sysctl — interview corner
What does sysctl do in Linux?
sysctl is the user-space tool for kernel parameters exposed as files under /proc/sys/. Names use dots (net.ipv4.tcp_fin_timeout); paths use slashes (/proc/sys/net/ipv4/tcp_fin_timeout).
You can read values, write temporary values with -w, and reload .conf files with -p or sysctl --system. There is no long-running sysctl daemon — each command talks to procfs directly.
A strong answer is:
"sysctl reads and writes kernel tunables in /proc/sys. Persistent settings go in /etc/sysctl.d/*.conf; sysctl -p or --system reloads them without reboot for most parameters."
How do you reload sysctl without rebooting?
For most tunables:
- Put
key = valuelines in/etc/sysctl.d/NN-name.conf - Run
sudo sysctl -p /etc/sysctl.d/NN-name.conffor one file, orsudo sysctl --systemfor everything
sysctl -p with no path on Ubuntu often follows the legacy /etc/sysctl.conf symlink — prefer explicit paths or --system.
A strong answer is:
"Edit /etc/sysctl.d/, then sysctl -p on that file or sysctl --system for all drop-ins — no reboot for most network and VM knobs."
Should you edit /etc/sysctl.conf or /etc/sysctl.d/?
Prefer /etc/sysctl.d/*.conf with a numeric prefix (e.g. 99-custom.conf) so:
- Vendor defaults in
/usr/lib/sysctl.d/stay intact - Overrides are ordered and easy to find
- Multiple teams can add files without one giant
sysctl.conf
Override one key from a vendor file by adding a lexically later file in /etc/sysctl.d/ with your value.
A strong answer is:
"I add numbered files under /etc/sysctl.d/ instead of editing sysctl.conf or vendor files — later filenames win."
When does sysctl still require a reboot?
Runtime sysctl -w works for many parameters, but memory layout settings are often fixed after boot — examples include vm.nr_hugepages, kernel.shmmax, and kernel.shmall.
Symptoms: value appears set but behaviour does not change, or workloads fail after hugepage tweaks. Fix: maintenance window, correct drop-in, rebuild initramfs if your distro embeds sysctl at boot, then reboot.
A strong answer is:
"Most sysctl changes apply live, but hugepages and some shared-memory limits need boot-time reservation — I treat those as reboot changes."
What is the relationship between sysctl and /proc/sys?
They are the same knobs. sysctl net.core.somaxconn reads /proc/sys/net/core/somaxconn. Writing with echo VALUE > /proc/sys/... is equivalent to sysctl -w for that key.
sysctl adds file loading (-p, --system), filtering (-a, grep), and safer parsing for scripts.
A strong answer is:
"/proc/sys is the source of truth; sysctl is the CLI to read, write, and bulk-load .conf files against those paths."
Troubleshooting
| Symptom | Likely cause | What to try |
|---|---|---|
Permission denied on write |
Not root | Prefix with sudo |
sysctl: cannot stat /proc/sys/... |
Typo or kernel lacks that tunable | sysctl -a | grep keyword; check kernel docs |
Value unchanged after sysctl -p |
Wrong file path or later file overrides | grep -r KEY /etc/sysctl.d/ /usr/lib/sysctl.d/ |
sysctl -p only loads one file |
Expected — use --system for all |
sudo sysctl --system |
| Setting reverts after reboot | Only used sysctl -w |
Add /etc/sysctl.d/*.conf |
| Setting wrong after removing drop-in | Old runtime value still in memory | sysctl --system or reboot |
| Unknown key errors in containers | Tunable not available in namespace | sysctl -e -p file to ignore missing keys |

