Skip to content

Instantly share code, notes, and snippets.

@fgrehm
Last active December 19, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fgrehm/68fa349251d70dfe8470 to your computer and use it in GitHub Desktop.
Save fgrehm/68fa349251d70dfe8470 to your computer and use it in GitHub Desktop.
lxc bridge for debian
sudo apt-get install -y bridge-utils dnsmasq
# USE_LXC_BRIDGE="false"
LXC_BRIDGE="lxcbr0"
LXC_ADDR="10.0.53.1"
LXC_NETMASK="255.255.255.0"
LXC_NETWORK="10.0.53.0/24"
LXC_DHCP_RANGE="10.0.53.2,10.0.53.254"
LXC_DHCP_MAX="253"
varrun="/var/run/lxc"
cleanup() {
# dnsmasq failed to start, clean up the bridge
sudo iptables -t nat -D POSTROUTING -s ${LXC_NETWORK} ! -d ${LXC_NETWORK} -j MASQUERADE || true
sudo ifconfig ${LXC_BRIDGE} down || true
sudo brctl delbr ${LXC_BRIDGE} || true
}
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
sudo mkdir -p ${varrun}
sudo brctl addbr ${LXC_BRIDGE}
sudo ifconfig ${LXC_BRIDGE} ${LXC_ADDR} netmask ${LXC_NETMASK} up
sudo dnsmasq --strict-order --bind-interfaces --pid-file=${varrun}/dnsmasq.pid --conf-file= --listen-address ${LXC_ADDR} --dhcp-range ${LXC_DHCP_RANGE} --dhcp-lease-max=${LXC_DHCP_MAX} --dhcp-no-override --except-interface=lo --interface=${LXC_BRIDGE} --dhcp-leasefile=/var/lib/misc/dnsmasq.${LXC_BRIDGE}.leases --dhcp-authoritative || cleanup
sudo iptables -t nat -A POSTROUTING -s ${LXC_NETWORK} ! -d ${LXC_NETWORK} -j MASQUERADE
sudo touch ${varrun}/network_up
# https://wiki.debian.org/LXC#Prepare_the_host
# https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/936756
sudo mkdir -p /cgroup
sudo mount none -t cgroup /cgroup
# lxc.customize 'cgroup.memory.limit_in_bytes', '400M' doesnt work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment