هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
The quick answer
tcpdump -D
tcpdump -i eth0 -nn 'host 10.0.2.21 and port 5432'
tcpdump -i any -nn -c 2000 -w /tmp/app-db.pcap 'port 5432'
tcpdump -nn -r /tmp/app-db.pcap | head-nn = no DNS and no port names (faster, clearer). -w saves a file; open it later in Wireshark.
Step by step
- Install and find the interface:
dnf -y install tcpdump
apt-get install -y tcpdump
tcpdump -D- Always use a filter — a busy server sends millions of packets:
| Filter | Captures |
|---|---|
host 10.0.2.21 | Everything to or from that IP. |
port 443 / tcp port 5432 | One port. |
src 203.0.113.50 and dst port 22 | One direction. |
net 10.0.0.0/16 | A whole network. |
'tcp[tcpflags] & (tcp-syn|tcp-rst) != 0' | Only connection starts and resets. |
udp port 53 | DNS. |
not port 22 | Hide your own SSH session. |
- Read the TCP flags in the output:
tcpdump -i eth0 -nn 'tcp port 5432 and host 10.0.2.21'
10:42:01.120 IP 10.0.1.11.48122 > 10.0.2.21.5432: Flags [S], seq 123, win 64240
10:42:02.121 IP 10.0.1.11.48122 > 10.0.2.21.5432: Flags [S], seq 123, win 64240| You see | Means |
|---|---|
[S] again and again, no [S.] | No answer: firewall drops, or the host is down. |
[S] then [R.] | Nothing listens on the port (connection refused). |
[S], [S.], [.] | Handshake OK — the problem is higher (TLS, auth, app). |
| Many retransmissions | Packet loss on the way. |
- Save to a file for Wireshark or a colleague — limit size and time:
tcpdump -i eth0 -nn -s 0 -c 5000 -w /tmp/web.pcap 'port 443'
tcpdump -i eth0 -nn -G 300 -W 12 -w '/var/tmp/cap-%H%M.pcap' 'port 443'The second line writes a new file every 5 minutes and keeps 12 files (one hour) — for problems that come and go.
- Plain HTTP or DNS content (TLS content is encrypted — you see only the handshake):
tcpdump -i eth0 -nn -A -s 0 'tcp port 80' | grep -E 'GET|POST|Host:'
tcpdump -i any -nn 'udp port 53'- Inside a container or Pod:
kubectl debug -it api-6d8f9c7b5d-x2kq9 -n shop --image=nicolaka/netshoot:v0.13 --target=api -- tcpdump -i any -nn port 5432
nsenter -t $(docker inspect -f '{{.State.Pid}}' api) -n tcpdump -i any -nn port 5432- Rules: captures can contain passwords, cookies and personal data. Capture only with permission, only what you need (filters,
-c), keep the file600, delete it when done.
Check that it worked
You can tell where the conversation stops: no SYN-ACK (network/firewall), a RST (nothing listens / something closes it), or a full handshake (look at TLS or the app). Then delete the capture files.
Common problems
| Problem | Cause | Fix |
|---|---|---|
tcpdump: … You don't have permission | Needs root (or the CAP_NET_RAW capability). | Run with sudo. |
| Nothing is captured | Wrong interface (VPN, bridge, container). | tcpdump -D; try -i any. |
| Too much output, terminal freezes | No filter, or name lookups. | Add a filter and -nn; write to a file with -w. |
| The file is huge | No -c or rotation. | -c COUNT, or -G/-W rotation. |
| You can not read HTTPS content | TLS encryption (on purpose). | Look at the handshake; use app logs or debug at the proxy for content. |
| Packets look "missing" on a busy host | The kernel dropped them (dropped by kernel at the end). | Stronger filter; write to a file; bigger buffer -B 4096. |
Go further
- Command pages: ss, ip, kubectl.
- Next how-tos: Test if a remote port is open, List open network connections, Open a shell in a running Pod.
- Full guides: Suricata (network IDS), Nmap. Learn it: CKA — Troubleshoot the network.
1You see the client's [S] again and again, but never [S.]. What does it mean?
The SYN gets no answer: a firewall drops it, or the host is down or unreachable.
2Why use -nn?
No DNS and port-name lookups: the output is faster and shows the real IPs and port numbers.