Quick take: The sysctl command reads and changes kernel parameters at runtime. sysctl -a lists them, sudo sysctl -w net.ipv4.ip_forward=1 changes one temporarily, and adding it to /etc/sysctl.conf makes it permanent.
Introduction
The sysctl command exposes tunable kernel parameters — settings that control networking, memory, and system behaviour — and lets you read or change them while the system is running. It is essential for server tuning, from enabling IP forwarding on a router to adjusting network buffers and memory limits.
Syntax
The basic syntax of the sysctl command is:
sysctl [OPTIONS] [PARAMETER[=VALUE]]Common Options and Parameters
The most useful options and parameters for the sysctl command:
| Option | Description |
|---|---|
| -a | List all kernel parameters and values. |
| PARAM | Show the value of one parameter. |
| -w PARAM=VAL | Set a parameter at runtime (temporary). |
| -p [FILE] | Load settings from a file (default /etc/sysctl.conf). |
| --system | Load settings from all standard config directories. |
Practical Examples
Real sysctl commands you can run today:
# List all parameters
sysctl -a
# Read one parameter
sysctl net.ipv4.ip_forward
# Enable IP forwarding temporarily
sudo sysctl -w net.ipv4.ip_forward=1
# Find networking parameters
sysctl -a | grep net.ipv4
# Make a change permanent
echo 'net.ipv4.ip_forward=1' | sudo tee -a /etc/sysctl.conf
# Apply the config file changes
sudo sysctl -pTips and Best Practices
- Changes made with
-ware temporary and reset on reboot; add them to/etc/sysctl.conf(or a file in/etc/sysctl.d/) and runsysctl -pto persist them. - Parameter names map to files under
/proc/sys/—net.ipv4.ip_forwardis/proc/sys/net/ipv4/ip_forward. - Filter the long list with grep:
sysctl -a | grep vm.swappinessto find a specific setting.
Final Thoughts
sysctl is the control panel for the running kernel, reading and tuning parameters that govern networking, memory, and more. Use -w for temporary changes while testing, then persist the ones you want in /etc/sysctl.d/ and apply with sysctl -p. It is a core tool for server and network tuning on Linux.
FAQ: sysctl Command in Linux
What is sysctl used for?+
sysctl views and changes kernel parameters at runtime — settings that control networking, memory, and system behaviour. It is used for server tuning such as enabling IP forwarding or adjusting network and memory limits.
How do I change a kernel parameter?+
Temporarily with sudo sysctl -w name=value, for example sudo sysctl -w net.ipv4.ip_forward=1. To make it permanent, add the line to /etc/sysctl.conf and run sudo sysctl -p.
How do I make sysctl changes permanent?+
Add the parameter to /etc/sysctl.conf or a file in /etc/sysctl.d/, then run sudo sysctl -p (or --system) to apply it. Otherwise the change is lost at reboot.
How do I list all kernel parameters?+
Run sysctl -a to list every parameter and its value. Pipe it through grep to find a specific area, such as sysctl -a | grep net.ipv4.
How do I enable IP forwarding?+
Run sudo sysctl -w net.ipv4.ip_forward=1 to enable it now, and add net.ipv4.ip_forward=1 to /etc/sysctl.conf to keep it enabled after reboot.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support