Networking
The tools, numbers and records you need to find out why two machines cannot talk.
Look at the host
ip addr | ip -br aYour interfaces and addresses
ip routeThe routing table, including the default gateway
ss -tulpnListening ports and the program behind each
ss -tan state establishedOpen TCP connections
cat /etc/resolv.confWhich DNS servers this machine uses
hostname -IThis machine's addresses
Is it reachable?
ping -c 4 8.8.8.8Is the network reachable at all? (an IP, no DNS involved)
ping -c 4 example.comDoes name lookup work as well?
traceroute example.com | tracepath example.comThe path the packets take, hop by hop
nc -zv host 443Can I open a TCP connection to that port?
curl -v https://example.comEverything that happens in an HTTPS request
curl -I https://example.comOnly the response headers
curl -w "%{http_code} %{time_total}s\n" -o /dev/null -s URLStatus code and total time
DNS
dig example.comAsk for the A record
dig +short example.com MXJust the answer, for one record type
dig @1.1.1.1 example.comAsk a specific resolver
dig +trace example.comFollow the lookup from the root servers down
dig -x 203.0.113.10Reverse lookup of an address
A / AAAA / CNAME / MX / TXT / NSAddress, IPv6 address, alias, mail server, text (SPF, DKIM), name server
TTLHow long a record may be cached: lower it before a change
HTTP and TLS
200 / 301 / 302 / 304OK / moved permanently / found (temporary) / not modified
400 / 401 / 403 / 404 / 429Bad request / not logged in / not allowed / not found / too many requests
500 / 502 / 503 / 504Server error / bad gateway / unavailable / gateway timeout
curl -X POST -H "Content-Type: application/json" -d '{"a":1}' URLSend JSON
openssl s_client -connect example.com:443 -servername example.comLook at the certificate a server presents
openssl x509 -in cert.pem -noout -dates -subjectValidity dates and subject of a certificate
Addressing
10.0.0.0/8 172.16.0.0/12 192.168.0.0/16The private IPv4 ranges
/24 = 256 addresses /16 = 65,536 /32 = one hostThe number after the slash is the length of the network part
ipcalc 10.0.4.0/22Work out the range, mask and broadcast of a network (if installed)
127.0.0.1 ::1This machine, over IPv4 and IPv6
169.254.0.0/16Link-local: what you get when DHCP failed
Well-known ports
22 SSH | 80 HTTP | 443 HTTPSRemote shell, web, secure web
53 DNS | 67/68 DHCP | 123 NTPNames, addresses and time
25 / 587 SMTP | 143 / 993 IMAPSending and reading mail
3306 MySQL | 5432 PostgreSQL | 6379 RedisCommon databases and caches
3389 RDP | 445 SMBRemote desktop, file shares
Packets and firewalls
sudo tcpdump -i any -nn port 53See DNS traffic as it happens
sudo tcpdump -i eth0 host 203.0.113.10 -w out.pcapRecord traffic to one host for later
sudo iptables -L -n -vList firewall rules with packet counts
sudo ufw allow 443/tcp && sudo ufw enableOpen a port with the simple firewall front end
ssh -L 8080:localhost:80 user@hostForward a local port to the server's port 80 through SSH
Nothing matches that search.
Cheatsheet for the Networking path · Deboistech · All cheatsheets