Skip to content

Instantly share code, notes, and snippets.

@AdamIsrael
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamIsrael/cc51d3d704c18095f718 to your computer and use it in GitHub Desktop.
Save AdamIsrael/cc51d3d704c18095f718 to your computer and use it in GitHub Desktop.
Vagrantfile to route network traffic w/o sshuttle

Juju Vagrant without sshuttle.

sshuttle allows traffic to be routed to the internal network (10.0.3.0) used for the lxc containers inside a Juju Vagrant image. sshuttle does not work with OS X 10.10 (Yosemite). This alternate solution alters your local network routing rules in order to communicate directly with the virtual machine over its vboxnet0 bridge. It's also faster than using sshuttle, because it doesn't need to proxy over an SSH tunnel or teardown/reassemble the TCP packets.

This approach adds and removes the route when a virtual machine is brought up and taken down, and requires sudo at each step. Alternatively, you could add this route at boot or via login script.

Installation

You'll need to have the triggers plugin installed for this to work.

vagrant plugin install vagrant-triggers

Add the config.trigger rules in your Vagrantfile:

config.trigger.after [:provision, :up, :reload] do
    system('sudo route add -net 10.0.3.0/24 172.16.250.15 >/dev/null')
end

config.trigger.after [:halt, :destroy] do
    system('sudo route delete -net 10.0.3.0/24 172.16.250.15 >/dev/null')
end

Optionally, add a sudoer role so you don't have to enter your password each time:

user ALL=(ALL) NOPASSWD: /sbin/route
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "trusty"
config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-juju-vagrant-disk1.box"
config.vm.provider :virtualbox do |vb|
# Default ram is 2G. Tried w/4G but may be running into issues with VM locking when host mem is exhausted
vb.customize ["modifyvm", :id, "--memory", 4096]
# increase the cpu cap
vb.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
end
###########################################################
# Configure routing so we can connect to lxc w/o sshuttle #
# $ vagrant plugin install vagrant-triggers #
###########################################################
config.trigger.after [:provision, :up, :reload] do
system('sudo route add -net 10.0.3.0/24 172.16.250.15 >/dev/null')
end
config.trigger.after [:halt, :destroy] do
system('sudo route delete -net 10.0.3.0/24 172.16.250.15 >/dev/null')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment