Sysctl

From Leo's Notes
Last edited on 18 August 2023, at 21:31.

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