Network Stack Tuning
Edit /etc/sysctl.conf:
# Increase connection backlog
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
# TCP buffer sizes
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 87380 16777216
# TCP connection handling
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 5
# Allow more local ports
net.ipv4.ip_local_port_range = 1024 65535sudo sysctl -pFile Descriptor Limits
Edit /etc/security/limits.conf:
* soft nofile 65535
* hard nofile 65535
root soft nofile 65535
root hard nofile 65535Systemd Service Limits
# For specific services like Nginx
[Service]
LimitNOFILE=65535Virtual Memory
# Reduce swappiness for servers
vm.swappiness = 10
# Increase file inotify watches (for apps watching many files)
fs.inotify.max_user_watches = 524288
# Increase maximum open files system-wide
fs.file-max = 2097152Verify Settings
# Check current limits
ulimit -n
cat /proc/sys/net/core/somaxconn
sysctl net.ipv4.tcp_fin_timeoutWhen to Tune
- "Too many open files" errors
- Connection timeouts under high load
- SYN flood protection needed
- High-traffic web servers (10,000+ concurrent connections)