Chapter 12: Networking

Linux networking cheat sheet

The chapter on one page: what to remember, the commands to have at your fingertips, and flashcards for quick revision.

The chapter in eight sentences

Cheat sheet

Inspect

CommandDoes
ip -br addr, ip -br linkAddresses, links and MACs
ip routeRoutes and default gateway
ip neighNeighbours
ping -c 2 HOSTReachability
tracepath -n ADDRPath hop by hop
ss -tulpnListening ports and programs
curl -sS -m 5 URLTest a service, show the error

Configure

CommandDoes
nmcli device statusDevices
nmcli connection show [NAME]Profiles / one profile
nmcli con add type dummy ifname I con-name N ipv4.method manual ipv4.addresses A/24New static profile
nmcli con modify N +ipv4.addresses A/24 ipv4.dns D ipv4.gateway GEdit the profile
nmcli con up N / down N / delete NApply / remove settings / delete
nmcli -g PROP con show NOne value

Names

Command / fileDoes
hostnamectl, hostnamectl set-hostname NShow / set the name
/etc/hostsLocal names, searched first
/etc/resolv.confDNS servers and search domain (managed by NetworkManager)
/etc/nsswitch.confhosts: files dns myhostname
getent hosts NWhat programs resolve
dig +short N, dig -x ADDR, host NDNS only

Flashcards

What do address, prefix and gateway mean?
Address: this interface. Prefix: how many bits are the network (/24 = 255.255.255.0). Gateway: the router for other networks.
Show addresses, routes, listeners?
ip -br addr · ip route · ss -tulpn
List devices and connection profiles?
nmcli device status · nmcli connection show
Create a static profile on a dummy interface?
nmcli con add type dummy ifname dummy0 con-name dummy0 ipv4.method manual ipv4.addresses 10.20.30.1/24
Change a profile and apply it?
nmcli con modify NAME +ipv4.addresses A/24 · nmcli con up NAME
Where are NetworkManager profiles stored?
/etc/NetworkManager/system-connections/*.nmconnection
Show or set the host name?
hostnamectl · hostnamectl set-hostname NAME
Order of name sources?
nsswitch.conf: files (/etc/hosts), then dns (resolv.conf), then myhostname.
See what programs resolve a name to, and ask DNS directly?
getent hosts NAME · dig +short NAME
"No route to host" with a working ping?
A firewall rejects the port.
"Connection refused"?
Nothing listens on that port or address: check ss -tlnp on the server.
Troubleshooting order?
Link, address, gateway, target IP, name, port.