Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Gentoo host for vagrant-lxc
View unanswered posts
View posts from last 24 hours

Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message

Joined: 05 Jul 2009
Posts: 34

PostPosted: Wed Oct 07, 2015 9:40 pm    Post subject: Gentoo host for vagrant-lxc Reply with quote

As a developer I've got used to vagrant way of doing things. Also, as most of stuff I develop for are to be run on ubuntu or RH servers I can made my life easier building it straight on those environments. But running vagrant on virtualbox is too resource intensive. So why not run it as a container? That's why I like lxc. It took me a while to get a working NAT network setup, and could not find any gentoo tutorial, so this DOC may help any newcomers.

Vagrant-LXC for gentoo hosts

1. First thing is to install vagrant. Is better to get the latest binary version. So you need layman.


sudo layman -a johu
sudo emerge -av vagrant-bin

You may need to unmask vagrant-bin either by executing dispatch-conf or manually editing package.keywords.

2. We also need bridge-utils, dnsmasq and lxc


sudo emerge -av bridge-utils dnsmasq lxc

You could use any private IP range. Is better to choose an uncommon one and of course, different than your home/work network. So I did choose

3. Let's try to manually setup the network:


sudo brctl addbr lxcbr0
sudo ifconfig lxcbr0 netmask up
sudo dnsmasq --strict-order --bind-interfaces --pid-file=/run/ --conf-file= --listen-address --dhcp-range ","  --dhcp-lease-max=253 --dhcp-no-override --except-interface=lo --interface=lxcbr0 --dhcp-leasefile=/var/lib/misc/dnsmasq.lxcbr0.leases --dhcp-authoritative

I'm assuming wlan0 is your external interface. Replace it for your interface.

sudo /sbin/iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sudo /sbin/iptables -A FORWARD -i wlan0 -o lxcbr0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo /sbin/iptables -A FORWARD -i lxcbr0 -o wlan0 -j ACCEPT

We need to install vagrant-lxc plugin:

vagrant plugin install vagrant-lxc

4. As a starting point we are going to bring up an Ubuntu Trusty lxc container.

I use to keep my vagrant projects inside ~/Projects

mkdir -p ~/Projects/teste
cd ~/Projects/teste
vagrant init beubi/trusty64
vagrant up --provider=lxc

So if everything is working you could now enter the new ubuntu vagrant VM by executing

vagrant ssh

Great but our network setup is not definitive. Let's make it!


brctl_lxcbr0="setfd 0
sethello 10
stp off"




Setup startup scripts

cd /etc/init.d
sudo ln -s net.lo net.lxcbr0
sudo rc-update add net.lxcbr0 default
sudo rc-update add dnsmasq default
sudo rc-update add iptables default
sudo /etc/init.d/iptables save

You may start those scripts right away but is better to do a full system reboot so you can make sure things are going to work forever.

lxcbr0 should be up and IP assigned.

Login to your vagrant VM and test your network:

cd ~/Projects/teste
vagrant ssh

vagrant-lxc github page:
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum