Adding a Second (Additional) IP Address to a Debian Server
This guide explains how to configure the additional IP address you purchased on a server running Debian 11, 12 or 13. The steps are ordered so that your SSH connection is not dropped; still, before you start we recommend making sure you can reach the server another way (for example by keeping a second SSH session open).
Before you start
Run the commands as root or with sudo. The examples below use these values; replace them with your own:
- Network interface: ens192 (it may be different on your server)
- Primary IP address: 203.0.113.10/24, gateway: 203.0.113.1
- Additional IP address: 203.0.113.20/24
You can see the interface name and your primary address with:
ip -4 addr show
In the output, a line such as inet 203.0.113.10/24 shows your primary address and the name at the end of the line (such as ens192) is the interface. Your additional IP address is shown on your service's page in the client area. For the additional IP you usually use the same prefix length as your primary address (such as /24); if you were given a different value, use that one. Do not add a gateway for the additional IP; the server should have a single default gateway.
Differences between versions
The steps are the same on all three versions; only these details differ, and each is noted in the relevant step:
- Location of the ip command:
/sbin/ipon Debian 11 and 12,/usr/sbin/ipon Debian 13. You can see yours withcommand -v ip. - Gateway in the Netplan file: older files (mostly Debian 11 and 12) use a
gateway4:line, newer ones aroutes:block. You do not need to touch the gateway line for an additional IP. - Servers upgraded from Debian 12 to 13: according to Debian's upgrade notes, the network interface name may change on some servers (for example ens1 instead of enp1s0). Make sure the interface name in the configuration file matches the one in the output of
ip -4 addr show.
1. How is your server's network configured?
Depending on the installation, Debian's network may be configured with a different tool. Check with:
ls /etc/netplan/ 2>/dev/null; grep -n "inet static" /etc/network/interfaces
- If there is a
.yamlfile in/etc/netplan/, Netplan is used: go to step 3. - If there is no Netplan file and
/etc/network/interfaceshas a line such asiface ens192 inet static, classic ifupdown is used: go to step 2. - If neither exists, the network may be configured with files in
/etc/systemd/network/: go to step 4.
2. Adding with ifupdown (/etc/network/interfaces)
- First back up the file:
cp /etc/network/interfaces /etc/network/interfaces.backup - Find the full path of the
ipcommand:command -v ip(usually/sbin/ipon Debian 11 and 12,/usr/sbin/ipon Debian 13). Use this path in the lines below. - Open the file (
nano /etc/network/interfaces) and add theupanddownlines at the end of your main interface's section. The whole section looks like this (the example is for Debian 11 and 12; on Debian 13 write/usr/sbin/ipinstead of/sbin/ip). You only need to add the last two lines; do not change the existing ones, and if your file hasaddressandnetmaskon separate lines, leave them as they are:
These lines make sure the additional IP address is configured every time the server starts. For a third address, repeat the same lines with the labelauto ens192 iface ens192 inet static address 203.0.113.10/24 gateway 203.0.113.1 up /sbin/ip addr add 203.0.113.20/24 dev $IFACE label $IFACE:0 down /sbin/ip addr del 203.0.113.20/24 dev $IFACE label $IFACE:0$IFACE:1. - You do not need to restart the networking service (restarting it may drop your SSH connection). To activate the address right away, run the same command once by hand:
ip addr add 203.0.113.20/24 dev ens192 label ens192:0
3. Adding with Netplan
- Back up the file in
/etc/netplan/(example:cp /etc/netplan/50-cloud-init.yaml /root/netplan.backup; the file name may be different on your server). - Open the file and add the additional IP address as a new line in your interface's
addresseslist. Indentation uses spaces, not tabs; do not change the existing lines. In your file the gateway may be written with aroutes:block as below or, in the older form, with agateway4: 203.0.113.1line; leave whichever you have as it is:network: version: 2 ethernets: ens192: addresses: - 203.0.113.10/24 - 203.0.113.20/24 routes: - to: default via: 203.0.113.1 - Try the configuration safely:
The command applies the new configuration and waits for your confirmation. If your connection still works, press Enter to confirm. If something goes wrong and you cannot confirm, it returns to the previous configuration automatically after 120 seconds, so you do not lose access to the server. Once confirmed, the configuration is permanent.netplan try
4. Adding with systemd-networkd files
Add a second Address= line to the [Network] section of your interface's .network file in /etc/systemd/network/:
[Network]
Address=203.0.113.10/24
Address=203.0.113.20/24
Gateway=203.0.113.1
This line makes sure the additional address is configured every time the server starts. To activate the address right away without restarting the network service, run the immediate command from step 2 once:
ip addr add 203.0.113.20/24 dev ens192
5. Checking
- On the server, both addresses should appear in the output of
ip -4 addr show dev ens192. - From your own computer, check that you can reach the new address with
ping 203.0.113.20. - To test that it persists, you can restart the server at a convenient time and check that the address is still configured.
The address the server uses for outgoing connections does not change; it stays your primary IP address. The additional address is used for incoming connections and for the services you bind to it (for example a second website or SSL certificate).
If you use a control panel
If Plesk is installed on your server, after adding the address to the operating system go to Tools & Settings > IP Addresses in Plesk and click Reread IP; the new address appears in the list and can be assigned to websites.
Troubleshooting
- "Address already assigned" or "RTNETLINK answers: File exists" error: the address is already configured; you do not need to do anything.
- The new address cannot be reached: check that you entered the address and prefix length correctly. If you use a firewall on the server (iptables, nftables, ufw), make sure incoming connections to the new address are allowed.
- The additional address is missing after a restart: check that the interface name in the configuration file matches the one on the server (
ip -4 addr show) and that theippath in theupline is correct (command -v ip). If you upgraded from Debian 12 to 13, the interface name may have changed. - Access to the server was lost: if you used Netplan, wait 120 seconds and the change is reverted. Otherwise you can open a support ticket from the client area.