sysctl
Overview
sysctl is used to modify kernel parameters at runtime. The parameters available are those listed under /proc/sys/.
Syntax
sysctl [options] [variable[=value]]Common Options
| Option | Description |
|---|---|
-a, --all |
Display all currently available kernel variables |
-w |
Write/modify a kernel parameter value in memory |
-p [file] |
Load sysctl settings from a configuration file (default /etc/sysctl.conf) |
-e |
Ignore errors about unknown keys |
Key Use Cases
- Tuning network stack performance and IP forwarding.
- Adjusting virtual memory swappiness (
vm.swappiness). - Configuring security controls like kernel pointer restriction (
kernel.kptr_restrict).
Examples with Explanations
Example 1: Enabling IP Forwarding
sysctl -w net.ipv4.ip_forward=1Enables IPv4 routing in memory immediately.
Example 2: Reloading Configuration
sysctl -p /etc/sysctl.d/99-custom.confApplies kernel configuration settings from /etc/sysctl.d/99-custom.conf.