Bash Wiki
Posts (Latest 30 updated) :
Read all
Contents:
  1. [Linux] Bash sysctl Uso: Manage kernel parameters at runtime
    1. Overview
    2. Usage
    3. Common Options
    4. Common Examples
    5. Tips

[Linux] Bash sysctl Uso: Manage kernel parameters at runtime

Overview

The sysctl command is used to view and modify kernel parameters at runtime in Linux-based operating systems. It allows users to adjust system settings without needing to reboot, making it a powerful tool for system administrators.

Usage

The basic syntax of the sysctl command is as follows:

sysctl [options] [arguments]

Common Options

  • -a: Display all current kernel parameters.
  • -n: Show the value of a specific parameter without the parameter name.
  • -w: Write a new value to a kernel parameter.
  • -p: Load parameters from a specified file.

Common Examples

Here are some practical examples of using the sysctl command:

  1. View all kernel parameters:
    sysctl -a
    
  2. Check the value of a specific parameter (e.g., vm.swappiness):
    sysctl -n vm.swappiness
    
  3. Change the value of a kernel parameter (e.g., set vm.swappiness to 10):
    sysctl -w vm.swappiness=10
    
  4. Load kernel parameters from a configuration file (e.g., /etc/sysctl.conf):
    sysctl -p
    
  5. View a specific parameter and its value (e.g., net.ipv4.ip_forward):
    sysctl net.ipv4.ip_forward
    

Tips

  • Always check the current values of parameters before making changes to understand the impact.
  • Use sysctl -p to apply changes from a configuration file after editing it.
  • Be cautious when modifying kernel parameters, as incorrect values can lead to system instability.
  • Consider making changes persistent by adding them to /etc/sysctl.conf for them to survive reboots.