GIT – sysctl 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 to both read and write sysctl data.
Linux set sysctl variables
Q. How do I set sysctl variables under Debian Linux?
A. sysctl 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 to both read and write sysctl data.
Method # 1: Setting value via procfs
You can use standard echo command to write data to variables:
# echo "value" > /proc/sys/location/variable
Method # 2: Temporary on the command line
Use sysctl command with -w option when you want to change a sysctl setting:
sysctl -w variable=value
Method # 3: Configuration file /etc/sysctl.conf
This is recommended way. First open /etc/sysctl.conf file
# vi /etc/sysctl.conf
Now add value:
variable = value
Close and save the changes. Type the following command to load sysctl settings from the file /etc/sysctl.conf file:
# sysctl -p
Read man page of sysctl for information:
$ man sysctl
Linux Increase Local Port Range with net.ipv4.ip_local_port_range
If your Linux server is opening lots of outgoing network connection, you need to increase local port range. By default range is small. For example squid proxy server can come under fire if it runs out of ports.
You can use sysctl command to to modify kernel parameters at runtime. The parameters available are those listed under /proc/sys/. Please note that this hack is only useful for high bandwidth, busy Linux servers or large scale grid servers.
To find current range type
$ sysctl net.ipv4.ip_local_port_range
net.ipv4.ip_local_port_range = 32768 61000
Set new local port range
You can set the range with the following command:
# echo 1024 65535 > /proc/sys/net/ipv4/ip_local_port_range
$ sudo sysctl -w net.ipv4.ip_local_port_range="1024 64000"
You may need to edit /etc/sysctl.conf file, to make changes to /proc filesystem permanently i.e. append the following to your /etc/sysctl.conf file:
# increase system IP port limits
net.ipv4.ip_local_port_range = 1024 65535
Linux Increase Process Identifiers Limit with /proc/sys/kernel/pid_max
Yesterday I wrote about increasing local port range with net.ipv4.ip_local_port_range proc file. There is also /proc/sys/kernel/pid_max file, which specifies the value at which PIDs wrap around (i.e., the value in this file is one greater than the maximum PID). The default value for this file, 32768, results in the same range of PIDs as on earlier kernels (<=2.4). The value in this file can be set to any value up to 2^22 (PID_MAX_LIMIT, approximately 4 million).
Increasing the value will help on large Linux system or clusters to ease process identification and process management. You can easily prevent fork() failures error message with this hack.
Display Current Process Identifiers Limit
Type the following command at shell prompt:
$ sysctl kernel.pid_max
$ cat /proc/sys/kernel/pid_max
kernel.pid_max = 32768
Allow for more PIDs
Type the following command
# sysctl -w kernel.pid_max=4194303
You need to append the following to your /etc/sysctl.conf:
kernel.pid_max = 4194303
Please note that this hack is only useful for large and busy server, don’t try this on old kernel or desktop systems.