cluster deboistech.in Get started
Cheatsheet

Networking

The tools, numbers and records you need to find out why two machines cannot talk.

Practice this path

Look at the host

  • ip addr  |  ip -br a

    Your interfaces and addresses

  • ip route

    The routing table, including the default gateway

  • ss -tulpn

    Listening ports and the program behind each

  • ss -tan state established

    Open TCP connections

  • cat /etc/resolv.conf

    Which DNS servers this machine uses

  • hostname -I

    This machine's addresses

Is it reachable?

  • ping -c 4 8.8.8.8

    Is the network reachable at all? (an IP, no DNS involved)

  • ping -c 4 example.com

    Does name lookup work as well?

  • traceroute example.com  |  tracepath example.com

    The path the packets take, hop by hop

  • nc -zv host 443

    Can I open a TCP connection to that port?

  • curl -v https://example.com

    Everything that happens in an HTTPS request

  • curl -I https://example.com

    Only the response headers

  • curl -w "%{http_code} %{time_total}s\n" -o /dev/null -s URL

    Status code and total time

DNS

  • dig example.com

    Ask for the A record

  • dig +short example.com MX

    Just the answer, for one record type

  • dig @1.1.1.1 example.com

    Ask a specific resolver

  • dig +trace example.com

    Follow the lookup from the root servers down

  • dig -x 203.0.113.10

    Reverse lookup of an address

  • A / AAAA / CNAME / MX / TXT / NS

    Address, IPv6 address, alias, mail server, text (SPF, DKIM), name server

  • TTL

    How long a record may be cached: lower it before a change

HTTP and TLS

  • 200 / 301 / 302 / 304

    OK / moved permanently / found (temporary) / not modified

  • 400 / 401 / 403 / 404 / 429

    Bad request / not logged in / not allowed / not found / too many requests

  • 500 / 502 / 503 / 504

    Server error / bad gateway / unavailable / gateway timeout

  • curl -X POST -H "Content-Type: application/json" -d '{"a":1}' URL

    Send JSON

  • openssl s_client -connect example.com:443 -servername example.com

    Look at the certificate a server presents

  • openssl x509 -in cert.pem -noout -dates -subject

    Validity dates and subject of a certificate

Addressing

  • 10.0.0.0/8  172.16.0.0/12  192.168.0.0/16

    The private IPv4 ranges

  • /24 = 256 addresses  /16 = 65,536  /32 = one host

    The number after the slash is the length of the network part

  • ipcalc 10.0.4.0/22

    Work out the range, mask and broadcast of a network (if installed)

  • 127.0.0.1  ::1

    This machine, over IPv4 and IPv6

  • 169.254.0.0/16

    Link-local: what you get when DHCP failed

Well-known ports

  • 22  SSH  |  80  HTTP  |  443  HTTPS

    Remote shell, web, secure web

  • 53  DNS  |  67/68  DHCP  |  123  NTP

    Names, addresses and time

  • 25 / 587  SMTP  |  143 / 993  IMAP

    Sending and reading mail

  • 3306  MySQL  |  5432  PostgreSQL  |  6379  Redis

    Common databases and caches

  • 3389  RDP  |  445  SMB

    Remote desktop, file shares

Packets and firewalls

  • sudo tcpdump -i any -nn port 53

    See DNS traffic as it happens

  • sudo tcpdump -i eth0 host 203.0.113.10 -w out.pcap

    Record traffic to one host for later

  • sudo iptables -L -n -v

    List firewall rules with packet counts

  • sudo ufw allow 443/tcp && sudo ufw enable

    Open a port with the simple firewall front end

  • ssh -L 8080:localhost:80 user@host

    Forward a local port to the server's port 80 through SSH

Cheatsheet for the Networking path · Deboistech · All cheatsheets