tcpconnect-bpfcc: Trace TCP connects
tcpconnect-bpfcc [-h] [-t] [-p PID] [-P PORT] [-4 | -6] [-L] [-U] [-u UID] [-c] [--cgroupmap CGROUPMAP] [--mntnsmap MNTNSMAP] [-d]
What it does
Trace TCP connects. Part of the bcc tools (bpfcc-tools 0.35.0 on Ubuntu, installed as /usr/sbin/tcpconnect-bpfcc; upstream and other distributions call it tcpconnect). It loads an eBPF program, so it needs root.
Options you will use
-t, --timestamp- include timestamp on output
-p, --pid PID- trace this PID only
-P, --port PORT- comma-separated list of destination ports to trace.
-4, --ipv4- trace IPv4 family only
-6, --ipv6- trace IPv6 family only
-L, --lport- include LPORT on output
-U, --print-uid- include UID on output
-u, --uid UID- trace this UID only
-c, --count- count connects per src ip and dest ip/port
--cgroupmap CGROUPMAP- trace cgroups in this BPF map only
--mntnsmap MNTNSMAP- trace mount namespaces in this BPF map only
-d, --dns- include likely DNS query associated with each connect
Examples
$ sudo tcpconnect-bpfcctrace all TCP connect()s
$ sudo tcpconnect-bpfcc -tinclude timestamps
$ sudo tcpconnect-bpfcc -dinclude DNS queries associated with connects
$ sudo tcpconnect-bpfcc -p 181only trace PID 181
$ sudo tcpconnect-bpfcc -P 80only trace port 80
$ sudo tcpconnect-bpfcc -P 80,81only trace port 80 and 81
$ sudo tcpconnect-bpfcc -4only trace IPv4 family
$ sudo tcpconnect-bpfcc -6only trace IPv6 family
Gotchas
- Active TCP connections (connect()) with PID, addresses and port.
- As a normal user it fails with "could not open bpf map: ..., error: Operation not permitted" (unprivileged BPF is off on Ubuntu).
Try tcpconnect-bpfcc in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.