# How to Change the IP Address of a Linux Server

Source: https://lyrahosting.com/how-to/how-to-change-ip-address-of-your-server/

1. [Offshore Hosting](https://lyrahosting.com/)
2. [How-to](https://lyrahosting.com/how-to/)
3. How to Change the IP Address of a Linux Server

How-to

Written by [the LyraHosting technical team](https://lyrahosting.com/about-us/#team) · Reviewed by Erik, certified Linux system administrator (LFCS) · Published 9 Jun 2022 · Updated 4 Nov 2026 · 5 min read

This guide changes the IP address of a Linux server, on a [VPS](https://lyrahosting.com/offshore-linux-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](https://www.rfc-editor.org/rfc/rfc5737.html). 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](https://lyrahosting.com/offshore-dedicated-servers/) 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](https://netplan.readthedocs.io/en/stable/netplan-yaml/); 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.

In this article

1. [Prerequisites](https://lyrahosting.com/how-to/how-to-change-ip-address-of-your-server/#prerequisites)
2. [Find your current IP address and interface](https://lyrahosting.com/how-to/how-to-change-ip-address-of-your-server/#find-your-current-ip-address-and-interface)
3. [Add the new IP address for a test](https://lyrahosting.com/how-to/how-to-change-ip-address-of-your-server/#add-the-new-ip-address-for-a-test)
4. [How to change the IP address on Ubuntu (netplan)](https://lyrahosting.com/how-to/how-to-change-ip-address-of-your-server/#how-to-change-the-ip-address-on-ubuntu-netplan)
5. [How to change the IP address on Debian (ifupdown)](https://lyrahosting.com/how-to/how-to-change-ip-address-of-your-server/#how-to-change-the-ip-address-on-debian-ifupdown)
6. [How to change the IP address on RHEL, AlmaLinux and Rocky Linux (NetworkManager)](https://lyrahosting.com/how-to/how-to-change-ip-address-of-your-server/#how-to-change-the-ip-address-on-rhel-almalinux-and-rocky-lin)
7. [Check the change](https://lyrahosting.com/how-to/how-to-change-ip-address-of-your-server/#check-the-change)

Keep exploring [All how-to guides](https://lyrahosting.com/how-to/) [Talk to our team](https://lyrahosting.com/contact-us/)

## Host it offshore with LyraHosting

KVM virtual servers in the Netherlands with full root access, from €8.99 a month.

[Explore offshore VPS](https://lyrahosting.com/offshore-linux-vps/) [Contact us](https://lyrahosting.com/contact-us/)

Keep reading

## More from the how-to

[View all](https://lyrahosting.com/how-to/)

01 / From the journal

How-to · 8 Jun 2022

### [How to Set Up an OpenVPN Server on Ubuntu LTS](https://lyrahosting.com/how-to/how-to-setup-an-openvpn-server-on-ubuntu-18-0420-0422-04-lts/)

Set up an OpenVPN server on Ubuntu 24.04 or 22.04 LTS with the openvpn-install script: the firewall, client files, and adding or revoking clients.

9 min read [Read article](https://lyrahosting.com/how-to/how-to-setup-an-openvpn-server-on-ubuntu-18-0420-0422-04-lts/)

02 / From the journal

How-to · 25 May 2022

### [How to Upgrade Ubuntu 20.04 LTS to 22.04 LTS](https://lyrahosting.com/how-to/how-to-upgrade-from-ubuntu-20-04-lts-to-22-04-lts/)

Ubuntu 20.04 is out of standard support. Upgrade a server to 22.04 LTS over SSH with do-release-upgrade, then on to 24.04 and 26.04.

7 min read [Read article](https://lyrahosting.com/how-to/how-to-upgrade-from-ubuntu-20-04-lts-to-22-04-lts/)

03 / From the journal

How-to · 7 Nov 2026

### [How to Update Your Linux Server](https://lyrahosting.com/how-to/how-to-update-your-linux-server/)

Update Ubuntu, Debian, RHEL, AlmaLinux or Rocky Linux with apt or dnf, check whether a reboot is needed and turn on automatic security updates.

5 min read [Read article](https://lyrahosting.com/how-to/how-to-update-your-linux-server/)
