Learn how to configure multiple IP addresses on a single network interface using systemd-networkd and NetworkManager. Set up persistent network aliases for hosting multiple services, load balancing, and network segmentation.
Prerequisites
- Root or sudo access
- Basic Linux command line knowledge
- Active network interface
What this solves
Network interface aliases allow you to assign multiple IP addresses to a single physical network interface, enabling you to host multiple services, implement load balancing, or create network segmentation without additional hardware. This tutorial covers configuring secondary IP addresses using both systemd-networkd and NetworkManager on modern Linux distributions.
Step-by-step configuration
Identify your network interface
First, identify the network interface you want to configure with additional IP addresses.
ip addr show
Note the interface name (typically eth0, enp0s3, or similar) and current IP configuration.
Check current network management system
Determine whether your system uses systemd-networkd or NetworkManager for network configuration.
systemctl is-active systemd-networkd
systemctl is-active NetworkManager
The active service will show "active" while the inactive one shows "inactive" or "failed".
Configure with systemd-networkd
Create network configuration file
Create a systemd-networkd configuration file for your interface. Replace eth0 with your actual interface name.
[Match]
Name=eth0
[Network]
DHCP=yes
Address=192.168.1.100/24
Address=192.168.1.101/24
Address=192.168.1.102/24
Gateway=192.168.1.1
DNS=8.8.8.8
DNS=8.8.4.4
This configuration maintains DHCP for the primary address and adds three static secondary addresses.
Alternative static-only configuration
For environments requiring only static IP addresses, use this configuration instead.
[Match]
Name=eth0
[Network]
Address=203.0.113.10/24
Address=203.0.113.11/24
Address=203.0.113.12/24
Gateway=203.0.113.1
DNS=8.8.8.8
DNS=1.1.1.1
Enable and restart systemd-networkd
Enable systemd-networkd if not already active and restart the service to apply changes.
sudo systemctl enable systemd-networkd
sudo systemctl restart systemd-networkd
sudo systemctl status systemd-networkd
Disable NetworkManager (if active)
If NetworkManager is running, disable it to prevent conflicts with systemd-networkd.
sudo systemctl disable NetworkManager
sudo systemctl stop NetworkManager
Configure with NetworkManager
Add secondary IP addresses with nmcli
Use NetworkManager's command-line tool to add secondary IP addresses to an existing connection.
nmcli connection show
sudo nmcli connection modify "Wired connection 1" +ipv4.addresses 192.168.1.100/24
sudo nmcli connection modify "Wired connection 1" +ipv4.addresses 192.168.1.101/24
sudo nmcli connection modify "Wired connection 1" +ipv4.addresses 192.168.1.102/24
Replace "Wired connection 1" with your actual connection name from the first command.
Apply NetworkManager changes
Restart the network connection to apply the new IP addresses.
sudo nmcli connection down "Wired connection 1"
sudo nmcli connection up "Wired connection 1"
Create dedicated connection profile
For better organization, create a new connection profile with multiple IP addresses.
sudo nmcli connection add \
con-name multi-ip \
ifname eth0 \
type ethernet \
ipv4.method manual \
ipv4.addresses "203.0.113.10/24,203.0.113.11/24,203.0.113.12/24" \
ipv4.gateway 203.0.113.1 \
ipv4.dns "8.8.8.8,1.1.1.1"
Activate the new profile
Switch to the new connection profile with multiple IP addresses.
sudo nmcli connection up multi-ip
sudo nmcli connection show --active
Temporary configuration with ip command
Add temporary IP aliases
Use the ip command to add temporary secondary IP addresses for testing purposes.
sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip addr add 192.168.1.101/24 dev eth0
sudo ip addr add 192.168.1.102/24 dev eth0
Remove temporary IP addresses
Remove temporarily added IP addresses when no longer needed.
sudo ip addr del 192.168.1.100/24 dev eth0
sudo ip addr del 192.168.1.101/24 dev eth0
sudo ip addr del 192.168.1.102/24 dev eth0
Configure firewall rules
Update firewall for new IP addresses
Configure firewall rules to allow traffic on the new IP addresses. This example uses nftables for modern Linux distributions.
sudo nft add rule inet filter input ip daddr 192.168.1.100 tcp dport { 22, 80, 443 } accept
sudo nft add rule inet filter input ip daddr 192.168.1.101 tcp dport { 22, 80, 443 } accept
sudo nft add rule inet filter input ip daddr 192.168.1.102 tcp dport { 22, 80, 443 } accept
Adjust ports based on your specific service requirements.
Verify your setup
ip addr show eth0
ping -c 3 192.168.1.100
ping -c 3 192.168.1.101
ss -tlnp | grep :80
Verify connectivity from another machine on the network:
ping -c 3 192.168.1.100
ping -c 3 192.168.1.101
telnet 192.168.1.100 22
Check routing table and network configuration:
ip route show
nmcli device show eth0
systemctl status systemd-networkd
Common issues
| Symptom | Cause | Fix |
|---|---|---|
| Secondary IPs not accessible | Firewall blocking traffic | Configure firewall rules for new IP addresses |
| Configuration not persistent | Using temporary ip commands | Use systemd-networkd or NetworkManager configuration |
| Network conflicts | Both NetworkManager and systemd-networkd active | Disable one network management system |
| Gateway conflicts | Multiple gateways configured | Use same gateway for all addresses on subnet |
| DNS resolution issues | Missing or incorrect DNS configuration | Add DNS servers to network configuration |
| Service binding fails | Application not configured for new IPs | Configure applications to bind to specific addresses |
Use cases and best practices
Web server virtual hosts
Configure web servers to serve different sites on different IP addresses.
server {
listen 192.168.1.100:80;
server_name site1.example.com;
root /var/www/site1;
location / {
try_files $uri $uri/ =404;
}
}
Database server separation
Bind database services to specific IP addresses for security and organization.
[mysqld]
bind-address = 192.168.1.101
port = 3306