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 routeThe interface is usually eth0, ens3 or enp1s0. The default via line shows the current gateway.
Ubuntu: static IP with Netplan
- List the existing files and back them up:
ls /etc/netplan/
sudo cp /etc/netplan/50-cloud-init.yaml /root/netplan-backup.yaml- 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]- 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- 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 tryPress 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
- Find the connection name:
nmcli connection show- Set the static address, gateway and DNS (replace
eth0with 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"- Add an extra IP with
+ipv4.addresses:
sudo nmcli con mod eth0 +ipv4.addresses 203.0.113.26/24- 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 eth0Check that it worked
ip -br addr
ip route
ping -c 3 1.1.1.1
dig +short mdmhost.comFrom 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).
