Home » 2014 » October » 4 » SYSCTL : A command to configure kernel parameters at runtime in linux

0:31 AM
SYSCTL : A command to configure kernel parameters at runtime in linux

Share on Google+

The command is used to configure kernel parameters at runtime

Most frequent usage:

  1. Enable/disable IP forwarding
  2. Change/Edit network configuration for ipv4/ipv6
  3. Change/Edit kernel parameters like hostaname, domainname, max_lock_depth. ostype, pid_max etc
  4. Change/edit file system configurations like file-max, dir-notify-enable, overflowgid, inode-nr etc

  • We can quickly set the kernel parameters in /proc/sys/ but it is useful for testing, these special settings within /proc/sys/ are lost when the machine is rebooted.
  • To save these custom settings permanently, add them to the /etc/sysctl.conf file.
  • Each time the system is booted, the init program runs the /etc/rc.d/rc.sysinit  script. This script executes sysctl using /etc/sysctl.conf to determine the values passed to the kernel. Any changed made in /etc/sysctl.conf therefore take effect each time the system is booted.

Format:
       sysctl [-n] [-e] variable ...
       sysctl [-n] [-e] [-q] -w variable=value ...
       sysctl [-n] [-e] [-q] -p <filename>
       sysctl [-n] [-e] -a
       sysctl [-n] [-e] -A


DESCRIPTION
       sysctl  is  used  to  modify  kernel  parameters at runtime.  It can edit values for following parameters:

localhost:/proc/sys:>ls
abi  crypto  debug  dev  fs  kernel  net  sunrpc  vm  xen


To change a kernel parameter:

sysctl -w variable=value

              To set a key, use the form variable=value, where variable is the key and value is the value to set  it to.  If the value contains quotes or characters which are parsed by the shell, you may need to enclose the value in double quotes.  This requires the -w parameter to use.


Options  with their examples:

       -n     Use this option to disable printing of the key name when printing values.

[shanky@HYDBMW fs]$ sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1
[shanky@HYDBMW fs]$ sysctl -n net.ipv4.ip_forward
1

     Note:- '/' can also be used in place of '.' for a variable. See below:

[shanky@HYDBMW sys]$ sysctl net/ipv4/ip_forward
net.ipv4.ip_forward = 1

-e     Use this option to ignore errors about unknown keys.

[shanky@HYDBMW fs]$ sysctl -n net.ipv4.ip_forwar
error: "net.ipv4.ip_forwar" is an unknown key
[shanky@HYDBMW fs]$ sysctl -e net.ipv4.ip_forwar
[shanky@HYDBMW fs]$

 

       -N     Use this option to only print the names. It may be useful with shells that have  programmable  completion.

[shanky@HYDBMW fs]$ sysctl -N net.ipv4.ip_forward
net.ipv4.ip_forward

       -q     Use this option to not display the values set to stdout.

       -w     Use this option when you want to change a sysctl setting.

[shanky@HYDBMW sys]$ sysctl -w net.ipv4.ip_forward=0
error: permission denied on key 'net.ipv4.ip_forward'


    -p     Load in sysctl settings from the file specified or /etc/sysctl.conf if none given. All these setting can be done only by root user.See the file below:

[shanky@HYDBMW sys]$ head /etc/sysctl.conf
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled.  See sysctl(8) and
# sysctl.conf(5) for more details.

# Controls IP packet forwarding
net.ipv4.ip_forward = 0

# Controls source route verification
net.ipv4.conf.default.rp_filter = 1

       -a     Display all values currently available.

kernel.sched_child_runs_first = 0
kernel.sched_min_granularity_ns = 2000000
kernel.sched_latency_ns = 10000000
kernel.sched_wakeup_granularity_ns = 2000000
kernel.sched_tunable_scaling = 1
kernel.sched_features = 3183
kernel.sched_migration_cost = 500000
kernel.sched_nr_migrate = 32
kernel.sched_time_avg = 1000
kernel.sched_shares_window = 10000000
kernel.timer_migration = 1

       -A     Display all values currently available in table form

 
 

Category: Open System-Linux | Views: 1670 | Added by: shanky | Tags: change system setting in linux, sysctl, change ip forwarding setting, configure kernel parameters in Linu, change kernal parameters at runtime | Rating: 5.0/1

Related blogs


You may also like to see:


[2014-12-03][Open System-Linux]
GREP command in Linux to search for a pattern
[2014-04-10][Open System-Linux]
SED command for filtering and transforming texts of a file using regular expression
[2016-02-05][Open System-Linux]
Lets try to understand sticky bit concept in Linux!
[2014-09-24][Open System-Linux]
Set, unset, display shell behaviour options : SHOPT command in Linux
[2014-03-17][Open System-Linux]
AWK command for scanning and analysing a large file in Linux

Total comments: 0
ComForm">
avatar