linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
Index
Categories
All entries
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
home/linux/kb/Commands/cmd-sysctl

kb/commands ── Commands ── intermediate

sysctl: kernel tunables

`sysctl` reads and writes kernel parameters through the virtual filesystem `/proc/sys/`. Network, memory, and filesystem tuning all go through these knobs.

view as markdownaka: proc-sys, kernel-tunables

Where parameters live

Each parameter is a file under /proc/sys/:

/proc/sys/net/ipv4/ip_forward          ↔  net.ipv4.ip_forward
/proc/sys/net/ipv4/tcp_congestion_control ↔ net.ipv4.tcp_congestion_control
/proc/sys/vm/swappiness                ↔  vm.swappiness
/proc/sys/kernel/pid_max               ↔  kernel.pid_max

Dots in the sysctl name correspond to slashes in the path. Reading or writing the file is equivalent to calling sysctl.

Basic commands

bash
sysctl -a                                  # all parameters (thousands)
sysctl -a 2>/dev/null | grep ^net.ipv4.tcp # filter by subsystem
sysctl net.ipv4.ip_forward                 # read one parameter
sysctl -n net.ipv4.ip_forward              # -n: value only, no name
sudo sysctl -w net.ipv4.ip_forward=1       # set (until reboot)

Persistent changes

-w survives only until the next reboot. To make a change permanent:

bash
echo 'net.ipv4.ip_forward = 1' | sudo tee /etc/sysctl.d/99-router.conf
sudo sysctl --system                       # apply all .conf files right now

Files in /etc/sysctl.d/ are read in lexicographic order. A numeric prefix (99- or 10-) controls priority.

Common subsystems

  • net.ipv4.tcp_*: all TCP tunables (congestion control, keepalive, windows)
  • net.ipv4.ip_forward: turn the machine into a router (ip-forwarding)
  • net.core.*: general network buffers and qdisc defaults
  • net.netfilter.nf_conntrack_max: connection tracking table size
  • vm.swappiness: how aggressively the kernel uses swap (0-100)
  • vm.overcommit_memory: memory overcommit strategy
  • fs.file-max: global open file descriptor limit
  • kernel.pid_max: maximum PID (default 32768 or 4M)

Inside a container

In Docker, /proc/sys is mounted read-only. sysctl -w fails with EPERM unless the container runs with --privileged or the required capability (SYS_ADMIN plus the correct mount). Some parameters are per-namespace (network sysctls); others are global and the host does not expose them to containers.

Backup before changes

bash
sysctl -a > /tmp/sysctl-backup-$(date +%F).txt 2>/dev/null

If tuning breaks something, compare with diff against the snapshot.

§ команды

bash
sysctl -a 2>/dev/null | grep tcp_congestion

Find parameters by topic (here: TCP congestion control)

bash
sudo sysctl -w net.ipv4.ip_forward=1

Enable IP forwarding (turn the host into a router); active until reboot

bash
sudo sysctl --system

Reload all /etc/sysctl.d/*.conf files after editing

bash
cat /proc/sys/net/ipv4/tcp_keepalive_time

Read directly through /proc, same result as sysctl but without the binary

bash
sudo sysctl -p /etc/sysctl.d/99-mytuning.conf

Apply a specific config file

§ см. также

  • tcp-statesTCP states (LISTEN, ESTABLISHED, TIME_WAIT)A TCP session moves through 11 states from LISTEN to CLOSED. The most important in production: LISTEN, ESTABLISHED, TIME_WAIT, CLOSE_WAIT.
  • tcp-handshakeTCP three-way handshakeTCP connection opens with three packets: SYN from the client, SYN-ACK from the server, ACK from the client. After that the connection is Established and data transfer can begin.
  • ip-forwardingIP Forwarding: Turn a Host into a RouterLinux does not forward packets between interfaces by default. Enable it with `sysctl net.ipv4.ip_forward=1`. Without this, NAT, VPN routing, and any forwarding will not work.
  • kernel-modulesKernel modules: LKM, modprobe, signing, DKMSAn LKM is code loaded into the kernel at runtime. modprobe resolves dependencies through depmod. Sign a module for Secure Boot. DKMS rebuilds out-of-tree modules after a kernel upgrade. Lockdown mode blocks unsigned modules.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies