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.

[[email protected] fs]$ sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1
[[email protected] fs]$ sysctl -n net.ipv4.ip_forward
1

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

[[email protected] sys]$ sysctl net/ipv4/ip_forward
net.ipv4.ip_forward = 1

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

[[email protected] fs]$ sysctl -n net.ipv4.ip_forwar
error: "net.ipv4.ip_forwar" is an unknown key
[[email protected] fs]$ sysctl -e net.ipv4.ip_forwar
[[email protected] fs]$

 

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

[[email protected] 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.

[[email protected] 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:

[[email protected] 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: 1245 | 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-01-09][Open System-Linux]
How to send a mail using unix/linux terminal?
[2014-09-20][Open System-Linux]
Export command in Linux
[2017-01-21][Open System-Linux]
Useful tips and tricks while working in Linux.
[2014-01-08][Open System-Linux]
SSH Login Setup
[2015-05-25][Open System-Linux]
Password-less Login to Linux/Unix Servers in Putty

Total comments: 0
avatar