Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Usage on fedora hosts

Casey Link edited this page Feb 27, 2015 · 17 revisions

Fedora 21

Vagrant and vagrant-lxc are now in yum.

sudo dnf|yum install vagrant vagrant-libvirt vagrant-lxc

Read this blog post by the Fedora packager for more info.

Fedora 20

Out of Date: This page is for Fedora 20 and earlier versions of Vagrant + vagrant-lxc.

There is a known issue with SSH for some base boxes, please keep an eye on GH-171 for the latest information

Versions:

  • Fedora 20 x86_64
  • Vagrant 1.3.4
  • Vagrant-LXC 0.6.3

Install lxc and redir:

$ sudo yum install lxc lxc-extra redir

Configure lxc networking

Method 1: Make an explicit lxc bridge in systemd

  • /etc/systemd/system/lxc-net.service
[Unit]
Description=Bridge interface for LXC Containers

[Service]
Type=oneshot

# Bring up bridge interface
ExecStart=/sbin/brctl addbr lxcbr0
ExecStart=/sbin/ip address add 192.168.150.1/24 dev lxcbr0
ExecStart=/sbin/ip link set lxcbr0 up

RemainAfterExit=yes

# Bring bridge interface down
ExecStop=/sbin/ip link set lxcbr0 down
ExecStop=/sbin/brctl delbr lxcbr0
  • /etc/systemd/system/lxc-dhcp.service
[Unit]
Requires=lxc-net.service
Requires=sys-devices-virtual-net-lxcbr0.device
After=sys-devices-virtual-net-lxcbr0.device

[Service]
ExecStart=/sbin/dnsmasq \
            --dhcp-leasefile=/var/run/lxc-dnsmasq.leases \
            --user=qemu \
            --group=qemu \
            --keep-in-foreground \
            --listen-address=192.168.150.1 \
            --except-interface=lo \
            --bind-interfaces \
            --dhcp-range=192.168.150.2,192.168.150.254

[Install]
WantedBy=default.target
  • Enable lxc-dhcp.service
$ sudo systemctl enable lxc-dhcp.service

Credits for systemd configuration go to @riccieri

Configure firewalld

  1. Open firewall application.
  2. Switch to permanent configuration mode.
  3. On public zone:
  • Enable masquerading.
  • Enable DHCP in services
  1. On trusted zone:
  • Add lxcbr0 to interfaces tab.
  • On top tab Direct Configuration add the following rule:
    • ipv: ipv4
    • table: mangle
    • Chain: POSTROUTING
    • Priority: 0 (Change it to fit your needs)
    • Args: -p udp --dport bootpc -j CHECKSUM --checksum-fill

NOTE: The last step of adding a rule is only needed if running Debian (or other distros) with ancient DHCP clients.

Final step

  • Reboot :-)

Method 2: Use the existing virbr0 provided by libvirtd

This method doesn't require creating an additional bridge and dnsmasq configuration, and it adheres more closely to the Fedora default lxc configuration. However it requires tweaking your Vagrantfile to override the default lxc configuration in the base box.

Install and start libvirtd to enable the virbr0 bridge

sudo yum install libvirt-daemon
sudo systemctl start libvirtd

Add snippet to Vagrantfile to override default in @fgrehm's base boxes

config.vm.provider :lxc do |vm|
    vm.customize 'network.link', 'virbr0'
end

PROTIP: You can add that snippet to your $HOME/.vagrant.d/Vagrantfile so all vagrant-lxc machines you use have it configured properly