Linux Add Additional IP Address: Bind Extra IPv4 on Ubuntu, Debian, CentOS and Rocky Linux
If you ordered extra addresses for a JUSTG cloud server or a /24 block for a dedicated server in Johannesburg or Moscow, you need to add the additional IP address in Linux before it answers traffic. This guide shows how to bind an extra IPv4 temporarily with ip addr add, how to make it persistent with netplan on Ubuntu, /etc/network/interfaces on Debian and nmcli on CentOS/Rocky/AlmaLinux, how to handle IPs from a different subnet with source routing, and how to bind a full /24 with a simple loop. Example addresses use documentation ranges; replace them with the IPs, prefix and gateway shown for your service in the client area.
Step 1: Check the interface name and current IPs
The brief view of ip lists each interface with its addresses. Note the interface that holds the main IP (often eth0, ens3 or enp1s0) and the default gateway.
ip -br a
ip route show defaultStep 2: Add the IP temporarily with ip addr add (for testing)
The quickest way to test a new address is to add it at runtime. It disappears on reboot, which makes it safe for a first check.
# add the extra IPv4 (not persistent, lost after reboot)
ip addr add 203.0.113.11/24 dev eth0
# confirm and test outgoing traffic from the new address
ip -br a show eth0
ping -c 3 -I 203.0.113.11 1.1.1.1
# remove it again if needed
ip addr del 203.0.113.11/24 dev eth0If the ping from the new source address works, the IP is routed correctly to your server and you can make it permanent.
Step 3: Make the extra IP persistent with netplan on Ubuntu
Ubuntu stores its network configuration in YAML files under /etc/netplan/. Add the new address to the addresses list of the interface. Indentation must use spaces only.
# /etc/netplan/50-cloud-init.yaml (the file name may differ)
network:
version: 2
ethernets:
eth0:
addresses:
- 203.0.113.10/24
- 203.0.113.11/24
routes:
- to: default
via: 203.0.113.1
nameservers:
addresses: [1.1.1.1, 8.8.8.8]netplan try # rolls back automatically if you lose access and do not confirm
netplan applyIf the server was set up by cloud-init and your changes are overwritten after a reboot, disable cloud-init network management:
echo "network: {config: disabled}" > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfgStep 4: Add the IP on Debian with /etc/network/interfaces
Debian with ifupdown allows several iface stanzas for the same interface; each extra stanza adds one address.
# /etc/network/interfaces
auto eth0
iface eth0 inet static
address 203.0.113.10/24
gateway 203.0.113.1
iface eth0 inet static
address 203.0.113.11/24Apply the change from the VNC console, or simply reboot during a maintenance window:
systemctl restart networkingStep 5: Add the IP on CentOS, Rocky Linux or AlmaLinux with nmcli
These systems use NetworkManager. The connection name may be System eth0, eth0 or Wired connection 1, so list it first. The + prefix appends the address instead of replacing the main one.
nmcli con show # find the connection name
nmcli con mod "System eth0" +ipv4.addresses 203.0.113.11/24
nmcli con up "System eth0"
nmcli -g ipv4.addresses con show "System eth0"Afterwards, run ip -br a to check that both addresses are present on the interface.
Step 6: Source routing when the IPs are in different subnets
If the extra IP comes from a different subnet with its own gateway, replies may leave through the main gateway with the wrong source and be dropped. Policy routing sends traffic from the extra IP through its own gateway:
# extra IP 198.51.100.10 with its own gateway 198.51.100.1
ip addr add 198.51.100.10/24 dev eth0
ip route add default via 198.51.100.1 dev eth0 table 100
ip rule add from 198.51.100.10 table 100
ip rule showTo keep it after reboot, use the equivalent persistent settings:
# netplan: add under eth0
routes:
- to: default
via: 203.0.113.1
- to: default
via: 198.51.100.1
table: 100
routing-policy:
- from: 198.51.100.10
table: 100
# nmcli (CentOS / Rocky / AlmaLinux)
nmcli con mod "System eth0" +ipv4.routes "0.0.0.0/0 198.51.100.1 table=100" \
+ipv4.routing-rules "priority 100 from 198.51.100.10 table 100"
nmcli con up "System eth0"Step 7: Bind a full /24 on a JUSTG dedicated server
A /24 contains 256 addresses. Check your assignment for the gateway and the usable range; in the example below, .1 is the gateway and .2 to .254 are usable. A loop adds them all for testing:
# example: 198.51.100.0/24, gateway 198.51.100.1, usable .2 - .254
for i in $(seq 2 254); do
ip addr add 198.51.100.$i/24 dev eth0
done
ip -4 -o addr show dev eth0 | wc -lFor a permanent setup, generate the configuration instead of typing 253 lines by hand:
# Ubuntu (netplan): print the address lines, then paste them under "addresses:"
for i in $(seq 2 254); do echo " - 198.51.100.$i/24"; done
# Debian (/etc/network/interfaces): one line inside the eth0 stanza
up for i in $(seq 2 254); do ip addr add 198.51.100.$i/24 dev eth0; done
# CentOS / Rocky / AlmaLinux (NetworkManager)
ADDRS=$(for i in $(seq 2 254); do printf "198.51.100.%s/24," "$i"; done)
nmcli con mod "System eth0" +ipv4.addresses "${ADDRS%,}"
nmcli con up "System eth0"Count the result with ip -4 -o addr show dev eth0 | wc -l after a reboot to confirm every address came back.
FAQ
How do I get more IPv4 addresses for my VPS?
Each JUSTG cloud server includes one IPv4. Additional IPv4 can be ordered through the upgrade options in the client area, and every cloud server can use free IPv6.
The new IP is listed in ip -br a but not reachable. What should I check?
Check the prefix and gateway against your assignment, make sure the firewall allows the service on that address, and test with ping -I. If it still fails, the IP may not be routed to your server yet.
Which address does the server use for outgoing connections?
The primary (first) address of the subnet. Applications can bind to a specific IP, or you can set the src option on a route.
If you still cannot resolve the issue, please submit a ticket to contact JUSTG technical support with your IP assignment and the output of ip -br a.