Linux defaults are conservative because the kernel runs on everything from embedded boards to bare-metal database hosts. On a busy cPanel host with thousands of sites and tens of thousands of mail connections per hour, several of those defaults are too low. The first symptoms are confusing: connection refused on a host that is not even busy, “too many open files” in error logs while the disk is empty, mysteriously dropped backend connections. The fix is a handful of sysctl values, set once.
What’s happening
The kernel limits we hit on cPanel hosts:
- fs.file-max — system-wide cap on open file descriptors. Each TCP connection, log file, MySQL table, and PHP-FPM worker counts. Default 9223372036854775807 on modern kernels, but per-process and per-user limits in
/etc/security/limits.confare often the real cap. - net.core.somaxconn — the listen() backlog size. Default 128, sometimes 4096. Too low and TCP SYN packets get dropped during traffic bursts; the client sees a connection timeout.
- net.ipv4.tcp_max_syn_backlog — SYN queue size before connection complete. Interacts with somaxconn.
- net.ipv4.ip_local_port_range — ephemeral port range. Default 32768-60999 gives ~28k usable ports. A busy host doing many outbound connections (mail relay, API calls) can exhaust this.
- net.netfilter.nf_conntrack_max — when conntrack is loaded (it always is when CSF/iptables stateful rules are in play), this caps tracked connections. Default 65536 on many distros; busy hosts hit this and connections get dropped silently.
- vm.swappiness — how eagerly the kernel swaps. Default 60; on a host with SSDs and MySQL, 10 is better.
How to verify
Current values:
sysctl -a | grep -E 'file-max|somaxconn|tcp_max_syn|ip_local_port|nf_conntrack_max|swappiness'
cat /proc/sys/fs/file-nr
cat /proc/net/sockstat
conntrack -C
file-nr shows allocated / unused / max. If allocated approaches max during peak hours, raise file-max.
conntrack -C shows current tracked connections. If it approaches nf_conntrack_max, the firewall is dropping new connections without logging much. Look in dmesg for nf_conntrack: table full, dropping packet — that is the smoking gun.
The fix
Add to /etc/sysctl.d/99-cpanel-perf.conf:
fs.file-max = 2097152
net.core.somaxconn = 4096
net.ipv4.tcp_max_syn_backlog = 4096
net.ipv4.ip_local_port_range = 10000 65535
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_tw_reuse = 1
net.netfilter.nf_conntrack_max = 524288
vm.swappiness = 10
vm.dirty_ratio = 15
vm.dirty_background_ratio = 5
Apply with sysctl -p /etc/sysctl.d/99-cpanel-perf.conf. Confirm with sysctl net.core.somaxconn and so on.
Pair with /etc/security/limits.conf to raise per-user file descriptor limits — without that, the system-wide file-max bump is meaningless for a process limited to 1024:
* soft nofile 65536
* hard nofile 131072
Re-login or restart affected services to pick up the new limits. Stack Harbor sets sysctl baselines per host as part of cPanel server administration.