This tool traces active TCP connections (eg, via a connect() syscall; accept() are passive connections). This can be useful for general troubleshooting to see what connections are initiated by the local server.
All connection attempts are traced, even if they ultimately fail.
This works by tracing the kernel tcp_v4_connect() and tcp_v6_connect() functions using dynamic tracing, and will need updating to match any changes to these functions.
Since this uses BPF, only the root user can use this tool.
CONFIG_BPF and bpftrace.
- Trace all active TCP connections:
Time of the call, in HH:MM:SS format.
Source IP address.
Destination IP address.
This traces the kernel tcp_v_connect functions and prints output for each event. As the rate of this is generally expected to be low (< 1000/s), the overhead is also expected to be negligible. If you have an application that is calling a high rate of connects()s, such as a proxy server, then test and understand this overhead before use.
This is from bpftrace
Also look in the bpftrace distribution for a companion _examples.txt file containing example usage, output, and commentary for this tool.
This is a bpftrace version of the bcc tool of the same name. The bcc tool may provide more options and customizations.
Unstable - in development.
Brendan Gregg, adapted for bpftrace by Dale Hamel
tcpaccept(8), funccount(8), tcpdump(8)
bcc-tcpaccept(8), bcc-tcpconnlat(8), bcc-tcpdrop(8), bcc-tcplife(8), bcc-tcpretrans(8), bcc-tcprtt(8), bcc-tcpstates(8), bcc-tcptop(8), bcc-tcptracer(8), tcpaccept(8), tcpdrop(8), tcpretrans(8).