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: 1057 | 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:


[2015-06-19][Open System-Linux]
How to create swap file in Linux : Adding extra swap space
[2014-11-25][Open System-Linux]
DMESG command in Linux : to display or control kernel ring buffer
[2015-03-23][Open System-Linux]
FSCK : Checking and reparing filesystems in Linux
[2016-03-17][Open System-Linux]
Some amazing command shortcuts in Linux
[2014-08-31][Open System-Linux]
20 command line tools to check load and performance of a Linux System

Total comments: 0
avatar