当前位置: 首页 > 图文教程 > 操作系统 > Unix/Linux > Linux上的sysctl

Unix/Linux
linux root 密码忘了怎么办?
Debian LINUX 基础知识介绍
在Linux操作系统下修改IP、DNS和路由配置
Linux网络管理员指南(下载)
Linux环境进程间通信:管道及有名管道
Linux操作系统中的七件超厉害的武器
linux下vi编辑器命令大全
Linux服务器安全小技巧
Linux和UNIX病毒需特别重视
配置安全的SCO UNIX网络系统
IIS的安全性全解析
UNIX防止非法用户注册的技术
linux 远程桌面连接
Vsftpd+tcp_wrappers控制主机和用户访问
挂载(mount)命令使用技巧
linux 如何结束进程
cpio 解压参数
gzip和gunzip 解压参数
compress与uncompress参数使用
bzip2 bunzip2 bzcat参数使用

Unix/Linux 中的 Linux上的sysctl


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-01   浏览: 38 ::
收藏到网摘: n/a


  我们常常在 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)