Linux sysctl Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Linux sysctl Guide
Complete beginner-friendly guide to sysctl on Linux, covering Arch Linux, CachyOS, and other distributions including kernel parameters, system tuning, and performance optimization.
Table of Contents
- Understanding sysctl
- Viewing Parameters
- Setting Parameters
- Common Parameters
- Performance Tuning
- Troubleshooting
Understanding sysctl
What is sysctl?
sysctl configures kernel parameters at runtime.
Uses:
- Network tuning: Optimize network performance
- Memory management: Configure memory settings
- Security: Harden system settings
- Performance: Optimize system performance
Why it matters:
- Runtime changes: Modify settings without reboot
- System optimization: Tune for your needs
- Troubleshooting: Fix system issues
Viewing Parameters
List All Parameters
View parameters:
# List all parameters
sysctl -a
# List specific category
sysctl -a | grep net
# View single parameter
sysctl kernel.hostname
Common Categories
Parameter categories:
# Network parameters
sysctl -a | grep net
# Kernel parameters
sysctl -a | grep kernel
# Virtual memory
sysctl -a | grep vm
Setting Parameters
Temporary Changes
Set temporarily:
# Set parameter
sudo sysctl kernel.hostname=myhost
# Set network parameter
sudo sysctl net.ipv4.ip_forward=1
Note: Changes are lost after reboot.
Permanent Changes
Make permanent:
# Edit sysctl config
sudo vim /etc/sysctl.conf
Add:
# Network forwarding
net.ipv4.ip_forward = 1
# Kernel hostname
kernel.hostname = myhost
Apply:
# Apply changes
sudo sysctl -p
Common Parameters
Network Parameters
Network settings:
# Enable IP forwarding
net.ipv4.ip_forward = 1
# Disable ICMP redirects
net.ipv4.conf.all.accept_redirects = 0
# TCP keepalive
net.ipv4.tcp_keepalive_time = 600
Memory Parameters
Memory settings:
# Swappiness (0-100)
vm.swappiness = 10
# Overcommit memory
vm.overcommit_memory = 1
Security Parameters
Security settings:
# Disable IP source routing
net.ipv4.conf.all.accept_source_route = 0
# Enable SYN cookies
net.ipv4.tcp_syncookies = 1
Performance Tuning
Network Performance
Optimize network:
# Increase TCP buffer sizes
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
File System Performance
Optimize filesystem:
# Increase file handles
fs.file-max = 2097152
# Inotify limits
fs.inotify.max_user_watches = 524288
Troubleshooting
Parameter Not Applied
Check configuration:
# Verify parameter
sysctl parameter-name
# Check config file
cat /etc/sysctl.conf
# Apply manually
sudo sysctl -p
Invalid Parameter
Test parameter:
# Test before applying
sudo sysctl -w parameter=value
# Check if valid
sysctl parameter-name
Summary
This guide covered sysctl usage, parameter configuration, and system tuning for Arch Linux, CachyOS, and other distributions.
Next Steps
- Performance Tuning - System optimization
- System Configuration - System setup
- Networking - Network configuration
- sysctl Documentation:
man sysctl
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.