Linux Networking Cheatsheet
Operational reference for the Linux networking toolkit. Sockets, routes, firewalls (iptables/nftables), packet capture (tcpdump), TLS debugging (openssl), and the eBPF-era diagnostics for the moments a connection just will not establish.
Inspecting interfaces, addresses, routes
5 commandsip a / ip addr showShow all interfaces and their addresses. Modern replacement for ifconfig.
Production note: On Kubernetes nodes, look for veth* (pod), cni0/flannel.1 (CNI), eth0 (host).
ip r / ip route showShow the kernel routing table.
Production note: On a misbehaving pod, compare to a healthy pod's routes — CNI mistakes often show up here.
ip -s link show <iface>Per-interface byte/packet counters and error stats.
Production note: Drops climbing on an interface = MTU mismatch, NIC saturation, or buffer issue.
ip neigh / ip nARP / neighbor table. Stale entries cause "destination unreachable" symptoms.
Production note: Force refresh with `ip neigh flush all` if you suspect ARP poisoning or stale entries after a node move.
ip netns listList network namespaces. Each Kubernetes pod runs in its own.
Production note: Enter a pod's netns from the node: `nsenter -t <PID> -n <command>`.
Sockets and listening ports
4 commandsss -tlnpTCP listening sockets with the owning process. -t TCP, -l listening, -n numeric, -p process.
Production note: Modern replacement for `netstat -tlnp`. Faster and shows more detail.
ss -tunapAll TCP+UDP sockets including established connections.
Production note: Look at Recv-Q / Send-Q columns to spot backlog.
ss -t state established '( dport = :443 )'Filter sockets by state and port. Useful when investigating TLS connection counts.
Production note: ss filters are more powerful than grep — fewer false positives in port-number matches.
lsof -i :443Which process is listening on a port. Falls back when ss output is overwhelming.
Production note: Pair with `lsof -p <pid>` to see all of a process's open files and sockets.
Connectivity testing
5 commandscurl -v https://example.comVerbose HTTPS request. Shows DNS, connect, TLS handshake, request, response.
Production note: Add --resolve example.com:443:1.2.3.4 to bypass DNS for testing a specific origin.
curl --connect-timeout 5 -o /dev/null -s -w "%{http_code} %{time_total}\n" URLLatency and status without body. Loop with watch for SLO-style probing.
Production note: Combine with `-o /dev/null --write-out "%{ssl_verify_result} %{remote_ip} %{time_namelookup} %{time_connect} %{time_starttransfer}"` for full timing breakdown.
nc -zv host port / ncat -zv host portTCP connect test. -z just probes, -v reports outcome.
Production note: Use to differentiate "DNS works but port is blocked" from "DNS is broken".
mtr -rwn host (or traceroute -T -p 443 host)Path-by-path latency and loss. -T uses TCP (passes most firewalls vs ICMP).
Production note: Run from both endpoints — asymmetric paths and loss show up immediately.
dig +trace example.com / dig @8.8.8.8 example.comDNS resolution path. +trace walks from root to authoritative.
Production note: `dig +short TXT _dmarc.example.com` for DMARC, etc. Always specify the resolver in incident debugging.
Packet capture and analysis (tcpdump)
4 commandstcpdump -i any -nn -s0 -w cap.pcap port 443Capture full-length packets on any interface. -nn suppresses name resolution; -s0 grabs full packet (essential for TLS analysis).
Warning: Captures contain plaintext for non-TLS traffic. Treat capture files as sensitive — store on encrypted volumes, scrub before sharing.
tcpdump -i eth0 -nn host 1.2.3.4 and port 443Filter by host and port. tcpdump's BPF filter language is concise.
Production note: Common filters: `tcp[tcpflags] & (tcp-syn|tcp-fin) != 0` (connection setup/teardown), `not port 22` (skip SSH noise).
tcpdump -i any -A -nn port 80ASCII dump of packets — readable for plaintext HTTP debugging.
Warning: Body content is in capture; never run on a production interface carrying customer data without explicit authorization.
tshark -i any -Y "http.response.code >= 500" -T fields -e ip.src -e http.hostCLI Wireshark with display filter. Grep-like for packet streams.
Production note: tshark is great in CI / scripts. For interactive analysis, capture with tcpdump and open the pcap in Wireshark GUI.
TLS debugging (openssl)
5 commandsopenssl s_client -connect example.com:443 -servername example.comOpen a TLS session and dump the cert chain. -servername sends SNI (required for most modern hosts).
Production note: Add -showcerts to print the entire chain in PEM. Pipe to `openssl x509 -text -noout` to inspect each cert.
openssl x509 -in cert.pem -noout -dates -subject -issuerParse a certificate file. Check expiry, subject, issuer in one line.
Production note: Add `-ext subjectAltName` to see SANs — vital for debugging "cert valid for X but I requested Y" errors.
openssl verify -CAfile chain.pem cert.pemVerify a cert against a CA bundle.
Production note: When a system trust store complains, use this to isolate "is the cert + chain self-consistent" from "does this OS trust the issuing CA".
curl --cacert chain.pem -v https://example.comTest with a custom CA bundle without modifying system stores.
Production note: Quick way to validate an internal CA before deploying it to nodes / containers.
openssl s_client -connect host:443 -tls1_2 / -tls1_3Force a specific TLS version. Useful for negotiating with legacy peers.
Warning: TLS 1.0 and 1.1 are deprecated and should be disabled in production. Use this only for debugging legacy systems.
Firewall: iptables / nftables
5 commandsiptables -L -n -v --line-numbersList all chains with packet counters and line numbers. Counters help identify which rules are actually being hit.
Production note: On modern distros, prefer nftables (`nft list ruleset`). iptables-nft preserves the iptables CLI on top of nftables.
iptables -t nat -L -nNAT table — DNAT/SNAT rules. Critical for understanding Kubernetes service routing.
Production note: On Kubernetes nodes, `iptables -t nat -L KUBE-SERVICES -n` shows how kube-proxy maps Service IPs to pod IPs.
iptables -A INPUT -p tcp --dport 22 -j DROPDrop incoming SSH. Example of an explicit firewall rule.
Warning: Modifying iptables on a remote host can lock you out. Always test with `at` to schedule a rollback if connection is lost.
nft list rulesetnftables — the modern Linux firewall framework.
Production note: nftables uses sets and maps for efficient rule matching at scale; iptables degrades linearly above a few hundred rules.
iptables-save / iptables-restoreBackup and restore the rule set. Always run iptables-save before making changes.
Production note: Persist rules with iptables-persistent (Debian/Ubuntu) or netfilter-persistent so they survive reboots.
eBPF-era observability
4 commandsss --tcp-infoPer-connection TCP stats: RTT, retransmits, congestion window. eBPF-backed in modern kernels.
Production note: Spotting elevated retransmits or low cwnd points to packet loss or path MTU issues.
bpftrace -e 'kprobe:tcp_sendmsg { @[comm] = count(); }'eBPF one-liner: count tcp_sendmsg calls per process. The "what is sending traffic" question, answered without restarting.
Production note: bpftool, BCC, and bpftrace are the modern observability stack — minimal overhead, no kernel modules.
tcpdrop (BCC tool)Trace why TCP packets are being dropped at the kernel level. Essential when retransmits climb without a clear cause.
Production note: Part of the bcc-tools package. The whole bcc/ suite is gold for production debugging.
cilium hubble observeCilium's eBPF-based flow visibility — pod-to-pod traffic with policy decisions.
Production note: In Cilium-managed clusters, this replaces tcpdump for east-west traffic analysis.
Common misconfigurations
The unsafe pattern, the replacement, and the reason the two are not equivalent in production.
Risky
# Use ICMP ping for connectivity test
ping -c 3 example.comHardened
# TCP probe at the actual port
curl --connect-timeout 5 -o /dev/null -s -w "%{http_code}\n" https://example.com
# or
nc -zv example.com 443Why it matters: ICMP is blocked by many firewalls and load balancers — a failing ping doesn't mean the service is down. Always probe the protocol your application uses, on the actual port.
Risky
# Capture only header (truncated)
tcpdump -i any -s 100 host 1.2.3.4Hardened
# Capture full packets
tcpdump -i any -s 0 -w trace.pcap host 1.2.3.4
# (-s 0 means full packet length;
# open in Wireshark for analysis)Why it matters: -s 100 captures only 100 bytes per packet — enough for the TCP header but not the application payload. TLS handshakes, HTTP bodies, and DNS responses get truncated. Almost never what you want.
Risky
# Test cert expiry by visiting in browser
firefox https://api.example.comHardened
# Scriptable cert expiry check
echo | openssl s_client -connect api.example.com:443 -servername api.example.com 2>/dev/null \
| openssl x509 -noout -enddate
# notAfter=Jul 15 23:59:59 2025 GMTWhy it matters: Browsers cache certs and may show stale data. The openssl s_client one-liner gives you the actual cert the server presents right now — the canonical answer for "when does this cert expire" and the right primitive for monitoring scripts.
Related learning paths
Cloud Native Security Engineering
Free 16-module course covering networking-aware security from PodSecurity to service mesh.
ContinueService Mesh Security module
How Linux networking primitives compose into a service-mesh data plane.
ContinueKubernetes Security Cheatsheet
NetworkPolicy patterns for the cluster-scoped equivalent of a firewall.
Continue