Skip to content

Linux & shell: Packet capture & network debugging

10 Linux & shell commands: Packet capture & network debugging. Click a command to see what each part does.

Index
10 items
Click a command to see what each part does.

Packet capture & network debugging10

  • sudo tcpdump -i any -nn port <port>Capture traffic on a port

    What each part does

    1. tcpdumppacket capture
    2. -i anyall interfaces
    3. -nndon't resolve names or ports
    4. port <port>filter: only traffic on that port (also host <ip>, tcp, udp)
  • sudo tcpdump -i <interface> -w <file>.pcap -c 10000 host <ip>Save a capture for Wireshark

    What each part does

    1. -w <file>.pcapwrite raw packets to a file
    2. -c 10000stop after 10,000 packets
    3. host <ip>only traffic to or from this IP
  • ip route get <ip>Which route and source IP would be used?

    What each part does

    1. ip route getthe exact route, gateway, interface and source address the kernel would use
  • mtr -rwc 50 <host>Path and packet loss to a host

    What each part does

    1. mtrtraceroute and ping combined, per hop
    2. -r -wreport mode with wide (untruncated) host names
    3. -c 5050 probes per hop
  • nmap -Pn -p 1-1024 <host>Scan a host's open ports

    What each part does

    1. nmapport scanner (only scan hosts you're allowed to)
    2. -Pnskip the ping check (many hosts block ping)
    3. -p 1-1024port range (or -p 22,80,443)
  • ss -sSocket summary

    What each part does

    1. ss -stotals of TCP states: established, time-wait, orphaned; spot connection leaks
  • ss -tn state established | awk 'NR>1 {split($4,a,":"); print a[1]}' | sort | uniq -c | sort -rn | headConnections per remote IP

    What each part does

    1. ss -tn state establishedopen TCP connections, numeric
    2. awk '...'take the peer address column and strip the port
    3. sort | uniq -c | sort -rn | headcount per IP, busiest first
  • ip neighARP / neighbour table

    What each part does

    1. ip neighIP to MAC mappings; FAILED or INCOMPLETE entries point to layer 2 problems
  • curl -sv --resolve <host>:443:<ip> https://<host>/Test a URL against a specific IP (skip DNS)

    What each part does

    1. --resolve <host>:443:<ip>use this IP for that host and port, keeping the right SNI and Host header
    2. -svquiet progress, verbose headers and TLS
  • nc -l <port>Listen on a port to test reachability

    What each part does

    1. nc -l <port>listen; from another machine nc -zv <host> <port> or curl shows whether traffic gets through

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…