问题
Right now, after installing LXC, you only have one default bridge "lxcbr0" which is used to connect your container to host machine. So through this way, we can create multiple containers and connect them all to the bridge "lxcbr0". My question is: Can I create two bridges "lxcbr0" and "lxcbr1" such that I can divide the multiple containers into two subnetwork, one of which connects to "lxcbr0" and the other one connects to "lxcbr1"?
Happy Holidays! Thanks. Deryk
回答1:
It's bash code that add lxcbr1 connacted to eth2
main.sh:
#!/bin/bash
BRCTL_BIN="/sbin/brctl"
IP_BIN="/sbin/ip"
# variable
brName=lxcbr1
brDev=eth2
# function: add bridge
#
function addBr() {
local brName=$1
local brDev=$2 || ""
if [ -d /sys/class/net/${brName} ]; then
# bridge exists
return
else
${BRCTL_BIN} addbr ${brName}
${BRCTL_BIN} setfd ${brName} 0
${BRCTL_BIN} sethello ${brName} 5
${IP_BIN} link set dev ${brName} up
if [ "${brDev}x" != "x" ]; then
${BRCTL_BIN} addif ${brName} ${brDev}
${IP_BIN} link set dev ${brDev} up
fi
fi
}
# add lxcbr1
addBr ${brName} ${brDev}
# it's simple example
# without bash variable
# add lxcbr1 and lxcbr3
addBr lxcbr1 eth1
addBr lxcbr3 eth3
Now you can connect your lxc container to lxcbr1 as eth11
lxc.network.type = veth
lxc.network.flags = up
lxc.network.mtu = 1500
lxc.network.link = lxcbr1
lxc.network.ipv4 = 192.168.0.11/24
lxc.network.name = eth11
lxc.network.veth.pair = veth11.1
来源:https://stackoverflow.com/questions/27653162/how-to-create-multiple-bridges-of-lxc