我正在Debian上运行LXC容器(lxc 0.7.2-1),通过公网IPconfiguration的桥接networking,我有一个问题,就是将虚拟MAC地址从LXC容器暴露给外部networking,在那里被交换机端口阻塞以防止LXC容器与世界通信。 我在Ubuntu 12.04.2 LTS(lxc 0.7.5-3ubuntu67)上运行另一个LXC容器,networkingconfiguration相同,但是我没有任何问题,因为它不会将伪造的MAC暴露给外部networking,并且所有通信都与主机的MAC进行通信。
目前我正试图找出主机间networkingconfiguration的差异,但没有太多的成功。 它可能是lxc本身的版本依赖行为?
Debian / etc / network / interfaces
auto br0 iface br0 inet static bridge_ports eth0 bridge_fd 0 bridge_stp off bridge_maxwait 0 address yyy9 netmask 255.255.255.192 broadcast yyy63 gateway yyy1 pre-up iptables-restore < /etc/iptables.up.rules
Debian LXCnetworkingconfiguration
lxc.network.type = veth lxc.network.flags = up lxc.network.link = br0 lxc.network.hwaddr = fe:95:57:4b:b4:9b lxc.network.ipv4 = yyy12/26
Ubuntu / etc / network / interfaces
auto br0 iface br0 inet static bridge_ports eth0 bridge_fd 0 bridge_stp off bridge_maxwait 0 address zzz146 netmask 255.255.255.0 broadcast zzz255 gateway zzz1 pre-up iptables-restore < /etc/iptables.rules up route add xxx1 br0
Ubuntu LXCnetworkingconfiguration
lxc.network.type = veth lxc.network.flags = up lxc.network.link = br0 lxc.network.name = eth0 lxc.network.ipv4 = xxx1/32 lxc.network.hwaddr = 00:16:3e:87:b5:b9
不同的是,Ubuntu上的LXC容器使用不同子网的IP地址,当Debian上的LXC容器使用与主机相同的子网IP,并且其默认网关与主机相同时,其主机的IP作为默认网关。
当LXC容器的IP地址不同于其主机的子网,并将其主机作为默认网关时,来自LXC容器的数据包将被路由,当它们离开主机的networking接口时,它们将拥有主机的MAC。 当LXC容器与主机位于同一子网并使用相同的网关时,数据包将被桥接并保留LXC的伪MAC。 我的解决scheme是强制路由通过主机,即使他们在同一个子网。 在这种情况下,我的LXC容器具有以下/ etc / network / interfaces :
auto eth0 iface eth0 inet static address yyy12 netmask 255.255.255.255 post-up route add yyy9 dev eth0 post-up route add default gw yyy9
而LXC主机在sysctl.conf中有以下内容
net.ipv4.ip_forward=1 net.ipv4.conf.bond0.proxy_arp = 1
并在/ etc / network / interfaces中 :
auto bond0 iface bond0 inet static address yyy9 netmask 255.255.255.192 broadcast yyy63 gateway yyy1 auto lxcbr0 iface lxcbr0 inet static bridge_ports none bridge_fd 0 bridge_stp off bridge_maxwait 0 address 192.168.120.1 netmask 255.255.255.0 up echo 1 > /proc/sys/net/ipv4/conf/eth0/proxy_arp up /sbin/ip route add to yyy12 dev lxcbr0
我已经从上面的configuration中删除了不相关的选项。