Sobes.tech
Senior

What Linux kernel parameters did you configure when tuning the TCP stack?

sobes.tech AI

Answer from AI

When tuning the TCP stack in Linux, the following kernel parameters are often configured (via sysctl or directly in /proc/sys/net/ipv4/):

  • net.ipv4.tcp_fin_timeout — the timeout for closing a connection in FIN_WAIT_2 state.
  • net.ipv4.tcp_tw_reuse and net.ipv4.tcp_tw_recycle — allow reusing and faster cleaning of TIME_WAIT sockets (in newer kernels, tcp_tw_recycle is disabled due to issues).
  • net.ipv4.tcp_max_syn_backlog — the maximum number of pending SYN connections.
  • net.ipv4.tcp_syncookies — enable SYN cookies to protect against SYN flood attacks.
  • net.core.somaxconn — the maximum queue size for listening sockets.
  • net.ipv4.tcp_rmem and net.ipv4.tcp_wmem — buffer sizes for TCP receive and send.
  • net.ipv4.tcp_congestion_control — selection of congestion control algorithm (e.g., cubic, bbr).

Example of configuration via sysctl:

sysctl -w net.ipv4.tcp_fin_timeout=30
sysctl -w net.ipv4.tcp_tw_reuse=1
sysctl -w net.core.somaxconn=1024

Configuration depends on load, application type, and performance requirements.