LXCコンテナにネットワークインターフェイスを追加する方法

LXCコンテナにネットワークインターフェイスを追加する方法

LXCコンテナのネットワークインタフェースに関する質問があります。私のコンテナにはデフォルトで次のインターフェイスがあります。

ubuntu@u5:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:16:3e:b7:de:91 
          inet addr:10.0.3.138  Bcast:10.0.3.255  Mask:255.255.255.0
          inet6 addr: fe80::216:3eff:feb7:de91/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:56 errors:0 dropped:0 overruns:0 frame:0
          TX packets:40 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:7230 (7.2 KB)  TX bytes:3500 (3.5 KB)

       lo        Link encap:Local Loopback 
                 inet addr:127.0.0.1  Mask:255.0.0.0
                 inet6 addr: ::1/128 Scope:Host
                 UP LOOPBACK RUNNING  MTU:65536  Metric:1
                 RX packets:0 errors:0 dropped:0 overruns:0 frame:0
                 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
                 collisions:0 txqueuelen:0
                 RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

次のような新しいインターフェイスを追加したいと思います。

      auto eth1

      iface eth1 inet static
      address 192.168.1.3
      netmask 255.255.255.0
      network 192.168.1.1
      broadcast 192.168.1.255

だからこのファイルを修正しました:/etc/network/interfaces

     # This file describes the network interfaces available on your system
     # and how to activate them. For more information, see interfaces(5).

     # The loopback network interface
     auto lo
     iface lo inet loopback

     auto eth0
     iface eth0 inet dhcp

     auto eth1

     iface eth1 inet static
     address 192.168.1.3
     netmask 255.255.255.0
     network 192.168.1.1
     broadcast 192.168.1.255

再起動しましたが役に立たない! ifconfigを使用すると、新しいインターフェイスが見つかりません。

      ubuntu@u5:/etc/network$ ifconfig
      eth0      Link encap:Ethernet  HWaddr 00:16:3e:b7:de:91 
                inet addr:10.0.3.138  Bcast:10.0.3.255  Mask:255.255.255.0
                inet6 addr: fe80::216:3eff:feb7:de91/64 Scope:Link
                UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                RX packets:57 errors:0 dropped:0 overruns:0 frame:0
                TX packets:40 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:1000
                RX bytes:7337 (7.3 KB)  TX bytes:3500 (3.5 KB)

       lo        Link encap:Local Loopback 
                 inet addr:127.0.0.1  Mask:255.0.0.0
                 inet6 addr: ::1/128 Scope:Host
                 UP LOOPBACK RUNNING  MTU:65536  Metric:1
                 RX packets:0 errors:0 dropped:0 overruns:0 frame:0
                 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
                 collisions:0 txqueuelen:0
                 RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

どんなアイデアがありますか?

ベストアンサー1

ゲスト以外のホストでコンテナ構成ファイルを変更する必要があります(confファイルがあるかどうかを指定していません)。/etc/lxcまたは~/.config/lxc)、以下のように新しいインターフェースに関連する新しいセクションを追加します。

 lxc.network.type = veth
 lxc.network.name = eth0
 lxc.network.link = br0
 lxc.network.ipv4 = 10.0.3.138/24
 lxc.network.flags = up

 lxc.network.type = veth
 lxc.network.link = br1
 lxc.network.ipv4 = 192.168.0.63/24
 lxc.network.name = eth1
 lxc.network.flags = up

最初のセクションはすでに持っている項目(一部の追加オプションを含めるか除く)であり、2番目のセクションは他のサブネットの新しいインターフェイスにすでに存在する項目をコピーします。その後、ゲストを再起動します。

おすすめ記事