Usage

Flags, examples, and output format reference.

proc-trace-net [-ctUurQ46] [-o FILE] [-p PID[,PID,...] | CMD...]
FlagArgumentDescription
๐ŸŽจ-cForce-enable ANSI color output. Auto-detected when stdout is a tty; NO_COLOR=1 disables it.
โฑ๏ธ-tShow elapsed duration when a connection closes. Appends timing to the close (ร—) line.
๐Ÿ”„-UShow TCP state update events โ€” ESTABLISHED, FIN_WAIT, TIME_WAIT transitions. Shown with a โ‡’ marker.
๐Ÿ‘ค-uPrint owning user of each connection as <username>. Root in red, other users in green.
๐Ÿ”-rPerform reverse DNS lookup on remote addresses. Replaces raw IPs with hostnames where available.
๐Ÿ”‡-QSuppress error messages (e.g. inode lookup failures). Useful for long-running background monitoring.
4๏ธโƒฃ-4Show IPv4 connections only. Mutually exclusive with -6.
6๏ธโƒฃ-6Show IPv6 connections only. Mutually exclusive with -4.
๐Ÿ“-oFILEAppend output to FILE instead of stdout. Colors are disabled for file output unless -c is also set.
๐ŸŽฏ-pPID[,PID,...]Only show connections owned by the given PID(s). Accepts a comma-separated list.

Anatomy of an output line

Each connection event produces one line. Symbols indicate direction and state. With -t, close lines include elapsed duration.

3892 PID โ€” process ID in amber
curl process name (from /proc/<pid>/comm) in cyan
<root> user in red (root) or green (other) โ€” only with -u
TCP protocol (TCP or UDP) in dim grey
10.0.2.15:54321 local address in green
โ†’ direction: โ†’ outbound (local initiated), โ† inbound (remote initiated)
โ† inbound connection in purple
ร— connection closed in red
โ‡’ TCP state update (ESTABLISHED, FIN_WAIT, etc.) โ€” only with -U
93.184.216.34:443 remote address in amber
0.342s connection duration in cyan โ€” close lines only, with -t

System-wide monitoring with color, timing, and user

The most useful default invocation. Watch every TCP/UDP connection machine-wide with colors, close timing, and user context.

system-wide (-ctu)
$ sudo proc-trace-net -ctu
 1234 sshd        <root>  TCP  10.0.2.15:22              โ†  203.0.113.7:41002
 2341 systemd-r   <root>  UDP  10.0.2.15:46012           โ†’  8.8.8.8:53
 3892 curl        <rick>  TCP  10.0.2.15:54321           โ†’  93.184.216.34:443
 3892 curl        <rick>  TCP  10.0.2.15:54321           ร—  93.184.216.34:443   0.342s

CMD mode โ€” trace a single command

Pass a command after the flags to trace only its network connections. proc-trace-net will exit when the command completes.

cmd mode
$ sudo proc-trace-net -ct curl https://github.com
 9812 curl         TCP  10.0.2.15:48201           โ†’  140.82.114.4:443
 9812 curl         TCP  10.0.2.15:48201           ร—  140.82.114.4:443    0.218s

Close timing (-ct)

The -t flag appends connection duration to close events. Spot hung or unusually long connections at a glance.

close timing (-ct)
$ sudo proc-trace-net -ct
 5501 nginx        TCP  10.0.2.15:80              โ†  192.168.1.5:52341
 5501 nginx        TCP  10.0.2.15:80              ร—  192.168.1.5:52341   0.004s
 7210 postgres     TCP  10.0.2.15:5432            โ†  127.0.0.1:41092
 7210 postgres     TCP  10.0.2.15:5432            ร—  127.0.0.1:41092     142.001s

TCP state updates (-cU)

The -U flag shows every TCP state transition โ€” useful for debugging connection teardown issues or TIME_WAIT accumulation.

state updates (-cU)
$ sudo proc-trace-net -cU
 3892 curl         TCP  10.0.2.15:54321           โ†’  93.184.216.34:443
 3892 curl         TCP  10.0.2.15:54321           โ‡’  93.184.216.34:443   ESTABLISHED
 3892 curl         TCP  10.0.2.15:54321           โ‡’  93.184.216.34:443   FIN_WAIT
 3892 curl         TCP  10.0.2.15:54321           ร—  93.184.216.34:443

PID filter โ€” watch nginx only (-p)

Use -p with a comma-separated list of PIDs to monitor only specific processes. Combine with pgrep for dynamic PID lookup.

pid filter (-p)
$ sudo proc-trace-net -ct -p $(pgrep nginx | paste -sd,)

Log to file silently (-Qo)

Run in the background, suppressing all error noise, writing a connection log for later analysis.

background logger
$ sudo proc-trace-net -Qto /var/log/connections.log &
[1] 9981

IPv4 only (-4)

Filter to only IPv4 connections. Useful to reduce noise in dual-stack environments.

ipv4 only (-4)
$ sudo proc-trace-net -4 -ct

Reverse DNS (-r)

The -r flag resolves remote IPs to hostnames. Adds latency but makes output much more readable for auditing.

reverse dns (-r)
$ sudo proc-trace-net -ctr
 3892 curl         TCP  10.0.2.15:54321           โ†’  server-93-184-216-34.example.com:443
 2341 systemd-r    UDP  10.0.2.15:46012           โ†’  dns.google:53