tcptracer(8)
π¦ tcptracer(8) π¦
β¨ NAME β¨
tcptracer - Trace TCP established connections. Uses Linux eBPF/bcc. π
π§ SYNOPSIS π§
tcptracer [-h] [-v] [-t] [-p PID] [-N NETNS] [--cgroupmap MAPPATH]
[--mntnsmap MAPPATH] [-4 | -6]
π DESCRIPTION π
okay so this tool traces established TCP connections that open and close while it's running, and it prints a line of output for every connect, accept and close event π₯. Each line tells you the type of event, the PID, the IP addresses and the ports. literally so useful π
this tool works using kernel dynamic tracing, which means it'll need an update if the kernel implementation changes π. Only established TCP connections get traced, so the overhead is expected to be pretty low, which is very giving β¨.
since this uses BPF, only the root user can use this tool π. not me trying to run it as a regular user π.
π REQUIREMENTS π
you'll need CONFIG_BPF and bcc πΈ.
π OPTIONS π
-hβ prints the usage message π.-vβ prints full lines, with long event type names and network namespace numbers π.-tβ includes a timestamp in the output β°.-p PIDβ traces only this process ID, filtered in-kernel π―.-N NETNSβ traces only this network namespace, filtered in-kernel π.--cgroupmap MAPPATHβ traces only the cgroups in this BPF map, filtered in-kernel ποΈ.--mntnsmap MAPPATHβ traces mount namespaces in the map, filtered in-kernel π§©.-4β traces the IPv4 family only π¦.-6β traces the IPv6 family only πΈ.
π EXAMPLES π
Trace all TCP established connections:
# tcptracer
Trace all TCP established connections with verbose lines:
# tcptracer -v
Trace PID 181 only:
# tcptracer -p 181
Trace connections in network namespace 4026531969 only:
# tcptracer -N 4026531969
Trace a set of cgroups only (see special_filtering.md from the bcc sources for more details, it's lowkey a must-read π):
# tcptracer --cgroupmap /sys/fs/bpf/test01
Trace IPv4 family only:
# tcptracer -4
Trace IPv6 family only:
# tcptracer -6
π«Ά FIELDS π«Ά
TYPEβ type of event. In non-verbose mode:Cfor connect,Afor accept,Xfor close π«.PIDβ process ID π.COMMβ process name π·οΈ.IPβ IP address family (4or6) π.SADDRβ source IP address π€.DADDRβ destination IP address π₯.SPORTβ source port πͺ.DPORTβ destination port ποΈ.NETNSβ network namespace where the event originated π.
π OVERHEAD π
this traces the kernel inet accept function, plus the TCP connect, close, and set state functions. However, it only prints information for connections that are established, so it shouldn't have a huge overhead π₯°.
as always, test and understand this tool's overhead for your types of workloads before using it in production π.
β οΈ bestie, seriously, test this before production. no shortcuts π
π SOURCE π
this is from bcc π. the repo lives at:
https://github.com/iovisor/bcc
also look in the bcc distribution for a companion _examples.txt file. it has example usage, output, and commentary for this tool π.
π₯οΈ OS π₯οΈ
Linux π§
π§ STABILITY π§
Unstable - still in development π οΈ.
π AUTHOR π
Iago LΓ³pez Galeiras βοΈ
π¦ SEE ALSO π¦
tcpaccept(8), tcpconnect(8), tcptop(8), tcplife(8) β¨
bestie, that's the whole tea βπ this came from the tcptracer(8) page, sourced from bcc, dated 2020-02-20, in the USER COMMANDS section. slay the tracing π π
π¦ where this page comes from
- centos-stream 10: bcc-tools 0.36.1-1.el10 Β· Apache-2.0
- centos-stream 9: bcc-tools 0.36.1-1.el9 Β· ASL 2.0
- fedora 43: bcc-tools 0.35.0-2.fc43 Β· Apache-2.0
- fedora 44: bcc-tools 0.35.0-5.fc44 Β· Apache-2.0
- π girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms