This guide changes the IP address of a Linux server, on a VPS or a dedicated server. It covers Ubuntu (netplan), Debian (ifupdown) and Red Hat-family systems such as RHEL, AlmaLinux and Rocky Linux (NetworkManager). First you add the new address next to the old one to test it, then you make the permanent change for your system.
The addresses in the examples (203.0.113.x) are reserved for documentation. Replace them with your own.
Prerequisites
To give your server a different public IP address, you need an additional IP address. If you don't have one, open a ticket in the support area and ask for one or more IPs: our billing department adds them to your service and sends you an invoice. On a LyraHosting Storage VPS, don't change the address yourself: ask support to change it.
Before you start, have these ready:
- the new IP address with its prefix length, for example
203.0.113.10/24, and the gateway. Ask support if you don't have them; - a way back in if the change cuts your SSH connection. On a LyraHosting Linux VPS, the control panel can reboot the server or boot it into the rescue system. On a LyraHosting dedicated server, IPMI works even when the server's network doesn't.
Run the commands below inside tmux or screen, so they keep running if your SSH session drops. If neither is installed, install tmux first: sudo apt install tmux on Ubuntu and Debian, or sudo dnf install tmux on RHEL, AlmaLinux and Rocky Linux.
Find your current IP address and interface
List the network interfaces and their addresses:
ip -brief address The output shows each interface (for example eth0, ens3 or enp3s0) with its addresses. To see the default gateway:
ip route show default The older ifconfig command still works where the net-tools package is installed, but current distributions use ip.
Add the new IP address for a test
The ip command adds an address straight away, without touching any configuration file. Add the new address next to the old one, so your SSH session stays up:
sudo ip address add 203.0.113.10/24 dev eth0 Then connect over SSH to the new address from another terminal to check that it works. An address added this way is gone after the next reboot.
Don't remove the old address with ip address del while you are connected over SSH. When both addresses are in the same subnet, the kernel removes the new one together with the old one unless the promote_secondaries setting is on, and it is off by default. Your server would drop off the network. To move to the new address, make the permanent change for your system below.
How to change the IP address on Ubuntu (netplan)
Ubuntu Server stores its network settings in YAML files in /etc/netplan/, for example 50-cloud-init.yaml. Make a backup copy first, then open the file with an editor such as nano:
sudo cp /etc/netplan/50-cloud-init.yaml ~/50-cloud-init.yaml.bak
sudo nano /etc/netplan/50-cloud-init.yaml Set the new address under addresses, and the gateway as a default route:
network:
version: 2
ethernets:
eth0:
addresses:
- 203.0.113.10/24
routes:
- to: default
via: 203.0.113.1
nameservers:
addresses: [1.1.1.1, 9.9.9.9] Older guides set the gateway with gateway4. Netplan has deprecated that key; use the routes entry above instead. To keep the old address too, list both addresses under addresses.
Test the new configuration with:
sudo netplan try netplan try applies the change and rolls it back after 120 seconds unless you confirm it. Run it inside tmux or screen. If your SSH session drops, reconnect on the new address, reattach with tmux attach (or screen -r) and press Enter to keep the change, all within the 120 seconds. If you can't reconnect, wait: the old settings come back on their own. The rollback restores only the running settings, though: your edited file stays on disk and would apply at the next reboot. Before you reboot, correct the file or put the backup back with sudo cp ~/50-cloud-init.yaml.bak /etc/netplan/50-cloud-init.yaml.
If the file says it was written by cloud-init, cloud-init may write it again at the next boot. Its header comment explains how to stop that.
How to change the IP address on Debian (ifupdown)
Debian servers that use ifupdown keep their settings in /etc/network/interfaces, or in a file under /etc/network/interfaces.d/. Edit the file where your interface is defined, so it isn't defined twice. Make a backup copy first, then open it:
sudo cp /etc/network/interfaces ~/interfaces.bak
sudo nano /etc/network/interfaces Change the address of your interface. The prefix length goes with the address:
auto eth0
iface eth0 inet static
address 203.0.113.10/24
gateway 203.0.113.1 Save the file, then restart the server to apply the new settings:
sudo reboot Restarting the server is the safe way to apply the change over SSH. Restarting only the interface with ifdown and ifup is risky once the file has changed, because ifdown works from the new file rather than the settings in use, and can leave the server without its route. If the server doesn't come back on the new address, use your way back in to correct the file or restore the backup.
How to change the IP address on RHEL, AlmaLinux and Rocky Linux (NetworkManager)
Current Red Hat-family systems manage the network with NetworkManager, and nmcli changes its settings. Find the name of your connection:
nmcli connection show Set the new static address and gateway on that connection, here called eth0:
sudo nmcli connection modify eth0 ipv4.method manual ipv4.addresses 203.0.113.10/24 ipv4.gateway 203.0.113.1 ipv4.dns 1.1.1.1 Then activate it:
sudo nmcli connection up eth0 The new settings apply at once and your SSH session drops. Reconnect on the new address. If the settings are wrong, the server goes off the network, so keep your way back in ready.
Older guides edit ifcfg- files in /etc/sysconfig/network-scripts/. That was the method on CentOS 7, which reached its end of life in June 2024. On current releases, use nmcli.
Check the change
Run ip -brief address again to see the new address, and ip route show default for the gateway. Then connect to the server over SSH on its new IP address from another computer.



