How To

sysctl Command in Linux: View and Change Kernel Parameters

The sysctl command reads and modifies Linux kernel parameters from the command line. Changes take effect immediately at runtime but are not persistent, a reboot restores the defaults. To keep changes after a reboot, you write them to configuration files.

How to Use the sysctl Command in Linux

View all current kernel parameters:

bashsysctl -a

Check a single parameter:

bashsysctl vm.swappiness

Output: vm.swappiness = 60

All users can view parameters. Only root can modify them.

sysctl reads from /proc/sys — a virtual directory the kernel exposes at runtime. It does not exist on disk. The naming maps directly between the two interfaces: dots in sysctl parameter names become slashes in the /proc/sys path, and the /proc/sys prefix is dropped. Both commands below return the same value:

bashsysctl vm.swappinesscat /proc/sys/vm/swappiness

Change Kernel Parameters at Runtime

Set a value with -w:

bashsudo sysctl -w net.ipv4.ip_forward=1

The change takes effect immediately and reverts to the default after a reboot. Set multiple parameters in one command:

bashsudo sysctl -w vm.swappiness=10 net.ipv4.ip_forward=1

You can also write directly to the /proc/sys file:

bashecho 1 | sudo tee /proc/sys/net/ipv4/ip_forward > /dev/null

Both methods are equivalent for runtime changes. Be careful on production systems — some kernel parameter values can cause instability or require a reboot to recover.

Make sysctl Changes Persistent After Reboot

Write the parameter to a file in /etc/sysctl.d/:

bashprintf 'net.ipv4.ip_forward = 1\n' | sudo tee /etc/sysctl.d/99-ip-forward.conf > /dev/null

The 99- prefix ensures this file loads last, after other configuration files in the directory.

Reload all sysctl configuration files:

bashsudo sysctl --system

To apply only a specific file without reloading everything:

bashsudo sysctl -p /etc/sysctl.d/99-ip-forward.conf

--system processes all files in canonical load order. -p applies only the file you name.

Use sysctl -a to browse parameters, -w for immediate runtime changes, and /etc/sysctl.d/*.conf with --system to persist them. Leave a comment below if you run into any issues.

Cyber Defence

Recent Posts

whereis Command in Linux: Find Binary, Source, and Man Pages

The whereis command locates the binary, source, and manual page files for a given command. Unlike which, it…

48 minutes ago

git clone: Clone a Repository from Remote or Local Sources

git clone copies an existing Git repository into a new directory on your local machine. It…

53 minutes ago

How to Copy Files and Directories in Linux: cp and rsync

The two main tools for copying files and directories in Linux are cp and rsync. cp handles quick, local file…

58 minutes ago

jobs Command in Linux: List and Manage Background Processes

The jobs command is a Bash builtin that lists all background and suspended processes belonging to the…

1 day ago

dmesg Command in Linux: Read and Filter Kernel Messages

The Linux kernel writes messages to the kernel ring buffer throughout the boot process and…

1 day ago

How to Transfer Files with rsync over SSH: A Practical Guide

rsync over SSH combines secure encrypted transport with fast incremental transfers. Instead of copying every file…

1 day ago