🎉 DevOps Interview Prep Bundle is live — 1000+ Q&A across 20 topicsGet it →
All Cheatsheets

Networking Cheatsheet

Essential networking commands for DevOps engineers — curl, netstat, dig, tcpdump, iptables, and Kubernetes networking debugging.

7 sections69 commandsClick any row to copy

curl — HTTP Testing

curl -v https://api.example.com/health
curl -s -o /dev/null -w '%{http_code}' https://example.com
curl -X POST https://api.example.com/data \ -H 'Content-Type: application/json' \ -d '{"key":"value"}'
curl -H 'Authorization: Bearer TOKEN' https://api.example.com
curl -L https://example.com
curl -o file.tar.gz https://example.com/release.tar.gz
curl -w '\nDNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n' -s -o /dev/null https://example.com
curl --resolve example.com:443:1.2.3.4 https://example.com
curl -k https://self-signed.example.com
curl -x http://proxy:8080 https://example.com

Verbose — shows request/response headers

Print only HTTP status code

POST JSON request with headers

Request with auth header

Follow redirects

Download file

Time each phase of HTTP request

Test specific IP without changing DNS

Skip TLS certificate verification

Request through HTTP proxy

DNS Lookup

dig example.com
dig example.com A
dig example.com MX
dig example.com TXT
dig @8.8.8.8 example.com
dig +trace example.com
dig +short example.com
dig -x 1.2.3.4
nslookup example.com
nslookup example.com 1.1.1.1
host example.com

Full DNS lookup with details

Look up A (IPv4) record

Look up mail server records

Look up TXT records (SPF, verification)

Force DNS query to Google's server

Trace full DNS resolution path

Print only the IP address

Reverse DNS — IP to hostname

Simple DNS lookup

DNS lookup using Cloudflare's server

Quick hostname lookup

Port & Connection Testing

nc -zv hostname 443
nc -zv hostname 22 80 443
nc -zvu hostname 53
ss -tlnp
ss -tlnp | grep ':8080'
ss -s
netstat -tlnp
lsof -i :8080
lsof -i tcp -P -n | grep LISTEN
fuser 8080/tcp

Test if TCP port 443 is open

Test multiple ports

Test UDP port (DNS)

All listening TCP ports with process info

Find what's listening on port 8080

Socket statistics summary

Listening ports (older systems)

Process using port 8080

All listening TCP connections

PID of process using port 8080

Network Interfaces & Routes

ip addr show
ip addr show eth0
ip route show
ip route get 8.8.8.8
ip link show
ip neigh show
route -n
ifconfig
ethtool eth0
ping -c 4 google.com
mtr google.com
traceroute google.com

Show all interfaces and IP addresses

Show specific interface details

Show routing table

Which interface routes to this IP

Show all network interfaces (without IPs)

Show ARP table (MAC to IP mapping)

Show routing table (older style)

Network interface info (older systems)

Network interface speed and settings

Send 4 ICMP pings to test connectivity

Continuous traceroute with statistics

Trace network path to destination

Packet Capture — tcpdump

tcpdump -i eth0
tcpdump -i eth0 port 80
tcpdump -i eth0 host 10.0.0.5
tcpdump -i eth0 -w capture.pcap
tcpdump -r capture.pcap
tcpdump -i eth0 'tcp port 443 and host 1.2.3.4'
tcpdump -i any -A 'port 8080'
tcpdump -i eth0 -n -q 'tcp[tcpflags] == tcp-rst'

Capture all traffic on eth0

Capture HTTP traffic only

Capture traffic to/from specific IP

Save capture to file (open in Wireshark)

Read previously saved capture

Capture HTTPS traffic to specific IP

Capture and print ASCII content on port 8080

Capture TCP RST packets (connection resets)

iptables & Firewall

iptables -L -n -v
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -s 10.0.0.0/8 -j ACCEPT
iptables -A INPUT -j DROP
iptables -D INPUT -p tcp --dport 80 -j ACCEPT
iptables -F
iptables-save > /etc/iptables/rules.v4
iptables-restore < /etc/iptables/rules.v4
ufw allow 22/tcp
ufw status verbose

List all rules with packet counts

Allow incoming TCP on port 80

Allow traffic from subnet

Drop all other incoming traffic

Delete a specific rule

Flush (delete) all rules

Save current rules

Restore saved rules

Allow SSH (Ubuntu firewall)

Show UFW rules

Kubernetes Networking Debug

kubectl run netdebug --image=nicolaka/netshoot --rm -it --restart=Never
kubectl exec netdebug -- curl my-service.my-namespace.svc.cluster.local
kubectl exec netdebug -- nslookup my-service.my-namespace
kubectl exec netdebug -- ss -tlnp
kubectl get endpoints my-service -n my-namespace
kubectl describe networkpolicy -n my-namespace
kubectl logs -n kube-system -l k8s-app=kube-dns
kubectl exec pod -- wget -qO- http://10.96.0.1/api/v1/namespaces

Launch debug pod with networking tools

Test service connectivity from inside cluster

DNS lookup from inside cluster

Check ports from inside cluster

Check which pods are behind a service

Show NetworkPolicy rules

CoreDNS logs for DNS issues

Test Kubernetes API server access from pod