Ce contenu n'est pas disponible dans la langue sélectionnée.
E.4. Using the sysctl Command
The
/sbin/sysctl
command is used to view, set, and automate kernel settings in the /proc/sys/
directory.
For a quick overview of all settings configurable in the
/proc/sys/
directory, type the /sbin/sysctl -a
command as root. This creates a large, comprehensive list, a small portion of which looks something like the following:
net.ipv4.route.min_pmtu = 552 kernel.sysrq = 0 kernel.sem = 250 32000 32 128
This is the same information seen if each of the files were viewed individually. The only difference is the file location. For example, the
/proc/sys/net/ipv4/route/min_pmtu
file is listed as net.ipv4.route.min_pmtu
, with the directory slashes replaced by dots and the proc.sys
portion assumed.
The
sysctl
command can be used in place of echo
to assign values to writable files in the /proc/sys/
directory. For example, instead of using the command
echo 1 > /proc/sys/kernel/sysrq
use the equivalent
sysctl
command as follows:
sysctl -w kernel.sysrq="1" kernel.sysrq = 1
While quickly setting single values like this in
/proc/sys/
is helpful during testing, this method does not work as well on a production system as special settings within /proc/sys/
are lost when the machine is rebooted. To preserve custom settings, add them to the /etc/sysctl.conf
file.
The
/etc/sysctl.conf
file is installed by the initscripts package to override some kernel default values and therefore only contains a few of the possible parameters. Use the sysctl -a
command to list the parameters in the sysctl
key format. See the /usr/share/doc/kernel-doc-kernel_version/Documentation/networking/ip-sysctl.txt
file for more information on the possible settings.
Each time the system boots, the
init
program runs the /etc/rc.d/rc.sysinit
script. This script contains a command to execute sysctl
using /etc/sysctl.conf
to determine the values passed to the kernel. Any values added to /etc/sysctl.conf
therefore take effect each time the system boots. Note that modules loaded after sysctl
has parsed this file might override the settings.