Network forensics¶
Who is listening, who is talking, and where packets die. All of these are in the base install or one package away.
Tested on Ubuntu 24.04 with iproute2 ss, OpenBSD netcat, iputils ping,
mtr 0.95 and tcpdump 4.99.
What is listening, and which process owns it?¶
The modern netstat -tulpn: TCP and UDP, listening sockets, process names,
no DNS lookups. netstat comes from net-tools, which most distributions no
longer install by default; ss reads the kernel directly and is faster on
busy hosts.
Which remote addresses hold the most connections?¶
ss -Htn state established | awk '{print $4}' \
| sed -E 's/:[0-9]+$//; s/^\[::ffff:(.*)\]$/\1/' \
| sort | uniq -c | sort -nr | head
One address with hundreds of connections is either your load balancer or the thing you are looking for.
Which process is talking to this address?¶
Is the port reachable from here?¶
-z connects without sending data, -w 3 gives up after three seconds.
"Timed out" usually means a firewall drops the packets; "connection refused"
means the host answered and nothing listens on the port.
Is the path MTU smaller than it should be?¶
# 1472 bytes of payload + 28 bytes of headers = 1500. Do not fragment.
ping -c 5 -M do -s 1472 example.com
If this fails while a normal ping works, something on the path has a smaller
MTU and drops large packets: the classic "SSH connects, then hangs" or "small
requests work, big ones time out". Lower -s until it passes to find the real
size.
Where along the path are packets lost?¶
Report mode (-r), wide output, IPs and AS numbers, 100 probes. Loss that
starts at one hop and continues to the end is real; loss on one middle
hop only is that router deprioritising replies to probes, and can be ignored.
Capture only new connection attempts¶
# SYN packets without ACK: every new TCP connection, nothing else.
sudo tcpdump -nni any 'tcp[tcpflags] & (tcp-syn|tcp-ack) == tcp-syn'
Small enough to leave running during an incident. Add -w syn.pcap to keep it
for Wireshark.