1) On the host system, add a tap1 interface
ip tuntap add mode tap tap1
ifconfig tap1 192.168.1.1 up
2) Setup a bridge
brctl addbr br0
brctl addif br0 tap1
#let’s see the bridge:
brctl show
#also:
brctl showmacs br0
3) Setup an LXC container with the following settings in the /var/lib/lxc/my-ubuntu/config file:
lxc.network.type=veth
lxc.network.link=br0
lxc.network.flags=up
lxc.network.hwaddr = 00:22:3e:da:58:6c
lxc.utsname = my-ubuntu
ping 192.168.1.1
4) You can setup NAT now:
#!/bin/bash
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
ping
wget
nslookup
General info about tun/tap:
http://en.wikipedia.org/wiki/TUN/TAP
How to configure a bridge
http://www.lainoox.com/bridge-brctl-tutorial-linux/
NAT How-to:
http://www.blindhog.net/linux-bridging-for-gns3-lan-communications/
http://www.netfilter.org/documentation/HOWTO/NAT-HOWTO-6.html
LXC containers:
http://www.janoszen.com/2012/06/04/lxc-linux-containers-on-steroids/
https://www.stgraber.org/2012/05/04/lxc-in-ubuntu-12-04-lts/