Sysctl: Difference between revisions

From Leo's Notes
This page was last edited on 18 August 2023, at 21:31.
m Added categories
No edit summary
 
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:


== Quick Usage ==
* <code>sysctl net.ipv4.ip_forward</code> as well as
* {{code|sysctl -a}} to see all set values.
* <code>cat /proc/sys/net/ipv4/ip_forward</code>
* {{code|sysctl key}} to see the value for 'key'
* {{code|1=sysctl -w key=value}} to write a value for 'key'.
* {{code|sysctl -p /etc/sysctl.conf}} to apply what's in the {{code|/etc/sysctl.conf}} file.


== Examples ==
== Common tunable parameters ==
=== TCP Forwarding ===
You'll commonly see these tunable parameters changed in your day to day life as a system administrator.
If you're making a Linux router, you need to enable IP forwarding:
{| class="wikitable"
{{highlight|lang=text|code=
!Task
net.ipv4.ip_forward = 1
!Description
}}
|-
 
|<code>net.ipv4.ip_forward</code>
 
|Enable IPv4 packet forwarding. Useful for NATs.
=== TCP Tuning ===
|-
{{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]]
{{Navbox Linux}}[[Category:Linux]]
[[Category:LinuxUtilities]]
[[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_forward as well as
  • cat /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