libvirt lxc 컨테이너는 시작 시 정적으로 할당된 주소를 사용하지 않습니다.

libvirt lxc 컨테이너는 시작 시 정적으로 할당된 주소를 사용하지 않습니다.

libvirt(CentOS 7)를 통해 구성된 LXC OS 컨테이너(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>

컨테이너가 시작되면 로컬에 정의된 대로 네트워크가 적절하게 설정되지 않습니다./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

ifdown eth0 && ifup eth0그러나 컨테이너 내에 있으면 원하는 구성을 얻습니다.

# 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

libvirt가 컨테이너의 네트워크를 올바르게 시작하도록 하려면 어떻게 해야 합니까?

답변1

systemctl disable NetworkManager
systemctl enable network

관련 정보