Linux Command Reference ยท Special Files and Directories
The /proc/sys directory
Reference for /proc/sys: how tunable kernel parameters map to files, how to read and write them, the sysctl command, persistence in sysctl.d, and common settings.
/proc/sys is the part of the /proc virtual filesystem that exposes the kernel's tunable parameters. Every file is one setting: reading it shows the current value, and writing to it (as root) changes the behavior of the running kernel immediately, with no reboot. Nothing here lives on disk; the files are windows into kernel memory.
The tree mirrors a dotted naming scheme. The parameter net.ipv4.ip_forward is the file /proc/sys/net/ipv4/ip_forward, and vm.swappiness is /proc/sys/vm/swappiness. The sysctl command is a convenience wrapper that translates between the two forms.
cat /proc/sys/kernel/ostype sysctl kernel.ostype echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward # needs root
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
sysctl [-n] name # read one parameter sysctl -a # list all parameters sudo sysctl -w name=value # change until reboot sudo sysctl -p [file] # load /etc/sysctl.conf or a file sudo sysctl --system # load every sysctl.d file
| Part | Description |
|---|---|
kernel/ |
Core kernel settings: pid_max, hostname, random/, printk. |
vm/ |
Memory management: swappiness, overcommit_memory, dirty_ratio. |
net/ |
Networking: ipv4/ip_forward, core/somaxconn, ipv6/. |
fs/ |
Filesystem limits: file-max, inotify/max_user_watches. |
user/ |
User namespace and per-user limits. |
Edge cases: values are text, usually one number or a few space-separated numbers. Some entries are read-only, some accept only specific values, and a write with a bad value fails with "Invalid argument".
Usage notes
- Changes are temporary. A
sysctl -worechowrite lasts until reboot. To keep a setting, putname = valuein a file such as/etc/sysctl.d/90-custom.confand runsudo sysctl --system. - Dots versus slashes.
net.ipv4.conf.eth0.rp_filteris a path witheth0as a directory. Interface names that contain dots (for example VLANs likeeth0.100) swap the roles:sysctl net/ipv4/conf/eth0.100/rp_filter. - Common tunings:
net.ipv4.ip_forward=1for routers and container hosts,vm.swappinessto prefer RAM over swap,fs.inotify.max_user_watchesfor editors and file watchers,net.core.somaxconnfor busy servers. - Containers. Many parameters are per network namespace, and most of
/proc/sysis read-only inside an unprivileged container. - Do not guess. Wrong values for
vm.overcommit_memoryorkernel.paniccan crash or hang a machine. Change one value at a time and note the old value. - Parameters versus
/sys./proc/sysholds kernel-wide tunables, while/sysexposes devices and drivers.
Related
/sys,/proc/PID,/proc/meminfo- Lessons: Performance and Tricks, Hardening