Cheat sheets

Cheat sheet

Network troubleshooting commands cheat sheet

The commands for finding a network fault, in the order to run them: the card and its address, the route, the neighbour, the path, the name, the port.

ip addr

Shows each network card with its addresses and prefix, and adds or removes addresses.

ip -br addr
Lists every card on one line each, with its state and addresses.
ip addr show eth0
Shows eth0 in full: flags, MTU, MAC address, addresses with prefix and broadcast.
ip -6 addr show scope global
Shows only the global IPv6 addresses, the ones SLAAC or DHCPv6 gave.
ip addr add 10.0.1.50/24 dev eth0
Gives eth0 a second address, 10.0.1.50 in the 10.0.1.0/24 network.
ip addr del 10.0.1.50/24 dev eth0
Removes that address again.

Every ip addr option, with real output

ip route

Shows the routing table, asks which route a destination takes, and adds or removes routes.

ip route
Prints the routing table: one line per destination network and where it goes.
ip route get 10.0.2.10
Shows which next hop, card and source address a packet to 10.0.2.10 would use.
ip route show default
Shows only the default route, the gateway for everything not listed.
ip route add default via 10.0.1.2
Sends every packet with no better route to the router at 10.0.1.2.
ip route add 10.0.3.0/24 via 10.0.12.2
Sends packets for 10.0.3.0/24 to the next router, 10.0.12.2.

Every ip route option, with real output

ping

Sends ICMP echo requests to an address and times the replies: reachable, how far, how fast, how lossy.

ping -c3 10.0.1.2
Sends three echo requests to 10.0.1.2 and prints each reply and a summary.
ping -c5 -i0.2 -q 10.0.2.10
Sends five quick requests and prints only the loss and timing summary.
ping -c1 -W2 10.0.2.10
Sends one request and waits at most two seconds: a fast yes/no test.
ping -c2 -s 1472 -M do 10.0.2.10
Sends full 1500-byte packets that may not be fragmented, to test the path MTU.
ping -c1 -t1 10.0.2.10
Sends one request with TTL 1, so the first router answers with time exceeded.

Every ping option, with real output

arping

Asks an address on your own network for its MAC address with ARP, below IP and any firewall.

arping -c2 -I eth0 10.0.1.2
Asks twice who has 10.0.1.2 and prints the MAC address that answers.
arping -D -c2 -w3 -I eth0 10.0.1.50; echo exit=$?
Checks whether 10.0.1.50 is free before using it: exit 0 means nobody answered.
arping -f -I eth0 10.0.1.2
Stops at the first reply: the quickest proof that 10.0.1.2 is on this network.
arping -b -c3 -I eth0 10.0.1.2
Keeps broadcasting instead of switching to unicast after the first reply, so a second device claiming the address shows too.
arping -U -c3 -I eth0 10.0.1.10
Announces your own address (gratuitous ARP) so neighbours update their caches, as after a failover moves an address.

Every arping option, with real output

traceroute

Lists every router on the way to an address, one line per hop, by sending probes with growing TTL.

traceroute -n 10.0.3.10
Lists each router's address on the way to 10.0.3.10.
traceroute -q1 -w2 webServer.lab
Traces the path with one probe per hop, waiting two seconds for each.
traceroute -I -n 10.0.3.10
Traces with ICMP echo probes, which some firewalls let through when UDP is blocked.
traceroute -T -p 443 -n 10.0.3.10
Traces with TCP SYN probes to port 443, which pass firewalls that let only web traffic through (needs root).
traceroute -U -p 53 -n 10.0.3.10
Sends every UDP probe to port 53 instead of a changing high port.

Every traceroute option, with real output

dig

Asks a DNS server a question and prints the full answer: status, records, who answered and how long it took.

dig +short webServer.lab
Prints only the address webServer.lab resolves to.
dig webServer.lab
Asks the configured resolver and prints the whole answer, including which server replied.
dig @10.0.1.2 webServer.lab
Asks the server at 10.0.1.2 directly, skipping /etc/resolv.conf.
dig AAAA webServer.lab +short
Asks for the name's IPv6 address.
dig -x 10.0.2.10 +short
Asks which name belongs to the address 10.0.2.10.

Every dig option, with real output

ss

Lists sockets: which ports are listening, which connections are open, and TCP's view of each.

ss -tlnp
Lists the TCP ports this device listens on, with the program behind each.
ss -ulnp
Lists the UDP ports this device listens on.
ss -tan
Lists every TCP connection with its state.
ss -tn state time-wait
Lists the connections that were closed and are waiting out TIME_WAIT.
ss -tin '( dport = :5201 )'
Shows RTT, congestion window and retransmits of connections to port 5201.

Every ss option, with real output

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab