sysctl设置和显示在/proc/sys目录中的内核参数.能用sysctl来设置或重新设置连网功能,如IP转发、IP碎片去除及源路由检查等。用户只需要编辑/etc/sysctl.conf文件,即可手工或自动执行由sysctl控制的功能。
命令格式:
- sysctl [-n] [-e] -w variable=value
- sysctl [-n] [-e] -p (default /etc/sysctl.conf)
- sysctl [-n] [-e] -a
sysctl [-n] [-e] -w variable=valuesysctl [-n] [-e] -p (default /etc/sysctl.conf)sysctl [-n] [-e] -a
常用参数的意义:
-w 临时改动某个指定参数的值,如
sysctl -w net.ipv4.ip_forward=1
-a 显示所有的系统参数
-p 从指定的文件加载系统参数,如不指定即从/etc/sysctl.conf中加载
如果仅仅是想临时改动某个系统参数的值,能用两种方法来实现,例如想启用IP路由转发功能:
1) #echo 1 > /proc/sys/net/ipv4/ip_forward
2) #sysctl -w net.ipv4.ip_forward=1
以上两种方法都可能即时开启路由功能,但如果系统重启,或执行了
# service network restart
命令,所设置的值即会丢失,如果想永久保留设置,能修改/etc/sysctl.conf文件
将 net.ipv4.ip_forward=0改为net.ipv4.ip_forward=1
- **********************
- sysctl man page
- NAME
- sysctl - configure kernel parameters at runtime
- SYNOPSIS
- sysctl [-n] [-e] variable ...
- sysctl [-n] [-e] [-q] -w variable=value ...
- sysctl [-n] [-e] [-q] -p
- sysctl [-n] [-e] -a
- sysctl [-n] [-e] -A
- DESCRIPTION
- sysctl is used to modify kernel parameters at runtime. The parameters
- available are those listed under /proc/sys/. Procfs is required for
- sysctl(8) support in Linux. You can use sysctl(8) to both read and
- write sysctl data.
- PARAMETERS
- variable
- The name of a key to read from. An example is kernel.ostype.
- The ’/’ separator is also accepted in place of a ’.’.
- 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.
- -n Use this option to disable printing of the key name when print-
- ing values.
- -e Use this option to ignore errors about unknown keys.
- -N Use this option to only print the names. It may be useful with
- shells that have programmable completion.
- -q Use this option to not display the values set to stdout.
- -w Use this option when you want to change a sysctl setting.
- -p Load in sysctl settings from the file specified or
- /etc/sysctl.conf if none given. Specifying - as filename means
- reading data from standard input.
- -a Display all values currently available.
- -A Display all values currently available in table form.
- EXAMPLES
- /sbin/sysctl -a
- /sbin/sysctl -n kernel.hostname
- /sbin/sysctl -w kernel.domainname="example.com"
- /sbin/sysctl -p /etc/sysctl.conf
- FILES
- /proc/sys /etc/sysctl.conf
- SEE ALSO
- sysctl.conf(5)
- BUGS
- The -A parameter behaves just as -a does.
- AUTHOR
- George Staikos,
- 21 Sep 1999 SYSCTL(8)
**********************sysctl man pageNAMEsysctl - configure kernel parameters at runtimeSYNOPSISsysctl [-n] [-e] variable ...sysctl [-n] [-e] [-q] -w variable=value ...sysctl [-n] [-e] [-q] -p sysctl [-n] [-e] -asysctl [-n] [-e] -ADESCRIPTIONsysctl is used to modify kernel parameters at runtime. The parametersavailable are those listed under /proc/sys/. Procfs is required forsysctl(8) support in Linux. You can use sysctl(8) to both read andwrite sysctl data.PARAMETERSvariableThe name of a key to read from. An example is kernel.ostype.The ’/’ separator is also accepted in place of a ’.’.variable=valueTo set a key, use the form variable=value, where variable is thekey and value is the value to set it to. If the value containsquotes or characters which are parsed by the shell, you may needto enclose the value in double quotes. This requires the -wparameter to use.-n Use this option to disable printing of the key name when print-ing values.-e Use this option to ignore errors about unknown keys.-N Use this option to only print the names. It may be useful withshells that have programmable completion.-q Use this option to not display the values set to stdout.-w Use this option when you want to change a sysctl setting.-p Load in sysctl settings from the file specified or/etc/sysctl.conf if none given. Specifying - as filename meansreading data from standard input.-a Display all values currently available.-A Display all values currently available in table form.EXAMPLES/sbin/sysctl -a/sbin/sysctl -n kernel.hostname/sbin/sysctl -w kernel.domainname="example.com"/sbin/sysctl -p /etc/sysctl.confFILES/proc/sys /etc/sysctl.confSEE ALSOsysctl.conf(5)BUGSThe -A parameter behaves just as -a does.AUTHORGeorge Staikos, 21 Sep 1999 SYSCTL(8)