Linux VPS

Configure a static IP and add extra IPs on a Linux VPS (Netplan and nmcli)

Set a static IPv4 address, gateway and DNS, and add additional IPs on Ubuntu with Netplan or on AlmaLinux and Rocky with NetworkManager (nmcli).

IntermediateLinux VPS (Ubuntu · Debian · AlmaLinux · Rocky)3 min read

Most VPS images get their address automatically, but when you add extra IPs, move to a new subnet or the template uses DHCP you do not want, you need to set the network configuration yourself. A mistake here cuts you off from SSH, so this guide uses the safe commands that roll back automatically.

Before you start

  • Root or sudo access over SSH (connect with SSH).
  • The exact values from your provider: IP address, prefix (for example /24), gateway and any additional IPs. In Virtualizor they are under the VPS's IP list (manage IP addresses in Virtualizor).
  • Access to the VNC or noVNC console in your VPS panel, in case the network goes down.

Warning: Never guess the gateway or prefix. A wrong value disconnects the VPS. Keep the VNC console open in another tab before you apply changes.

Find the interface name and current settings

ip -br addr
ip route

The interface is usually eth0, ens3 or enp1s0. The default via line shows the current gateway.

Ubuntu: static IP with Netplan

  1. List the existing files and back them up:
ls /etc/netplan/
sudo cp /etc/netplan/50-cloud-init.yaml /root/netplan-backup.yaml
  1. Edit the file (name may differ) so it looks like this, using your own values. Additional IPs are simply more lines under addresses:
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: false
      addresses:
        - 203.0.113.25/24
        - 203.0.113.26/24
      routes:
        - to: default
          via: 203.0.113.1
      nameservers:
        addresses: [1.1.1.1, 8.8.8.8]
  1. If cloud-init manages the file, stop it overwriting your changes:
echo "network: {config: disabled}" | sudo tee /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
  1. Fix permissions and apply with automatic rollback. If you lose access, the old config returns after 120 seconds:
sudo chmod 600 /etc/netplan/*.yaml
sudo netplan try

Press Enter to keep the configuration once you confirm SSH still works.

Note: Some providers give the gateway outside your subnet (for example a /32 address). Then add on-link: true under the default route.

AlmaLinux and Rocky: static IP with nmcli

  1. Find the connection name:
nmcli connection show
  1. Set the static address, gateway and DNS (replace eth0 with the connection name):
sudo nmcli con mod eth0 ipv4.method manual ipv4.addresses 203.0.113.25/24 ipv4.gateway 203.0.113.1 ipv4.dns "1.1.1.1 8.8.8.8"
  1. Add an extra IP with +ipv4.addresses:
sudo nmcli con mod eth0 +ipv4.addresses 203.0.113.26/24
  1. Apply. Run it in one line so the connection comes back even though SSH drops briefly:
sudo nmcli con down eth0 && sudo nmcli con up eth0

Check that it worked

ip -br addr
ip route
ping -c 3 1.1.1.1
dig +short mdmhost.com

From your own computer, ping each new IP. Then point services at it, for example a web server listen directive or a DNS A record.

Troubleshooting

  • Extra IP does not answer from outside: the provider may need to route it to your VPS first, or the MAC must match. Check it is assigned in the panel.
  • Locked out: log in through VNC, restore the backup file and run netplan apply.
  • Outgoing mail uses the wrong IP: the first address is used for outgoing traffic by default; set the right one and its PTR (reverse DNS for email).

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.