Kernel parameters are configuration settings that control the behavior of the Linux kernel.
These
parameters can be used to modify system performance, hardware compatibility, debugging, security, and
other kernel functionalities.
Ways to Set Kernel Parameters
Kernel parameters can be set in multiple ways:
1. At Boot Time (GRUB or LInux LOader (LILO))
o Modify the bootloader configuration e.g., GRand Unified Bootloader (GRUB) to set
parameters.
o Example (for GRUB2):
sudo nano /etc/default/grub
Modify the GRUB_CMDLINE_LINUX line:
GRUB_CMDLINE_LINUX="quiet splash parameter=value"
(This line imports any entries to the end of the 'linux' line)
Then update GRUB:
sudo update-grub
2. Using Sysctl (Runtime Kernel Parameters)
o Modify parameters dynamically using sysctl.
o Example:
sudo sysctl -w kernel.parameter=value
(This command is used to modify kernel parameters at runtime. It allows
you to change system settings without rebooting.)
o To make it persistent:
sudo nano /etc/sysctl.conf
Add:
kernel.parameter=value
Apply changes:
sudo sysctl -p
3. Using /proc Filesystem
o Directly modify kernel parameters through /proc.
o Example:
echo value | sudo tee /proc/sys/kernel/parameter
Common Kernel Parameters
Performance & Memory Management
o vm.swappiness → Controls swap usage (0-100).
o vm.dirty_ratio → Maximum percentage of dirty pages before writing to disk.
Security
o kernel.randomize_va_space → Controls Address Space Layout Randomization (ASLR).
(ASLR is a security feature that randomizes memory addresses to make it harder for
attackers to exploit memory corruption vulnerabilities.)
o fs.protected_hardlinks → Prevents hardlink creation (another reference to the same
data) by unauthorized users.
Networking
o net.ipv4.ip_forward → Enables/disables packet forwarding.
o net.core.somaxconn → Maximum number of connections in the listen queue.