2015年11月2日 星期一

[Linux 文章收集] Linux set sysctl variables

Source From Here
Question
How do I set sysctl variables (kernel parameters) under a Debian/Ubuntu or any Linux distributions using command line options?

How-To
You need to use the sysctl command which is used to modify kernel parameters at runtime. The parameters available are those listed under /proc/sys/. Procfs is required for sysctl support in Linux. You can use sysctl command to both read and write sysctl variables.

You must login as the root user to use any one of the following command on a Linux operating systems.

Display Linux kernel parameters
The syntax is:



- Example: Check setting of variable net.ipv4.ip_forward
// -a, --all: display all variables
# sysctl -a | grep net.ipv4.ip_forward
net.ipv4.ip_forward = 0
net.ipv4.ip_forward_use_pmtu = 0

// -n, --values: print only values of a variables
# sysctl -n net.ipv4.ip_forward
0

How do I set new values?
There are three methods to set new values for given kernel parameters as follows:

Method # 1: Setting value via procfs 
You can use standard echo command to write data to variables (this temporary change): 
# echo 1 > /proc/sys/net/ipv4/ip_forward

Method # 2: Temporary on the command line 
Use sysctl command with -w option when you want to change a sysctl setting:
# sysctl -w net.ipv4.ip_forward=1
net.ipv4.ip_forward = 1

Method # 3: Configuration file /etc/sysctl.conf
This is recommended way. First open /etc/sysctl.conf file, enter:
# vi /etc/sysctl.conf
  1. net.ipv4.ip_forward=1  
// -p, --load[=]: read values from file
# sysctl -p
net.ipv4.ip_forward = 1


沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...