我想在主机下运行2个LXC容器,并且我希望每个在networking上都有自己的IP,假设主机有10.10.1.10,容器有10.10.1.11和10.10.1.12。
我的设置是否要求在hosts / etc / network / interfaces文件中configuration2个桥接接口,如下所示:
auto br0 iface br0 inet static address 10.10.1.11 #ip of our host netmask 255.255.255.0 #subnet of our host network 10.10.1.0 #network of our host broadcast 10.10.1.255 #our broadcast address gateway 10.10.1.1 #default gw for our host to access the internet bridge_ports eth0 bridge_fd 9 bridge_hello 2 bridge_maxage 12 bridge_stp off auto br1 iface br0 inet static address 10.10.1.12 #ip of our host netmask 255.255.255.0 #subnet of our host network 10.10.1.0 #network of our host broadcast 10.10.1.255 #our broadcast address gateway 10.0.1.1 #default gw for our host to access the internet bridge_ports eth0 bridge_fd 9 bridge_hello 2 bridge_maxage 12 bridge_stp off
或者还有另一种方式来configuration主机更像交换机,并允许个别容器configuration自己的IP (这将是更安全的,所以我们并不总是改变接口文件,每当我们移动容器)。
在主机上使用一个网桥。
LXCconfiguration文件决定了访客/容器IP地址是什么。
# ifconfig br0 Link encap:Ethernet HWaddr 22:C7:47:62:9C:02 inet addr:10.2.0.6 Bcast:10.2.127.255 Mask:255.255.128.0 inet6 addr: fe80::e611:5bff:febe:b62a/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1756184372 errors:0 dropped:0 overruns:0 frame:0 TX packets:470262588 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:112684582109 (104.9 GiB) TX bytes:657886062154 (612.7 GiB)
和一个示例LXCconfiguration文件…
# cat /etc/lxc/Analytics.conf lxc.utsname = Analytics lxc.tty = 4 lxc.network.type = veth lxc.network.flags = up lxc.network.link = br0 lxc.network.name = eth0 lxc.network.mtu = 1500 lxc.network.ipv4 = 10.2.0.80/17 lxc.network.hwaddr = 00:30:6E:08:EC:80 lxc.rootfs = /srv/lxc/Analytics lxc.mount = /etc/lxc/Analytics.fstab lxc.cgroup.devices.deny = a # /dev/null and zero lxc.cgroup.devices.allow = c 1:3 rwm lxc.cgroup.devices.allow = c 1:5 rwm # consoles lxc.cgroup.devices.allow = c 5:1 rwm lxc.cgroup.devices.allow = c 5:0 rwm lxc.cgroup.devices.allow = c 4:0 rwm lxc.cgroup.devices.allow = c 4:1 rwm # /dev/{,u}random lxc.cgroup.devices.allow = c 1:9 rwm lxc.cgroup.devices.allow = c 1:8 rwm # /dev/pts/* lxc.cgroup.devices.allow = c 136:* rwm lxc.cgroup.devices.allow = c 5:2 rwm # rtc lxc.cgroup.devices.allow = c 254:0 rwm