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
Task
iproute2 (now)
net-tools (old)
All addresses
ip a
ifconfig -a
One interface
ip a show enp3s0
ifconfig enp3s0
Link state / cable in?
ip link (look for LOWER_UP)
mii-tool
Routing table
ip route
route -n
Which route wins for an IP?
ip route get 1.1.1.1
—
ARP / neighbour table
ip neigh
arp -a
Listening sockets + owning process
ss -tulpn
netstat -tulpn
Established connections
ss -tan state established
netstat -tan
Interface counters / errors
ip -s link show enp3s0
ifconfig
Changing things right now (lost on reboot)
Task
Command
Add an address
ip addr add 192.168.1.50/24 dev enp3s0
Remove an address
ip addr del 192.168.1.50/24 dev enp3s0
Interface up / down
ip link set enp3s0 up / down
Add a default gateway
ip route add default via 192.168.1.1
Add a static route
ip route add 10.0.0.0/8 via 192.168.1.254
Delete a route
ip route del 10.0.0.0/8
Flush an interface’s addresses
ip addr flush dev enp3s0
Set MTU
ip 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.
nmcli con mod "Wired connection 1" ipv4.addresses 192.168.1.50/24 ipv4.method manual
Set gateway and DNS
nmcli con mod "…" ipv4.gateway 192.168.1.1 ipv4.dns "1.1.1.1 9.9.9.9"
Apply the change
nmcli con down "…" && nmcli con up "…"
Text UI, if you would rather
nmtui
DNS
Task
Command
Is resolv.conf generated?
ls -l /etc/resolv.conf — a symlink means do not edit it
Which servers, per interface
resolvectl status
Resolve through the system stack
resolvectl query example.com
Ask a DNS server directly
dig example.com
Ask a specific server
dig @1.1.1.1 example.com
Short answer only
dig +short example.com
Reverse lookup
dig -x 192.168.1.50
Flush the cache
resolvectl flush-caches
Local overrides
/etc/hosts (consulted first — see /etc/nsswitch.conf)
Testing and diagnosis
Rung
Test
If it fails
1. Link
ip link
Cable, port, or the switch
2. Address
ip a
DHCP, or config that never applied
3. Gateway
ping 192.168.1.1
Wrong subnet or wrong gateway
4. Internet by IP
ping 1.1.1.1
Routing, or a firewall upstream
5. Name resolution
dig example.com
It is DNS. It is usually DNS.
6. The service
curl -v https://host · ss -tulpn
The network is exonerated
Also useful
Command
Trace the path
traceroute 1.1.1.1 · mtr 1.1.1.1
Is that port open, from here?
nc -vz host 443
Watch actual packets
tcpdump -ni enp3s0 port 443
Who is using the network?
ss -tanp
Test a DNS-free connection
curl --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.