Most servers receive their network settings automatically or from the installer, and you never need to touch them. But sooner or later you will: to add an address, change DNS resolvers, fix a gateway after a reinstall, or understand why the network did not come back after a reboot. Each distribution family uses a different tool, and a typo on a remote server can cut you off completely.
This guide covers the three common systems, how to apply changes safely, and how to recover if something goes wrong.
Before you change anything
- Write down the current settings:
ip -br a # interfaces and addresses
ip r # routes, including "default via" (the gateway)
resolvectl status 2>/dev/null || cat /etc/resolv.conf # DNS
- Know your interface name. Modern systems use names such as
eth0,ens3,enp1s0oreno1. Use the name shown byip -br a, not one from a tutorial. - Have console access. The VNC console in your control panel works even when the network is down. Open it in a browser tab before you start.
- Use the values your provider assigned. On a dedicated server the IP, prefix (netmask) and gateway are in your welcome email or client area. Using a wrong gateway or a neighbour’s address causes outages for you and possibly for others.
Netmask and prefix
| Netmask | Prefix | Usable addresses |
|---|---|---|
| 255.255.255.0 | /24 | 254 |
| 255.255.255.192 | /26 | 62 |
| 255.255.255.248 | /29 | 6 |
| 255.255.255.252 | /30 | 2 |
Ubuntu: Netplan
Ubuntu 18.04 and later use Netplan: YAML files in /etc/netplan/ that generate the real configuration for systemd-networkd or NetworkManager.
ls /etc/netplan/
sudo cp /etc/netplan/50-cloud-init.yaml /root/netplan-backup.yaml
A static configuration:
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: false
addresses:
- 203.0.113.10/24
routes:
- to: default
via: 203.0.113.1
nameservers:
addresses: [1.1.1.1, 8.8.8.8]
YAML is indentation-sensitive: use spaces, never tabs, and keep each level aligned. Older guides use gateway4:; it still works on many releases but is deprecated — use routes: as above.
Set strict permissions (Netplan warns otherwise):
sudo chmod 600 /etc/netplan/*.yaml
Apply safely with automatic rollback
sudo netplan try
netplan try applies the configuration and waits 120 seconds for you to press Enter. If you lose connection and cannot confirm, it rolls back automatically. Once you have confirmed, the change is permanent. Use sudo netplan apply only when you are sure.
Stop cloud-init overwriting your changes
On cloud images, cloud-init may regenerate the Netplan file at boot. If your edits disappear after a reboot, disable its network handling:
echo 'network: {config: disabled}' | sudo tee /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
AlmaLinux, Rocky Linux, CentOS Stream: NetworkManager
RHEL-family systems use NetworkManager, managed with nmcli:
nmcli con show # list connections (note the NAME)
nmcli dev status
Set a static address on the connection (here called ens3):
sudo nmcli con mod ens3 ipv4.method manual \
ipv4.addresses 203.0.113.10/24 \
ipv4.gateway 203.0.113.1 \
ipv4.dns "1.1.1.1 8.8.8.8"
sudo nmcli con up ens3
con up applies the change immediately. If you are connected over SSH, run it inside tmux so the command completes even if your session drops for a moment.
The configuration is stored in /etc/NetworkManager/system-connections/ (keyfile format on version 9). nmtui gives a text-menu interface if you prefer.
Debian: ifupdown
Debian servers commonly use /etc/network/interfaces:
auto ens3
iface ens3 inet static
address 203.0.113.10/24
gateway 203.0.113.1
dns-nameservers 1.1.1.1 8.8.8.8
dns-nameservers requires the resolvconf package; otherwise put resolvers in /etc/resolv.conf. Apply with:
sudo ifdown ens3 && sudo ifup ens3 # run in one line, inside tmux
# or
sudo systemctl restart networking
DNS resolvers
On Ubuntu, /etc/resolv.conf usually points to 127.0.0.53, the local systemd-resolved stub, which forwards to the servers configured in Netplan. Check what is really used:
resolvectl status
resolvectl query example.com
Common public resolvers:
| Provider | IPv4 |
|---|---|
| Cloudflare | 1.1.1.1, 1.0.0.1 |
| 8.8.8.8, 8.8.4.4 | |
| Quad9 | 9.9.9.9 |
Your provider’s own resolvers, if offered, are often the fastest from inside the data centre. Do not edit /etc/resolv.conf directly on systems where it is a symlink — your change will be overwritten.
Hostname
sudo hostnamectl set-hostname web1.example.com
Add the name to /etc/hosts so local lookups work:
127.0.1.1 web1.example.com web1
For a mail server, the hostname should match the reverse DNS of the IP.
Verify
ip -br a
ip r | grep default
ping -c 3 203.0.113.1 # gateway
ping -c 3 1.1.1.1 # internet by IP
ping -c 3 example.com # DNS
If the gateway answers but 1.1.1.1 does not, check the default route. If IP works but names do not, it is DNS.
If you lose access
- Open the VNC console from the control panel and log in.
- Restore your backup (
/root/netplan-backup.yaml, or revert withnmcli). - Apply again and check
ip aandip r. - If the original settings are lost, take the IP, prefix and gateway from your welcome email or client area, or ask support.
Multiple IPs
Additional addresses go into the same configuration as extra lines under addresses: (Netplan), +ipv4.addresses (nmcli) or extra address lines (ifupdown). Full instructions, including testing each address, are in adding IP addresses on Linux and, for Windows, adding IPs on Windows Server.