-
-
Save fgrehm/68fa349251d70dfe8470 to your computer and use it in GitHub Desktop.
lxc bridge for debian
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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