Created
February 11, 2015 18:02
-
-
Save asakura/294c6612a3b86adc8a20 to your computer and use it in GitHub Desktop.
dnsmasq for docker, static address for lxc
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 -i | |
service docker stop | |
lxc-stop -n conjur-standalone-01 | |
service lxc-net stop | |
service lxc stop | |
# Delete old bridges | |
ip link set dev docker0 down | |
brctl delbr docker0 | |
ip link set dev lxcbr0 down | |
brctl delbr lxcbr0 | |
iptables -t nat -F POSTROUTING | |
# Create brand new bridges | |
brctl addbr br0 | |
ip addr add 10.0.0.1/24 dev br0 | |
ip link set dev br0 up | |
brctl addbr br1 | |
ip addr add 10.0.1.1/24 dev br1 | |
ip link set dev br1 up | |
cat << EOF > /etc/network/interfaces.d/br0.cfg | |
auto br0 | |
iface br0 inet dhcp | |
pre-up brctl addbr br0 | |
pre-up ip addr add 10.0.0.1/24 dev br0 | |
post-down ip link set br0 down | |
post-down brctl delbr br0 | |
EOF | |
# Install and configure dnsmasq | |
aptitude install -yqq dnsmasq | |
cat << EOF > /etc/dnsmasq.conf | |
address=/conjur/10.0.1.2 | |
listen-address=10.0.0.1,127.0.0.1 | |
no-dhcp-interface=10.0.0.1 | |
EOF | |
service dnsmasq restart | |
# Update docker's settings | |
echo 'DOCKER_OPTS="-b=br0 --dns 10.0.0.1"' >> /etc/default/docker | |
service docker start | |
# Update LXC's settings | |
cat << EOF > /etc/default/lxc-net | |
USE_LXC_BRIDGE="true" | |
LXC_BRIDGE="br1" | |
LXC_ADDR="10.0.1.1" | |
LXC_NETMASK="255.255.255.0" | |
LXC_NETWORK="10.0.1.0/24" | |
LXC_DHCP_RANGE="10.0.1.2,10.0.1.254" | |
LXC_DHCP_MAX="253" | |
LXC_DHCP_CONFILE=/etc/lxc/dnsmasq.conf | |
EOF | |
cat << EOF > /etc/lxc/default.conf | |
lxc.network.type = veth | |
lxc.network.link = br1 | |
lxc.network.flags = up | |
lxc.network.hwaddr = 00:16:3e:xx:xx:xx | |
EOF | |
cat << EOF > /etc/lxc/dnsmasq.conf | |
dhcp-host=conjur-standalone-01,10.0.1.2 | |
EOF | |
cat << EOF > /etc/dnsmasq.d/lxc | |
bind-interfaces | |
except-interface=br1 | |
EOF | |
# Update lxc container's settings | |
cat << EOF > /var/lib/lxc/conjur-standalone-01/config | |
lxc.start.auto = 1 | |
lxc.start.delay = 5 | |
lxc.start.order = 100 | |
lxc.network.type = veth | |
lxc.network.flags = up | |
lxc.network.link = br1 | |
lxc.network.hwaddr = 00:16:3e:63:0b:ec | |
EOF | |
service lxc-net start | |
service lxc start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment