Time: 40 minutes | Level: Advanced | Docker: docker run -it --rm --privileged ubuntu:22.04 bash
The Linux kernel exposes hundreds of tunable parameters through the sysctl interface and the /proc/sys/ virtual filesystem. These parameters control networking, memory management, security hardening, and system behavior — all at runtime, without rebooting. This lab covers reading, modifying, and persisting kernel parameters safely.
Step 1: Explore the /proc/sys/ Hierarchy
The /proc/sys/ filesystem mirrors the sysctl namespace as a directory tree.
📸 Verified Output:
Copy abi debug dev fs kernel net user vm Each subdirectory corresponds to a sysctl namespace:
Copy ls /proc/sys/net/ipv4/ | head -10 📸 Verified Output:
Copy conf
fib_multipath_hash_fields
fib_multipath_hash_policy
fib_multipath_hash_seed
fib_multipath_use_neigh
fib_notify_on_flag_change
fwmark_reflect
icmp_echo_enable_probe
icmp_echo_ignore_all
icmp_echo_ignore_broadcasts 💡 Every file under /proc/sys/ maps 1:1 to a sysctl key — slashes become dots. So /proc/sys/net/ipv4/ip_forward → net.ipv4.ip_forward.
Step 2: Read Parameters with sysctl -a
List all available kernel parameters (983+ on a typical system):
📸 Verified Output:
Read specific parameters:
📸 Verified Output:
💡 You can also read directly from /proc/sys/: cat /proc/sys/net/ipv4/ip_forward — the output is identical.
Step 3: Understand Key Parameters
Read security-relevant parameters:
📸 Verified Output:
💡 kernel.randomize_va_space = 2 means full ASLR (Address Space Layout Randomization) is enabled — a key defense against exploit techniques.
Step 4: Runtime Changes with sysctl -w
Changes made with -w take effect immediately but are not persistent across reboots:
📸 Verified Output:
You can also write directly to /proc/sys/:
📸 Verified Output:
💡 Direct writes to /proc/sys/ and sysctl -w are equivalent. The proc interface is useful in scripts.
Step 5: Persist Changes with sysctl.conf
Runtime changes vanish on reboot. To persist them, write to /etc/sysctl.conf or a drop-in file under /etc/sysctl.d/:
📸 Verified Output:
The sysctl -p command loads parameters from a file (default: /etc/sysctl.conf).
💡 Files in /etc/sysctl.d/ are processed alphabetically. Use 99- prefix so your overrides apply last, after any distro defaults.
Step 6: Network Tuning Parameters
For high-throughput servers, tune these networking parameters:
📸 Verified Output:
A production web server config (/etc/sysctl.d/99-network-tuning.conf):
Step 7: Security Hardening Parameters
Security-focused sysctl settings to harden a production system:
A security hardening config (/etc/sysctl.d/99-security.conf):
💡 Run sysctl -p /etc/sysctl.d/99-security.conf to apply immediately, and it will auto-apply on next boot.
Step 8: Capstone — Tune a Server for High Connections
Scenario: You're deploying a high-traffic API gateway. Apply and verify a complete tuning profile.
📸 Verified Output: