Calculate maximum concurrent TCP connections a server can handle given port and memory limits.
Each outbound TCP connection to a given remote (IP, port) pair consumes one unique local (source IP, source port) combination, so the theoretical connection ceiling from a single host is the ephemeral port range size multiplied by the number of local source IPs available to bind from. In practice, connections lingering in TIME_WAIT after close continue to occupy their port for roughly 2×MSL, so the effective available capacity for new connections is lower than the theoretical maximum — a common bottleneck for high-throughput proxies and load generators making many short-lived outbound connections to the same destination.
Maximum connections
max_conns = ephemeral_port_range × local_IPs
`cat /proc/sys/net/ipv4/ip_local_port_range` prints the low and high bounds (default is often 32768–60999). Widen it with `sysctl -w net.ipv4.ip_local_port_range="10000 65535"` if you're hitting connection ceilings.
The (source IP, source port, dest IP, dest port) 4-tuple must be unique per connection to the same destination — binding outbound connections across multiple local IPs multiplies the number of distinct 4-tuples available, effectively giving each IP its own independent ephemeral port range against the same remote endpoint.
Enable `net.ipv4.tcp_tw_reuse=1` (safe for outbound/client connections), reduce `net.ipv4.tcp_fin_timeout`, or better, reuse persistent connections (HTTP keep-alive, connection pooling) so fewer short-lived connections are created in the first place.