Linux Networking Cheatsheet

Addresses, routes, sockets and DNS from the Linux command line. Pairs with Networking on Linux — read that for the why. The old column is net-tools (ifconfig, route, netstat, arp), deprecated but still all over the internet and still installed on older boxes. Anything that changes state wants sudo.

Looking at the current state

Taskiproute2 (now)net-tools (old)
All addressesip aifconfig -a
One interfaceip a show enp3s0ifconfig enp3s0
Link state / cable in?ip link (look for LOWER_UP)mii-tool
Routing tableip routeroute -n
Which route wins for an IP?ip route get 1.1.1.1—
ARP / neighbour tableip neigharp -a
Listening sockets + owning processss -tulpnnetstat -tulpn
Established connectionsss -tan state establishednetstat -tan
Interface counters / errorsip -s link show enp3s0ifconfig

Changing things right now (lost on reboot)

TaskCommand
Add an addressip addr add 192.168.1.50/24 dev enp3s0
Remove an addressip addr del 192.168.1.50/24 dev enp3s0
Interface up / downip link set enp3s0 up / down
Add a default gatewayip route add default via 192.168.1.1
Add a static routeip route add 10.0.0.0/8 via 192.168.1.254
Delete a routeip route del 10.0.0.0/8
Flush an interface’s addressesip addr flush dev enp3s0
Set MTUip link set enp3s0 mtu 9000

Runtime only

Everything in that table lives in memory and disappears at reboot — handy for a temporary rescue address, fatal if you thought you were configuring a server. Persistent config belongs to whichever system owns the box.

Which config system is in charge?

CheckCommand
Is NetworkManager or networkd running?systemctl is-active NetworkManager systemd-networkd
Is netplan present?ls /etc/netplan/ · netplan status
What did netplan actually render?netplan get

netplan (Ubuntu server)

# /etc/netplan/01-netcfg.yaml   (2-space indent, no tabs)
network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: false
      addresses:
        - 192.168.1.50/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [1.1.1.1, 9.9.9.9]
TaskCommand
Apply with a 120-second auto-rollbacknetplan try
Apply immediately (no safety net)netplan apply
Check the YAML parsesnetplan generate
Silence the permissions warningchmod 600 /etc/netplan/*.yaml
Use DHCP insteaddhcp4: true and drop the addresses/routes

NetworkManager (desktops, RHEL / Alma)

TaskCommand
Device and connection statusnmcli device status · nmcli con show
Set a static addressnmcli con mod "Wired connection 1" ipv4.addresses 192.168.1.50/24 ipv4.method manual
Set gateway and DNSnmcli con mod "…" ipv4.gateway 192.168.1.1 ipv4.dns "1.1.1.1 9.9.9.9"
Apply the changenmcli con down "…" && nmcli con up "…"
Text UI, if you would rathernmtui

DNS

TaskCommand
Is resolv.conf generated?ls -l /etc/resolv.conf — a symlink means do not edit it
Which servers, per interfaceresolvectl status
Resolve through the system stackresolvectl query example.com
Ask a DNS server directlydig example.com
Ask a specific serverdig @1.1.1.1 example.com
Short answer onlydig +short example.com
Reverse lookupdig -x 192.168.1.50
Flush the cacheresolvectl flush-caches
Local overrides/etc/hosts (consulted first — see /etc/nsswitch.conf)

Testing and diagnosis

RungTestIf it fails
1. Linkip linkCable, port, or the switch
2. Addressip aDHCP, or config that never applied
3. Gatewayping 192.168.1.1Wrong subnet or wrong gateway
4. Internet by IPping 1.1.1.1Routing, or a firewall upstream
5. Name resolutiondig example.comIt is DNS. It is usually DNS.
6. The servicecurl -v https://host · ss -tulpnThe network is exonerated
Also usefulCommand
Trace the pathtraceroute 1.1.1.1 · mtr 1.1.1.1
Is that port open, from here?nc -vz host 443
Watch actual packetstcpdump -ni enp3s0 port 443
Who is using the network?ss -tanp
Test a DNS-free connectioncurl --resolve host:443:1.2.3.4 https://host

Warning

Applying a network change on a machine you are SSHed into can cut you off instantly. On Ubuntu use netplan try — it rolls back after 120 seconds unless you confirm, so a change that kills your session undoes itself. NetworkManager has no equivalent: have console access, or schedule a reboot as your rollback before you start.