Sysctl: Difference between revisions
From Leo's Notes
This page was last edited on 18 August 2023, at 21:31.
→Examples: tcp forwarding |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
The <code>sysctl</code> command is used to view and modify Linux kernel parameters. | |||
== Quick usage guide == | |||
{| class="wikitable" | |||
!Task | |||
!Command | |||
|- | |||
|List all current kernel parameters and their values. | |||
|{{code|sysctl -a}} | |||
|- | |||
|See a specific parameter by its key | |||
|{{code|sysctl key}} | |||
|- | |||
|Set a specific parameter to a new value | |||
|{{code|1=sysctl -w key=value}} | |||
|- | |||
|Load parameters from a file | |||
|<code>sysctl -p /etc/sysctl.d/params.conf</code> | |||
|} | |||
On a related note, some parameters are also visible from the <code>/proc</code> filesystem. For example, the value for <code>net.ipv4.ip_forward</code> can be read by calling either: | |||
* <code>sysctl net.ipv4.ip_forward</code> as well as | |||
* | * <code>cat /proc/sys/net/ipv4/ip_forward</code> | ||
* | |||
== | == Common tunable parameters == | ||
You'll commonly see these tunable parameters changed in your day to day life as a system administrator. | |||
{| class="wikitable" | |||
{ | !Task | ||
net.ipv4.ip_forward | !Description | ||
|- | |||
|<code>net.ipv4.ip_forward</code> | |||
|Enable IPv4 packet forwarding. Useful for NATs. | |||
|- | |||
{{highlight|lang=text|code= | |<code>vm.swappiness</code> | ||
|How much the system favors to swap memory to page cache. | |||
|- | |||
|{{highlight|lang=text|code= | |||
# Provide adequate buffer memory. | # Provide adequate buffer memory. | ||
# rmem_max and wmem_max are TCP max buffer size | # rmem_max and wmem_max are TCP max buffer size | ||
| Line 57: | Line 76: | ||
net.ipv4.tcp_low_latency=1 | net.ipv4.tcp_low_latency=1 | ||
}} | }} | ||
|TCP tunables | |||
|} | |||
{{Navbox Linux}}[[Category:Linux]] | |||
[[Category:LinuxUtilities]] | |||
Latest revision as of 21:31, 18 August 2023
The sysctl command is used to view and modify Linux kernel parameters.
Quick usage guide
| Task | Command |
|---|---|
| List all current kernel parameters and their values. | sysctl -a
|
| See a specific parameter by its key | sysctl key
|
| Set a specific parameter to a new value | sysctl -w key=value
|
| Load parameters from a file | sysctl -p /etc/sysctl.d/params.conf
|
On a related note, some parameters are also visible from the /proc filesystem. For example, the value for net.ipv4.ip_forward can be read by calling either:
sysctl net.ipv4.ip_forwardas well ascat /proc/sys/net/ipv4/ip_forward
Common tunable parameters
You'll commonly see these tunable parameters changed in your day to day life as a system administrator.
| Task | Description |
|---|---|
net.ipv4.ip_forward
|
Enable IPv4 packet forwarding. Useful for NATs. |
vm.swappiness
|
How much the system favors to swap memory to page cache. |
# Provide adequate buffer memory.
# rmem_max and wmem_max are TCP max buffer size
# settable with setsockopt(), in bytes
# tcp_rmem and tcp_wmem are per socket in bytes.
# tcp_mem is for all TCP streams, in 4096-byte pages.
# The following are suggested on IBM's
# High Performance Computing page
# net.core.rmem_max = 524288000
# net.core.wmem_max = 524288000
net.core.rmem_default = 462144000
net.core.wmem_default = 462144000
net.ipv4.tcp_rmem = 4096 46214400 262144000
net.ipv4.tcp_wmem = 4096 46214400 262144000
# This server might have 200 clients simultaneously, so:
# max(tcp_wmem) * 2 * 200 / 4096
net.ipv4.tcp_mem = 46214400 46214400 46214400
# Disable TCP SACK (TCP Selective Acknowledgement),
# DSACK (duplicate TCP SACK), and FACK (Forward Acknowledgement)
net.ipv4.tcp_sack = 0
net.ipv4.tcp_dsack = 0
net.ipv4.tcp_fack = 0
# Disable the gradual speed increase that's useful
# on variable-speed WANs but not for us
net.ipv4.tcp_slow_start_after_idle = 0
# recommended default congestion control is htcp
net.ipv4.tcp_congestion_control=htcp
# recommended for hosts with jumbo frames enabled
net.ipv4.tcp_mtu_probing=1
# recommended for CentOS7+/Debian8+ hosts
net.core.default_qdisc = fq
net.ipv4.tcp_low_latency=1
|
TCP tunables |