Linux上的sysctl

原贴:http://www.linuxpk.com/2386.html
Linux上的sysctl

我们常常在 Linux 的 /proc/sys 目录下,手动设定一些 kernel 的参数或是直接 echo 特定的值给一个 proc下的虚拟档案,俾利某些档案之开启,常见的例如设定开机时自动启动 IP Forwarding:

  echo “1” > /proc/sys/net/ipv4/ip_forward

   其实,在 Linux 我们还可以用 sysctl command 便可以简易的去检视、设定或自动配置 特定的 kernel 设定。我们可以在系统提示符号下输入「sysctl -a」,摘要如后:abi.defhandler_coff = 117440515

  dev.raid.speed_limit_max = 100000

  net.ipv4.conf.default.send_redirects = 1

  net.ipv4.conf.default.secure_redirects = 1

  net.ipv4.conf.default.accept_redirects = 1

  net.ipv4.conf.default.mc_forwarding = 0

  net.ipv4.neigh.lo.delay_first_probe_time = 5

  net.ipv4.neigh.lo.base_reachable_time = 30

  net.ipv4.icmp_ratelimit = 100

  net.ipv4.inet_peer_gc_mintime = 10

  net.ipv4.igmp_max_memberships = 20

  net.ipv4.ip_no_pmtu_disc = 0

  net.core.no_cong_thresh = 20

  net.core.netdev_max_backlog = 300

  net.core.rmem_default = 65535

  net.core.wmem_max = 65535

  vm.kswapd = 512 32 8

  vm.overcommit_memory = 0

  vm.bdflush = 30 64 64 256 500 3000 60 0 0

  vm.freepages = 351 702 1053

  kernel.sem = 250 32000 32 128

  kernel.panic = 0

  kernel.domainname = (none)

  kernel.hostname = pc02.shinewave.com.tw

  kernel.version = #1 Tue Oct 30 20:11:04 EST 2001

  kernel.osrelease = 2.4.9-13

  kernel.ostype = Linux

  fs.dentry-state = 1611 969 45 0 0 0

  fs.file-nr = 1121 73 8192

  fs.inode-state = 1333 523 0 0 0 0 0

  从上述的语法我们大概可看出 sysctl 的表示法乃把目录结构的「/」以「.」表示,一层一层的连结下去。当然以echo 特定的值给一个 proc下的虚拟档案也是可以用 sysctl加以表示,例如:

  #sysctl –w net.ipv4.ip_forward =”1”

  或是直接在 /etc/sysctl.conf 增删修改特定档案的 0,1值亦可:

  # Enables packet forwarding

  net.ipv4.ip_forward = 1

  # Enables source route verification

  net.ipv4.conf.default.rp_filter = 1

  # Disables the magic-sysrq key

  kernel.sysrq = 0

   当然如果考虑 reboot 后仍有效, 直接在 /etc/sysctl.conf 增删修改特定档案的 0,1值才可使之保留设定(以RedHat 为例,每次开机系统启动后, init 会执行 /etc/rc.d/rc.sysinit,便会使用 /etc/sysctl.conf 的预设值去执行 sysctl)。

  相关参考档案:

  /sbin/sysctl

  /etc/sysctl.conf

  sysctl 及sysctl.conf manpage

  /usr/src/linux-x.y.z/Documentation/sysctl/*

  /usr/share/doc/kernel-doc-x.y.z/sysctl/* (RedHat)
本文来自:http://www.linuxpk.com/2386.html
-->linux电子图书免费下载和技术讨论基地
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值