Addresses, routes, neighbours
ip -br a # addresses, one line per interfaceip r # routing tableip r get 8.8.8.8 # which route and source addressip -br link # interfaces up or downip neigh # ARP / neighbour tablehostname -I # this machine's addressesWhat listens, what’s connected
sudo ss -tulpn # listening TCP/UDP, with the programsudo ss -tlnp 'sport = :443' # who has port 443ss -tn state established # open TCP connectionssudo lsof -i :8080 # which process uses port 80800.0.0.0:80 listens everywhere; 127.0.0.1:80 only on this machine.
DNS
getent hosts example.com # what programs on this machine will getdig +short example.com # ask DNS directlydig @1.1.1.1 example.com # ask a specific serverdig +short -x 203.0.113.10 # reverse lookupdig +trace example.com # follow it from the rootresolvectl status # which DNS servers (systemd-resolved)cat /etc/resolv.confgetent follows /etc/hosts; dig doesn’t.
HTTP with curl
curl -I https://example.com # headers onlycurl -v https://example.com -o /dev/null # TLS and headers in detailcurl -L https://example.com # follow redirectscurl --resolve example.com:443:203.0.113.10 https://example.com/ # skip DNScurl -w 'dns=%{time_namelookup} connect=%{time_connect} tls=%{time_appconnect} total=%{time_total}\n' -o /dev/null -s https://example.comcurl -k https://localhost:8443/ # ignore the certificate (testing only)Can I reach it?
ping -c 4 10.0.0.5nc -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 neededmtr -rwc 20 example.com # loss per hopping -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
sudo tcpdump -i any -nn port 443 # see traffic on 443sudo tcpdump -i eth0 -nn host 10.0.0.5 and port 5432sudo tcpdump -i any -nn -c 20 'tcp[tcpflags] & tcp-syn != 0' # connection attemptssudo tcpdump -i any -w cap.pcap port 53 # save for WiresharkFirewalls
sudo ufw status verbose # Ubuntusudo ufw allow 443/tcpsudo firewall-cmd --list-all # RHEL, Rockysudo firewall-cmd --add-port=443/tcp --permanent && sudo firewall-cmd --reloadsudo nft list ruleset # what the kernel really hasCommon errors
Temporary failure in name resolutionConnection timed outvsConnection refusedNo route to hostAddress already in usesudo: unable to resolve hostSSL routines::wrong version number
The Subnet Calculator and Port Lookup help with addresses and ports.