Using aliased bond interface on host by an lxc container

As the title says, how do I edit the lxc container's configuration to use the aliased bond0 interface on the host? This is what I have in the /etc/network/interfaces file now:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
#allow-hotplug eth0
#iface eth0 inet static
#   address 192.168.100.90/22
#   gateway 192.168.101.1


auto bond0
iface bond0 inet static
    address 192.168.100.90/22
    gateway 192.168.101.1
    bond-slaves eth0 eth1
    bond-mode active-backup
    bond-miimon 100
    bond-primary eth0 eth1

Can I add this to at the end:

auto bond0:101
iface bond0:101 inet static
    address 192.168.100.101
    netmask 255.255.252.0

and make the lxc container use this address? I don't want bridging, I just want the host and lxc cont. on the same network. I don't know what configuration options go into /var/lib/lxc/lxc_cont/config file. I tried this

lxc.network.type = phys
lxc.network.flags = up
lxc.network.link = bond0:101
lxc.network.hwaddr = 00:00:00:fe:fe:01
lxc.network.ipv4 = 192.168.100.101/22
lxc.network.ipv4.gateway = 192.168.101.1

but get this error:

lxc-start 20160912185144.642 ERROR    lxc_conf - conf.c:lxc_assign_network:3044 - failed to move 'bond0:101' to the container : Invalid argument
      lxc-start 20160912185144.642 ERROR    lxc_start - start.c:lxc_spawn:1197 - failed to create the configured network

In the future I would be adding other containers on the bond0 interface such as:

auto bond0:102
iface bond0:102 inet static
    address 192.168.100.102
    netmask 255.255.252.0

auto bond0:102

etc.

I've setup containers using bridged interface before, but I'm stuck whith regards to this bonding thing.

Any help or pointers are much appreciated!

Thanks for your time!

P.S. seems to me that my question is similar to this one

https://serverfault.com/questions/744443/is-there-a-way-to-get-the-kvm-guest-using-alias-interfaces-to-communicate-with-o

1
задан 13 April 2017 в 15:14
1 ответ

На работе мне помогал коллега-администратор. Это рабочая конфигурация:

# interfaces file

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
#allow-hotplug eth0
#iface eth0 inet static
#   address 192.168.100.90/22
#   gateway 192.168.101.1

auto bond0
iface bond0 inet manual
    bond-slaves eth0 eth1
    bond-mode active-backup
    bond-miimon 100
    bond-primary eth0 eth1

auto br0
iface br0 inet static
    address 192.168.100.90
    netmask 255.255.252.0
    gateway 192.168.101.1
    bridge-ports bond0
    bridge-fd 0
    bridge-stp off
    bridge-maxwait 5

Итак, вам нужно переместить IP-адрес на мост. lxc-config выглядит так:

...
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
lxc.network.name = eth0
lxc.network.mtu = 1500
lxc.network.hwaddr = 00:00:00:fe:fe:01
lxc.network.ipv4 = 192.168.100.91/22
lxc.network.ipv4.gateway = 192.168.101.1
...

Обычно я также редактирую файл интерфейсов для гостя, хотя в этом нет необходимости, поскольку конфигурация выше управляет назначением IP:

# guest interfaces file
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
    address 192.168.100.91
    netmask 255.255.252.0

Итак, теперь хост-машина и будущие гостевые контейнеры lxc будет находиться в той же сети. Для другого контейнера lxc вы просто назначаете следующий ip в подсети. Думаю, вам не нужны macvlans, я пробовал использовать их, но не смог заставить их работать.

Надеюсь, кто-то сочтет это полезным, если они это сделают, я отмечу это как принятый ответ.

Если я пропустил некоторая информация, дайте мне знать.

0
ответ дан 4 December 2019 в 05:53

Теги

Похожие вопросы