LXC 容器的公共静态 IP 地址

LXC 容器的公共静态 IP 地址

我有一台运行 Ubuntu 14(服务器版)的服务器,使用两个网络适配器连接到网络。这两个网络适配器配置为绑定,以提供网络冗余(以防其中一个发生故障)。此服务器配置了静态 IP 地址

在这台服务器上,我安装了 LXC 并创建了一个新容器。我想将这个容器也直接连接到网络,所以我创建了一个网桥。

这是我的主机服务器上的网络配置(/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

# The primary network interface
auto p2p3
iface p2p3 inet manual
bond-master bond0

auto p2p4
iface p2p4 inet manual
bond-master bond0

# Set up a bonding NIC
auto bond0
iface bond0 inet manual
bond-mode active-backup
bond-miimon 100
bond-slaves p2p3 p2p4

# Set up bridge
auto br0
iface br0 inet static
address 103.129.12.95
gateway 103.129.12.1
netmask 255.255.255.0
dns-nameservers 103.129.12.2 103.129.12.3
bridge-ports bond0
up ip route add 192.168.105.0/24 via 103.129.12.23

这是容器配置:

lxc.include = /usr/share/lxc/config/ubuntu.common.conf
lxc.rootfs = /var/lib/lxc/mailman/rootfs
lxc.mount = /var/lib/lxc/mailman/fstab
lxc.utsname = mailman
lxc.arch = amd64
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
lxc.network.hwaddr = 12:ae:9a:12:ac:32
lxc.start.auto = 0
lxc.loglevel = 0
lxc.network.ipv4 = 103.129.12.96
lxc.network.ipv4.gateway = 103.129.12.1

以及容器的网络配置(/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

我的配置似乎有问题,因为网络仅在主机上有效(而不在容器上)。有人能给我指点一下吗?谢谢!

答案1

事实证明我必须将网络掩码添加到容器网络配置中:

lxc.network.ipv4 = 103.129.12.96/24

最好将容器接口也改为手动:

iface eth0 inet manual

相关内容