OnCallReadyStart learning

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-bpfcc

trace all TCP connect()s

$ sudo tcpconnect-bpfcc -t

include timestamps

$ sudo tcpconnect-bpfcc -d

include DNS queries associated with connects

$ sudo tcpconnect-bpfcc -p 181

only trace PID 181

$ sudo tcpconnect-bpfcc -P 80

only trace port 80

$ sudo tcpconnect-bpfcc -P 80,81

only trace port 80 and 81

$ sudo tcpconnect-bpfcc -4

only trace IPv4 family

$ sudo tcpconnect-bpfcc -6

only trace IPv6 family

Gotchas

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.