How to register a large number of IP addresses with Debian/Ubuntu | INTROSERV
EUR
european

EUR

usa

USD

English En
Ex. VAT Ex. VAT 0%

How to register a large number of IP addresses with Debian/Ubuntu

A single server often needs more than one IP address. This guide explains two ways to assign multiple IPv4 addresses to a single network interface on Debian and Ubuntu:

  • automatically, with a shell script and a systemd service, recommended for large ranges;
  • directly in netplan, recommended when the addresses must survive a network reconfiguration as well as a reboot.

Both methods make the configuration persistent across reboots. Read the note at the end of each method to choose the one that fits your case.

When you need multiple IP addresses

Several common workloads on a single server call for more than one public address:

  • Mail servers that use separate addresses and PTR records to isolate the sending reputation of different domains.
  • Web servers that require dedicated addresses for legacy applications, customer isolation, or specific firewall policies.
  • Proxy and VPN infrastructure, where each proxy instance or VPN endpoint is bound to its own public address.
  • Containers or virtual machines that use routed IP addresses.

INTROSERV VPS plans include two IPv4 addresses and a /112 IPv6 subnet by default. Additional IPv4 addresses are available in many locations. Check the order configurator for availability in your chosen region.

Before you start

You need root access and the name of the interface that will carry the extra addresses. Modern Debian and Ubuntu releases no longer use the old eth0 name, so do not assume it. List the interfaces together with their current addresses and identify the one that already holds your primary address:

ip -br addr show

The output shows entries such as ens3, enp1s0 or eth0 next to the addresses already configured on them. The interface that already carries your main IP is the one to use in the steps below. The examples here use ens3.

Warning: These steps change network configuration on a server you most likely reach over SSH. A mistake can cut your own access. Keep a second way in if you have one, such as the provider console or IP-KVM, and prefer the safe-apply options shown below.

Creating the address script

A short script adds a range of addresses in one pass. Create it under /usr/local/sbin:

nano /usr/local/sbin/extra-ips.sh

Paste the following script. Replace the interface name, the prefix and the range with the block assigned to you. The addresses below use the documentation range from RFC 5737 and are placeholders:

#!/bin/bash set -euo pipefail # Interface that will carry the additional addresses. IFACE="ens3" # Common prefix and the first and last value of the host octet. # Replace these with the block assigned to you. PREFIX="203.0.113" FIRST=10 LAST=60 # Stop early with a clear message if the interface name is wrong. if ! ip link show "$IFACE" >/dev/null 2>&1; then echo "Interface $IFACE not found. Check the name with: ip -br addr show" >&2 exit 1 fi for HOST in $(seq "$FIRST" "$LAST"); do ip addr replace "${PREFIX}.${HOST}/32" dev "$IFACE" done

Info: The addresses use a /32 prefix on purpose. The primary interface already owns the route for its subnet, so each secondary address needs only a local host route. A /32 prefix prevents the kernel from adding a duplicate subnet route and keeps the routing table clean. The script uses ip addr replace rather than ip addr add so it can be rerun safely without failing on addresses that already exist.

Make the script executable. Note the full path, which was the part missing in the previous version of this guide:

chmod +x /usr/local/sbin/extra-ips.sh

Making the addresses persist with a systemd service

Running the script by hand adds the addresses until the next reboot. To apply them automatically at boot, create a systemd service that runs the script during boot. This method works the same way whether the system uses netplan, systemd-networkd or the older ifupdown stack.

Create the unit file:

nano /etc/systemd/system/extra-ips.service

Add the following:

[Unit] Description=Assign additional IP addresses After=network-online.target Wants=network-online.target [Service] Type=oneshot ExecStart=/usr/local/sbin/extra-ips.sh RemainAfterExit=yes [Install] WantedBy=multi-user.target

Reload systemd and enable the service so it runs now and on every boot:

systemctl daemon-reload systemctl enable --now extra-ips.service

Confirm that the service started correctly:

systemctl status --no-pager extra-ips.service

Warning: Addresses added by this script are not part of the netplan or systemd-networkd configuration. A later netplan apply, a networkctl reconfigure, or any network restart can remove them. They come back on the next reboot, or immediately if you run systemctl restart extra-ips.service. If the addresses must stay in place through a network reconfiguration as well, use the netplan method below instead.

Alternative: defining the addresses in netplan

On Ubuntu, where netplan is the default, the addresses can be declared in netplan itself. The network stack then treats them as managed addresses, so they survive a reconfiguration. This suits a small, fixed list. For a large range the systemd service above scales better, because netplan needs one line per address.

When multiple netplan files define the same interface, their settings may override or merge in unexpected ways, which can drop your primary address and cut off access. Editing the existing configuration file is usually safer than creating another file for the same interface. Open the file that already configures your interface, commonly /etc/netplan/50-cloud-init.yaml or /etc/netplan/00-installer-config.yaml:

ls /etc/netplan/ nano /etc/netplan/50-cloud-init.yaml

Keep every existing setting for the interface, such as dhcp4, the primary address, the gateway and the nameservers. Add the extra addresses under an addresses list on the same interface. The example below keeps DHCP for the primary address and adds three secondary addresses:

network: version: 2 ethernets: ens3: dhcp4: true addresses: - 203.0.113.10/32 - 203.0.113.11/32 - 203.0.113.12/32

Recent netplan versions warn if the file is readable by other users. Restrict the permissions to clear that warning:

chmod 600 /etc/netplan/50-cloud-init.yaml

Test the change with netplan try. It applies the configuration and rolls it back automatically after 120 seconds unless you confirm, which protects you from losing remote access:

netplan try

If the connection stays up and everything looks correct, confirm when prompted, then apply the configuration permanently:

netplan apply

Verifying the result

List the addresses currently bound to the interface and confirm the new ones are present:

ip -br addr show ens3

The additional addresses should now appear in the output and will be restored automatically after every reboot.

Removing the addresses

To remove a single address, delete it from the interface:

ip addr del 203.0.113.10/32 dev ens3

If you used the script and service, stop assigning the whole range at boot by disabling and removing the service:

systemctl disable --now extra-ips.service rm /etc/systemd/system/extra-ips.service systemctl daemon-reload

If you used netplan, remove the extra lines from the addresses list in the netplan file, then run netplan apply.

Troubleshooting

If the service does not start, check its state and logs:

systemctl status --no-pager extra-ips.service journalctl -u extra-ips.service

Confirm the following:

  • the interface name in the script matches the real name from ip -br addr show;
  • the addresses belong to the block allocated to you;
  • the script is executable.

If you used a /24 prefix by mistake instead of /32, the routing table shows the symptom as several duplicate subnet routes. Check it with:

ip route

This guide focuses on IPv4. As with IPv4, secondary IPv6 addresses are normally added as host addresses with a /128 prefix, using the same ip addr replace command, for example ip addr replace 2001:db8::10/128 dev ens3.

VAT

  • Other

    Ex. VAT

    0%
  • austria

    Austria

    20%
  • Belgium

    Belgium

    21%
  • Bulgaria

    Bulgaria

    20%
  • Croatia

    Croatia

    25%
  • Cyprus

    Cyprus

    19%
  • Czech Republic

    Czech Republic

    21%
  • Denmark

    Denmark

    25%
  • Estonia

    Estonia

    22%
  • France

    France

    20%
  • Finland

    Finland

    24%
  • Germany

    Germany

    19%
  • Greece

    Greece

    24%
  • Hungary

    Hungary

    27%
  • Ireland

    Ireland

    23%
  • Italy

    Italy

    22%
  • Latvia

    Latvia

    21%
  • Lithuania

    Lithuania

    21%
  • Luxembourg

    Luxembourg

    17%
  • Malta

    Malta

    18%
  • Netherlands

    Netherlands

    21%
  • Poland

    Poland

    23%
  • Portugal

    Portugal

    23%
  • Romania

    Romania

    19%
  • Slovakia

    Slovakia

    20%
  • Slovenia

    Slovenia

    22%
  • Spain

    Spain

    21%
  • Sweden

    Sweden

    25%
  • USA

    USA

    0%
european
states
  • germany
  • Español
  • Italiano
  • Poland
  • Русский
  • Slovenski
  • Türkçe
  • ukraine
  • kingdom
  • French
  • Hrvatska
  • Other
  • Austria
  • Belgium
  • Bulgaria
  • Croatia
  • Cyprus
  • Czech Republic
  • Denmark
  • Estonia
  • Finland
  • France
  • Germany
  • Greece
  • Hungary
  • Ireland
  • Italy
  • Latvia
  • Lithuania
  • Luxembourg
  • Malta
  • Netherlands
  • Poland
  • Portugal
  • Romania
  • Slovakia
  • Slovenia
  • Spain
  • Sweden
  • USA