IPs & SubnetsLinux

How to configure additional IPs In Debian & Ubuntu

This guide details how to configure additional Failover IPs in a Debian or Ubuntu VPS Server or Dedicated Server. This guide assumes there is no NetPlan installed on the server so is aimed at Ubuntu 18 and Debian 10/11. If you are using Ubuntu 22 or Debian 12. Please see the guide on how to configure additional IPs with NetPlan.

  1. Configure additional IPs and Subnets in CentOS, RockyLinux and AlmaLinux
  2. Configure additional IPs and Subnets in Ubuntu 22 and Debian 12 with NetPlan

To ensure additional IPs or subnets to ping inside your virtual container and be accessible from the outside world, you need to add separate network interfaces for each additional IP.

Configure Additional IPs in Ubuntu 18/Debian 11

cp /etc/network/interfaces /etc/network/interfaces.bak

Next, edit the file with a program like Nano or vi;

nano /etc/network/interfaces

Then, add the secondary interface exactly below. You can just copy the code to the file but remember to replace the IP sections with your additional IP details.

auto eth0:0
iface eth0:0 inet static
    address YOUR_ADDITIONAL_IP
    netmask 255.255.255.255

To make sure any secondary interface(s) is brought up when the eth0 is activated we must add the following line to the eth0 configuration file:

post-up /sbin/ifconfig eth0:0 YOUR_ADDITIONAL_IP netmask 255.255.255.255 broadcast YOUR_ADDITIONAL_IP pre-down /sbin/ifconfig eth0:0 down

Configure Multiple IPs

So, you can configure multiple IPs in your KVM NVMe VPS or Dedicated server by adding them all to the interfaces file. Each of your IPs will have an interface at the top and a postup and postdown script at the bottom. So, if you have 8 IPs you would have 16 sections in the file.

auto eth0
iface eth0 inet static
    address YOUR_VM_IP
    netmask 255.255.255.0
    broadcast xxx.xxx.xxx.255
    gateway xxx.xxx.xxx.254

auto eth0:0
iface eth0:0 inet static
    address YOUR_IP1
    netmask 255.255.255.255

auto eth0:1
iface eth0:1 inet static
    address YOUR_IP2
    netmask 255.255.255.255

    post-up /sbin/ifconfig eth0:0 YOUR_IP1 netmask 255.255.255.255 broadcast YOUR_IP1
    pre-down /sbin/ifconfig eth0:0 down

    post-up /sbin/ifconfig eth0:1 YOUR_IP2 netmask 255.255.255.255 broadcast YOUR_IP2
    pre-down /sbin/ifconfig eth0:1 down

Restart your network interfaces to activate the new Failover IPs 

sudo /etc/init.d/networking restart

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button