How to Trace TCP SYN Backlog Queues in Linux Using tcpsynbl

TCP Three-Way Handshake Queuing and SYN Backlog Architecture

When an inbound TCP connection reaches a Linux server, the kernel manages its transition through two distinct queue stages before the application ever invokes accept(). The first stage is the SYN backlog queue (or half-open connection table). Upon receiving a TCP SYN segment, the kernel responds with a SYN-ACK packet and records the half-open connection state in the SYN backlog. Once the client returns the final ACK packet, the handshake completes, and the connection shifts into the listen accept queue (governed by the backlog argument passed to listen()).

If an application experiences sudden bursts of connection requests, or if an attacker initiates a SYN flood, the SYN backlog quickly approaches exhaustion. When the queue overflows, the kernel either engages TCP SYN cookies (causing TCP options like window scaling and selective acknowledgements to be lost or restricted) or silently drops incoming SYN packets entirely, causing clients to stall on connection timeouts. Traditional monitoring tools like ss or netstat only sample established sockets; they cannot capture instantaneous SYN queue depth at the microsecond moment inbound packets arrive.

The tcpsynbl utility, provided within the BPF Compiler Collection (BCC), attaches extended Berkeley Packet Filter (eBPF) kprobes directly to the kernel’s internal SYN handling functions: tcp_v4_syn_recv_sock() and tcp_v6_syn_recv_sock(). By sampling the SYN backlog occupancy whenever a handshake progresses, tcpsynbl constructs a log2 histogram revealing exact queue occupancy patterns, enabling systems engineers to diagnose connection bottlenecks and optimize kernel tuning before packet drops occur.

Installing BCC Tools and Kernel Headers on Linux

Because tcpsynbl dynamically compiles eBPF probes against kernel tracing hooks, the Linux host requires kernel development headers and BCC user-space tools.

On Ubuntu and Debian systems, install the toolset using APT:

# Update repositories and install BCC utilities along with kernel headers
sudo apt update
sudo apt install -y bpfcc-tools linux-headers-$(uname -r)

On Red Hat Enterprise Linux, Rocky Linux, or Fedora systems, install the packages via DNF:

# Install BCC tools and kernel headers on RHEL/Fedora
sudo dnf install -y bcc-tools kernel-devel-$(uname -r)

On Debian and Ubuntu distributions, the binary is installed under /usr/sbin/ with a -bpfcc suffix (e.g. tcpsynbl-bpfcc). Create a convenient symlink or verify executable access:

# Create convenient symlink for tcpsynbl
sudo ln -s /usr/sbin/tcpsynbl-bpfcc /usr/local/bin/tcpsynbl

# Verify executable readiness
tcpsynbl -h

Tracing Live SYN Backlog Occupancy via tcpsynbl

Running tcpsynbl without arguments hooks kernel SYN reception. The tool aggregates queue depth metrics in kernel memory maps with virtually zero performance overhead. When you press Ctrl+C, it renders an ASCII log2 histogram detailing SYN queue backlog sizes observed across all local listening sockets:

# Trace global TCP SYN backlog queue depth
sudo tcpsynbl

A typical trace output presents queue depth distributions:

Tracing SYN backlog size... Hit Ctrl-C to end.
^C
   backlog               : count     distribution
         0 -> 1          : 1254     |****************************************|
         2 -> 3          : 341      |**********                              |
         4 -> 7          : 88       |**                                      |
         8 -> 15         : 12       |                                        |
        16 -> 31         : 2        |                                        |
        32 -> 63         : 0        |                                        |

Evaluating the histogram distribution provides immediate clarity on queue health:

  • Left-skewed distribution (0 to 3): Indicates healthy socket handling where the application accepts connections rapidly, keeping the backlog clear.
  • Right-skewed or long-tailed distribution (64 to 512+): Warns that the queue is frequently operating near capacity. During load spikes, connections are at immediate risk of being dropped or subjected to SYN cookies.

Filtering by Bound Local Port

In production web environments hosting multiple daemons (such as an Nginx reverse proxy on port 443 alongside an internal Redis instance on port 6379), a global trace conflates separate workloads. Pass the -p parameter to restrict tracing exclusively to a targeted listening port:

# Trace SYN backlog depth exclusively for HTTPS port 443
sudo tcpsynbl -p 443

To inspect a database listener under load testing (such as PostgreSQL on port 5432):

# Monitor database listener SYN backlog during stress test
sudo tcpsynbl -p 5432

Isolating the port ensures performance metrics reflect the specific service under investigation without background noise from auxiliary management daemons.

Interpreting SYN Backlog Exhaustion vs Listen Backlog Limits

In the Linux TCP implementation, the maximum allowable SYN backlog is bounded by two distinct parameters:

  1. The application-level backlog integer passed to the listen(int sockfd, int backlog) system call.
  2. The global kernel parameter net.ipv4.tcp_max_syn_backlog.

The kernel calculates the effective queue limit as min(backlog, somaxconn, tcp_max_syn_backlog). If tcpsynbl shows queue depths plateauing at 128 or 256 while high connection rates cause dropped handshakes, query the active sysctl limits:

# Inspect global SYN backlog and listen queue limits
sysctl net.ipv4.tcp_max_syn_backlog
sysctl net.core.somaxconn

If tcp_max_syn_backlog is set to a low default (e.g. 512 or 1024), increase it to support high-concurrency microservices:

# Increase maximum SYN backlog limit
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=4096
sudo sysctl -w net.core.somaxconn=4096

Persist the tuned values by adding them to /etc/sysctl.d/99-syn-backlog.conf:

# Persist TCP queue tuning across reboots
cat <<EOF | sudo tee /etc/sysctl.d/99-syn-backlog.conf
net.ipv4.tcp_max_syn_backlog = 4096
net.core.somaxconn = 4096
EOF

sudo sysctl --system

By utilising tcpsynbl during stress testing and benchmark analysis, Linux administrators gain visibility into the earliest microsecond stages of TCP connection establishment, preventing handshake stalls and optimizing kernel transport queues.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.