13

We have a server with multiple IP adresses. Lately we migrated to systemd and we still need mutliple IPs on that server. With systemd-networkd we have some trouble finding a configuration example. so we use a bash script at the end of the boot process to add the ips to the interface.

Can someone provide a systemd-networkd config example for adding more than one IP to one interface.

2
  • Have you checked man systemd.network ? Just a sidenote, you don't have to go ALL in an use systemd-networkd. What distribution are we talking about?
    – ek9
    Jul 2, 2014 at 7:09
  • We checked the manpage. I think it is very compatible and portable if we use systemd-netword, as it will be available on all distros soon. Distro is gentoo.
    – user61664
    Jul 2, 2014 at 7:35

3 Answers 3

15

According to systemd.network(5), you can simply add multiple Address= lines to the [Network] section, with the required addresses.

[Network]
Address=10.2.3.4/16
Address=10.6.7.8/16
Gateway=...

Alternatively, create a separate [Address] section for each address.

[Network]
Gateway=...

[Address]
Address=10.2.3.4/16

[Address]
Address=10.6.7.8/16

(The same applies to [Route] sections and Gateway= parameters.)

Note that systemd-networkd is still very new and receives bug fixes almost daily. Make sure you're using the latest systemd release, and test the Git builds if possible. See the mailing list and the IRC channels #systemd & #gentoo-systemd on freenode in case of bugs.

2
  • 3
    In Ubuntu 16.04 LTS, the first method does not seem to work (only the first IP address is reachable). However, the second method, with separate [Address] sections, does work. For what it's worth, I have defined a single gateway under the [Network] section, as in the second example. I should add also that I am unable to get two static IP addresses working on two separate physical network interfaces, no matter what I try (I have yet to find an example of this in the systemd documentation or elsewhere on the web), so I'm left to settle for two IP addresses on a single interface. Sep 23, 2016 at 16:56
  • doesn't work in Arch Linux, SystemD 249.2-1
    – Kevin
    Sep 8, 2021 at 14:14
1

I'm using a container under Proxmox, and Proxmox writes its own /etc/systemd/network/eth0.network in the container. To get around not being able to rely on that file not being overwritten, you can create a drop-in file with the additional IP address(es), /etc/systemd/network/eth0.network.d/additional-ips.conf

[Match]
Name = eth0

[Address]
Address = 192.168.1.102/24
0

Using Arch Linux, SystemD 249.2-1, none of these (3) methods work (tried this answer too)

-------------------------
[Network]
Address=10.2.3.4/16
Address=10.6.7.8/16
-------------------------
[Network]
Address=192.168.59.1/24 192.168.1.5/24
-------------------------
[Address]
Address=10.2.3.4/16

[Address]
Address=10.6.7.8/16
-------------------------

Instead, using a simple SystemD service, you can set a second IP after boot... See this answer for more details on systemd service creation... Bonus point: this method allows you to have static or DHCP for the primary address.

  • touch /usr/local/bin/second_ip
  • chmod +x /usr/local/bin/second_ip
  • edit file as per below
#!/bin/bash
ip address add 10.10.128.128/16 dev eth0
  • touch /etc/systemd/system/second-ip.service

  • edit file as per below

  • systemctl enable second-ip

     [Unit]
     Description=second ip service
     After=network.target
    
     [Service]
     User=root
     ExecStart=/usr/local/bin/second_ip                                                                                      Type=simple
    
     [Install]
     WantedBy=multi-user.target
    

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .