KnowledgebaseLinux VPS › Network config on a VPS — what your distro uses and where to edit

Network config on a VPS — what your distro uses and where to edit

Every Linux distro has settled on one of three network configuration systems, and which one you're dealing with determines where you edit IP addresses, set static routes, and add an alias IP. This article maps it out so you don't spend 20 minutes editing the wrong config file.

What each distro uses by default

Distro Config system Config files
Debian 12+ ifupdown /etc/network/interfaces + /etc/network/interfaces.d/*
Ubuntu Server 18.04+ Netplan → systemd-networkd /etc/netplan/*.yaml
AlmaLinux 9+ NetworkManager /etc/NetworkManager/system-connections/* or via nmcli

LYLIX VPS images provision the IP via cloud-init at first boot; whichever system your distro uses, cloud-init writes the appropriate config and brings the interface up. You usually don't need to touch it unless you're adding a static route, an alias IP, or migrating networking around.

Debian (ifupdown)

Cloud-init writes /etc/network/interfaces.d/50-cloud-init.cfg:

auto eth0
iface eth0 inet static
    address 192.0.2.100/24
    gateway 192.0.2.1
    dns-nameservers 8.8.8.8 1.1.1.1

iface eth0 inet6 static
    address 2001:db8::100/64
    gateway 2001:db8::1

Apply changes:

ifdown eth0 && ifup eth0
# Or for a full restart
systemctl restart networking

Don't edit the cloud-init-managed file directly — cloud-init can overwrite on reboot. Add a new file at /etc/network/interfaces.d/60-custom.cfg for your own additions, or disable cloud-init's networking module (/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with network: {config: disabled}) and take full ownership.

Ubuntu (Netplan)

Cloud-init writes /etc/netplan/50-cloud-init.yaml:

network:
    version: 2
    ethernets:
        eth0:
            addresses:
                - 192.0.2.100/24
            gateway4: 192.0.2.1
            nameservers:
                addresses: [8.8.8.8, 1.1.1.1]

Apply with:

netplan try                          # apply with 120s safety rollback if you lose access
netplan apply                        # apply for real

Like Debian, don't edit the cloud-init file directly. Drop a new file at /etc/netplan/60-custom.yaml with your additions; netplan merges multiple YAML files.

AlmaLinux (NetworkManager)

NetworkManager stores connections under /etc/NetworkManager/system-connections/. The format is keyfile (INI-style). Easier to manage via nmcli than editing files:

nmcli connection show                            # list all connections
nmcli connection show eth0                       # details
nmcli connection modify eth0 ipv4.dns "8.8.8.8 1.1.1.1"
nmcli connection up eth0                         # restart the connection

To add an alias IP:

nmcli connection modify eth0 +ipv4.addresses 192.0.2.101/24
nmcli connection up eth0

To add a static route:

nmcli connection modify eth0 +ipv4.routes "10.0.0.0/8 192.0.2.1"
nmcli connection up eth0

Common operations

Adding a second IP (alias) on the same interface

Debian: add a stanza to /etc/network/interfaces.d/60-custom.cfg:

auto eth0:1
iface eth0:1 inet static
    address 192.0.2.101/24

Ubuntu: in a custom netplan YAML, add the address to the existing addresses: list.

AlmaLinux: nmcli connection modify eth0 +ipv4.addresses 192.0.2.101/24.

Setting a static route

Debian:

iface eth0 inet static
    address 192.0.2.100/24
    gateway 192.0.2.1
    up   ip route add 10.0.0.0/8 via 192.0.2.1
    down ip route del 10.0.0.0/8 via 192.0.2.1

Ubuntu (netplan):

routes:
    - to: 10.0.0.0/8
      via: 192.0.2.1

AlmaLinux: nmcli connection modify eth0 +ipv4.routes "10.0.0.0/8 192.0.2.1"

Diagnostics regardless of backend

ip a                                  # show IP addresses on all interfaces
ip r                                  # show routing table
resolvectl status                     # DNS config (systemd-resolved-based distros)
ss -tlnp                              # listening sockets, with process

These work the same on every modern distro, regardless of which config system is managing the underlying files.

Also Read

« « Back

Powered by WHMCompleteSolution