详情参考:https://wiki.debian.org/LXC/SimpleBridge
1) 使用网桥
假设我们主机只有eth0的物理网卡,在主机/etc/network/interfaces中,直接加入下面的字段:
auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_fd 0
bridge_maxwait 0
然后重启网络 /etc/init.d/networking restart 之后可以发现主机网络出现br0的网桥。
如果LXC在编译时没有配置路径,容器的config默认路径在/usr/local/var/lib/lxc/xxx/config ,我们需要在这个文件中加入网络选项
lxc.network.type = veth
lxc.network.flags = up
# that's the interface defined above in host's interfaces file
lxc.network.link = br0
# name of network device inside the container,
# defaults to eth0, you could choose a name freely
# lxc.network.name = lxcnet0
lxc.network.hwaddr = 00:FF:AA:00:00:01
然后我