Multiple IP addresses with bonded interfaces
Solution 1:
As I had this issue myself and there is little information on it anywhere, so here is the "correct" solution for the /etc/network/interfaces file:
auto bond0
iface bond0 inet static
address 192.168.0.5
netmask 255.255.255.0
gateway 192.168.0.1
bond-mode 802.3ad
bond-miimon 100
bond-updelay 200
bond-downdelay 200
bond-lacp-rate 1
bond-slaves eth0 eth1
auto bond0:1
iface bond0:1 inet static
address 192.168.10.160
netmask 255.255.255.0
It works almost the same as with regular interfaces like eth0, but you must not repeat the bond configuration - that should only be in the bond0 configuration. You can then add as many additional IP addresses as needed like this, as bond0:2, bond0:3, etc.
If you also want to add IPv6 addresses, it is a little different again, as you need to add this (as an example):
iface bond0 inet6 static
address 2eee:354:3a3::745
netmask 64
gateway 2eee:354:3a3::1
IPv6 does not need bond0:1 or similar workarounds - just use bond0 for every address. It uses the bond settings from the IPv4 address, like a second IPv4 address. And you do not need to repeat the gateway part for additional IPv6 addresses, just use address
and netmask
for the second IPv6 address.
After you changed the interfaces file, you should execute the following commands to fully restart networking and load these changes:
ip address flush eth0
ip address flush eth1
systemctl restart networking
This removes all IP addresses from eth0 and eth1 and then restarts networking with the new configuration. Make sure you are logged in locally to the machine, as you need to completely turn of networking before restarting it, so all connections will be lost.