O contêiner libvirt lxc não usará endereço atribuído estaticamente na inicialização

O contêiner libvirt lxc não usará endereço atribuído estaticamente na inicialização

Eu tenho um contêiner LXC OS (CentOS 7) configurado via libvirt (CentOS 7):

<domain type='lxc'>
  <name>lxc-test1.example.com</name>
  <uuid>5a715193-55ef-49d7-a4f6-ac5c27bce838</uuid>
  <memory unit='KiB'>2097152</memory>
  <currentMemory unit='KiB'>2097152</currentMemory>
  <vcpu placement='static'>4</vcpu>
  <os>
    <type arch='x86_64'>exe</type>
    <init>/sbin/init</init>
  </os>
  <features>
    <privnet/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/libexec/libvirt_lxc</emulator>
    <filesystem type='mount' accessmode='passthrough'>
      <source dir='/var/lib/libvirt/filesystems/lxc-test1.example.com'/>
      <target dir='/'/>
    </filesystem>
    <interface type='bridge'>
      <mac address='00:16:3e:c3:6c:78'/>
      <source bridge='br_v123'/>
    </interface>
    <console type='pty'>
      <target type='lxc' port='0'/>
    </console>
  </devices>
</domain>

Quando o contêiner é iniciado, ele não configura sua rede adequadamente conforme definido em seu local/etc/sysconfig/network-scripts/ifcfg-eth0

TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.2.0.1
PREFIX=24
GATEWAY=10.2.0.254
DNS1=10.0.0.18
DNS2=10.0.0.19

Porém, se eu ifdown eth0 && ifup eth0estiver dentro do container ele obtém a configuração desejada.

# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
34: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:16:3e:c3:6c:78 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::216:3eff:fec3:6c78/64 scope link 
       valid_lft forever preferred_lft forever
 # ifdown eth0 && ifup eth0
 Device 'eth0' successfully disconnected.
 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)
 # ip addr
 34: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
     link/ether 00:16:3e:c3:6c:78 brd ff:ff:ff:ff:ff:ff
     inet 10.2.0.1/24 brd 10.47.34.255 scope global eth0
        valid_lft forever preferred_lft forever
     inet6 fe80::216:3eff:fec3:6c78/64 scope link 
        valid_lft forever preferred_lft forever

# ping -c 1 10.0.2.254
PING 10.0.2.254 (10.0.2.254) 56(84) bytes of data.
64 bytes from 10.0.2.254: icmp_seq=1 ttl=255 time=0.453 ms

--- 10.0.2.254 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.453/0.453/0.453/0.000 ms

Como posso fazer com que o libvirt inicie a rede do contêiner corretamente?

Responder1

systemctl disable NetworkManager
systemctl enable network

informação relacionada