Sub topic 1
Addresses, Prefix Lengths, and the Default Gateway
Prerequisites
This chapter assumes you can use a Linux shell, edit files with a terminal editor, run commands with sudo, and read basic IPv4 addresses. Have console access to the server ready in case an SSH session drops during changes.
Addresses and prefix lengths
An IPv4 address such as 192.168.1.50/24 has two parts. The address identifies the interface. The number after the slash is the prefix length. It counts the leading bits that name the network. With /24, the first 24 bits (192.168.1) form the network, and the last 8 bits identify hosts. That subnet holds 254 usable host addresses.
A wrong prefix length causes connectivity failures. If you set /16 instead of /24, the server treats a much larger range as local and sends traffic directly to those hosts instead of through the gateway.
The default gateway
The default gateway is the router that receives traffic bound for destinations outside the local subnet. It must sit inside the subnet that the address and prefix define. For 192.168.1.50/24, the gateway is usually 192.168.1.1.
Inspecting what the server is using now
Record the current state before you change anything:
ip -br address show
ip route show default
hostnamectl
resolvectl statusThe first command lists addresses per interface. Note the interface name, such as enp1s0, because later steps use it.
Which tool manages your network configuration
Several tools can own the network configuration. Check which ones are active:
ls /etc/netplan/
systemctl is-active NetworkManager systemd-networkdIf Netplan files exist, Netplan generates the settings for either systemd-networkd or NetworkManager. If NetworkManager runs without Netplan files, use nmcli. Pick one tool per interface so two tools do not overwrite each other.
Static addresses versus DHCP
With DHCP, the server requests its address, gateway, and DNS settings from a DHCP server. The lease can change over time. A server that other systems depend on should use a static address, which stays fixed until you change it.
Exercise
What network does 10.20.30.40/22 belong to?
Show answer
10.20.28.0/22. A /22 mask is 255.255.252.0. The third octet 30 AND 252 gives 28, so the network covers 10.20.28.0 through 10.20.31.255.