Sie sind auf Seite 1von 2

Adjusting Kernel Parameters

Unlike many Linux applications that need to be restarted before their configurat
ion parameters are read, many of the Linux kernel's parameters can be instantane
ously activated and deactivated.
The Linux kernel stores many of its dynamic parameters in the /proc filesystem,
which resides on a virtual RAM disk in memory for maximum performance.
Parameters are generally categorized by function within subdirectories of the /p
roc; information on IDE hard drives are located in the /proc/ide directory, for
example, and general system parameters are located in the /proc/sys directory.
System parameters are held within files with names that mimic their function. Fo
r example, a Linux system can become a rudimentary router if the IP forwarding n
etworking parameter is set to 1, not 0. Networking parameters for IPv4 addressin
g schemes are located in the /proc/sys/net/ipv4/. The file that covers IP forwar
ding is named ip_forward and contains a single byte: 1 when it's active or 0 whe
n it's not.
You can update these files by redirecting the output of the echo command to over
write the file contents using the > redirection character. This line activates I
P forwarding by overwriting the contents of the ip_forward file with the value 1
.
[root@bigboy tmp] echo 1 > /proc/sys/net/ipv4/ip_forward
There are some disadvantages to doing this. It is not a permanent solution, and
the system will revert back to its defaults after the next reboot. You can overc
ome this by adding the echo commands to the /etc/rc.local script that runs at th
e end of each reboot. This too has its disadvantages; it is the very last script
to be run so if your parameters need to be set earlier, as most kernel paramete
rs should be, it isn't a suitable solution.
Linux has a more elegant solution called the /etc/sysctl.conf file. It is a list
of all the /proc filesystem files the systems administrator wants to customize
and the values they should contain. The file has two columns, the first is the f
ilename relative to the /proc/sys directory, and the second is the value the fil
e should contain separated by an equals sign. You can also replace the slashes i
n the filename with periods. Continuing with the example, you can set the /proc/
sys/net/ipv4/ip_forward file with a value of 1 using either of these configurati
ons.
#
# Sample /etc/sysctl.conf file
#
# Activate IP forwarding
#
net.ipv4.ip_forward = 1
#
# Activate IP forwarding too!
#
net/ipv4/ip_forward = 1
Editing the /etc/sysctl.conf file isn't enough, because the update isn't instant
aneous. You have to force Linux to reread the file and reset the kernel paramete
rs using the sysctl -p command. In the example, the /proc/sys/net/ipv4/ip_forwar
d file had a value of 0 until the sysctl command ran, after which time, IP forwa
rding was activated.
[root@bigboy tmp]# cat /proc/sys/net/ipv4/ip_forward
0
[root@bigboy tmp]# sysctl -p
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1
kernel.sysrq = 0
kernel.core_uses_pid = 1
[root@bigboy tmp]# cat /proc/sys/net/ipv4/ip_forward
1
[root@bigboy tmp]#

The use of the /etc/sysctl.conf is important in day to day administration.

Das könnte Ihnen auch gefallen