How to create a bridge for lxc container with wlan0 NAT (for ubuntu 12.04)

1) On the host system, add a tap1 interface

ip tuntap add mode tap tap1
ifconfig tap1 up

2) Setup a bridge
brctl addbr br0
brctl addif br0 tap1
#let’s see the bridge:
brctl show
brctl showmacs br0

3) Setup an LXC container with the following settings in the /var/lib/lxc/my-ubuntu/config file: = 00:22:3e:da:58:6c
lxc.utsname = my-ubuntu


4) You can setup NAT now:
echo “1” > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

NOTE: Before you setup conteiner’s interfaces properly it might take too much time to start the container, If so then on the container host cd to /etc/network and change dhcp mode to manual for eth0

Troubleshooting tools:
tcpdump -i br0
tshark -i br0

General info about tun/tap:

How to configure a bridge

NAT How-to:

LXC containers:

1 comment
  1. Greg said:

    > ifconfig tap1 up

    Is ip assigned to tap1 expected to coincide with ip of default gw?

    > = 00:22:3e:da:58:6c

    Where does hwaddr come from? I took it from ifconifig tap1

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: