Posted by: kezhong | July 30, 2009

Modifying Linux Kernel Parameters at Runtime

Linux provides a very flexible approach to system administrators that they can modify runtime kernel parameters without compiling and installing a new kernel or module. It is implemented by the virtual file system /proc. Most of Linux kernel parameters can be found in the directory /proc/sys. You can use either the echo command with redirection or the sysctl command to modify these kernel parameters.

For example, I can use two methods as below, if I want to enable the IP forwarding temporarily.
# echo 1 > /proc/sys/net/ipv4/ip_forward
or
# sysctl -w net.ipv4.ip_forward=1

After modifying, it takes effect at once. But when you reboot the system or restart the network service, it will recover the default value 0 again.

If you want to make it effective permanently, you have to either save the above echo command line to the file /etc/rc.d/rc.local or modify the file /etc/sysctl.conf as below.

Modify the file /etc/sysctl.conf, change the value 0 to 1.
  net.ipv4.ip_forward = 1
Then save the file. When the system boot up, the initial script /etc/rc.d/rc.sysinit will read the content of the file /etc/sysctl.conf. But the sysctl.conf file will not take effect immediately when you use this method. If you want, you can issue the command with –p parameter.
# sysctl –p

How to correspond the relationship between the kernel file in the directory /proc/sys and the variable of the file sysctl.conf? Because all possible kernel parameters are in the directory /proc/sys, you can set the variables of the file sysctl.conf omitting the previous part (/proc/sys), and then change the all “/” to “.”.

For example,
  /proc/sys/net/ipv4/ip_forward     –>       net.ipv4.ip_forward
  /proc/sys/kernel/hostname         –>       kernel.hostname
  /proc/sys/kernel/domainname      –>       kernel.domainname
  /proc/sys/fs/file-max                 –>       fs.file-max

 

Reference
Administer Linux on the fly


Responses

  1. good example


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: