Skip to content
ohsudo, Home
Networking

Linux Networking Cheat Sheet

The Linux network commands you use when something can't connect: addresses and routes, listening ports, DNS, curl, reachability, packet capture, MTU and firewalls.

Updated November 15, 2026 · Applies to Ubuntu · Debian · RHEL / Rocky · iproute2

Addresses, routes, neighbours

Terminal window
ip -br a # addresses, one line per interface
ip r # routing table
ip r get 8.8.8.8 # which route and source address
ip -br link # interfaces up or down
ip neigh # ARP / neighbour table
hostname -I # this machine's addresses

What listens, what’s connected

Terminal window
sudo ss -tulpn # listening TCP/UDP, with the program
sudo ss -tlnp 'sport = :443' # who has port 443
ss -tn state established # open TCP connections
sudo lsof -i :8080 # which process uses port 8080

0.0.0.0:80 listens everywhere; 127.0.0.1:80 only on this machine.

DNS

Terminal window
getent hosts example.com # what programs on this machine will get
dig +short example.com # ask DNS directly
dig @1.1.1.1 example.com # ask a specific server
dig +short -x 203.0.113.10 # reverse lookup
dig +trace example.com # follow it from the root
resolvectl status # which DNS servers (systemd-resolved)
cat /etc/resolv.conf

getent follows /etc/hosts; dig doesn’t.

HTTP with curl

Terminal window
curl -I https://example.com # headers only
curl -v https://example.com -o /dev/null # TLS and headers in detail
curl -L https://example.com # follow redirects
curl --resolve example.com:443:203.0.113.10 https://example.com/ # skip DNS
curl -w 'dns=%{time_namelookup} connect=%{time_connect} tls=%{time_appconnect} total=%{time_total}\n' -o /dev/null -s https://example.com
curl -k https://localhost:8443/ # ignore the certificate (testing only)

Can I reach it?

Terminal window
ping -c 4 10.0.0.5
nc -zv 10.0.0.5 5432 # is this TCP port open?
nc -zvu 10.0.0.5 53 # UDP (not reliable)
tracepath example.com # path and MTU, no root needed
mtr -rwc 20 example.com # loss per hop
ping -M do -s 1472 -c 2 10.0.0.5 # does 1500 MTU pass unfragmented?
Result Usually means
Connection refused Host is up, nothing listens on that port
Connection timed out A firewall drops it, or the host is down
No route to host No route, or a firewall rejects with ICMP
Name or service not known DNS has no answer for that name

Capture packets

Terminal window
sudo tcpdump -i any -nn port 443 # see traffic on 443
sudo tcpdump -i eth0 -nn host 10.0.0.5 and port 5432
sudo tcpdump -i any -nn -c 20 'tcp[tcpflags] & tcp-syn != 0' # connection attempts
sudo tcpdump -i any -w cap.pcap port 53 # save for Wireshark

Firewalls

Terminal window
sudo ufw status verbose # Ubuntu
sudo ufw allow 443/tcp
sudo firewall-cmd --list-all # RHEL, Rocky
sudo firewall-cmd --add-port=443/tcp --permanent && sudo firewall-cmd --reload
sudo nft list ruleset # what the kernel really has

Common errors

The Subnet Calculator and Port Lookup help with addresses and ports.

Other cheat sheets