tcptracer(8)

πŸ“¦ version 0.36.1, in alpine 3.24, nixpkgs unstable, opensuse-leap 16.0

πŸ¦‹ 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: C for connect, A for accept, X for close πŸ’«.
  • PID β€” process ID πŸ†”.
  • COMM β€” process name 🏷️.
  • IP β€” IP address family (4 or 6) 🌍.
  • 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 πŸ’…πŸŽ€