Create Vagrant private network with both an IPv4 and IPv6 address?

2,787 views
Skip to first unread message

Robert F

unread,
May 10, 2016, 3:39:43 PM5/10/16
to Vagrant
Is it possible to create a private network on a Vagrant box that has both an IPv4 and IPv6 address?  I'd like to do something like this:

config.vm.network "private network", ip: "192.168.1.100"
config.vm.network "private network", ip6: "<some internal private IPv6 address>"

The reason I'd like to do this is that I have an Ansible play that needs to reference "ansible_default_ipv6.address" but there is no such address associated with my Vagrant VM if I'm also using an IPv4 address.  The Vagrant documentation doesn't discuss this so I'm guessing its not possible but I thought I would check here in case there's some undocumented way to do it.

Thanks!

pixel fairy

unread,
May 10, 2016, 3:55:52 PM5/10/16
to Vagrant
yes, just like you said. you may have trouble if your host is windows. in that case run linux in vmware and vagrant in that. if you want i can post an example or two.

pixel fairy

unread,
May 10, 2016, 3:56:50 PM5/10/16
to Vagrant
v6 addresses are handled the same way in Vagrantfile

Robert F

unread,
May 10, 2016, 4:05:39 PM5/10/16
to Vagrant
I should have mentioned that I'm running Vagrant on a Mac, not Windows.  Yes, if you have any examples of how this is done, I would love to see them.

Alvaro Miranda Aguilera

unread,
May 10, 2016, 5:20:25 PM5/10/16
to vagra...@googlegroups.com
Hello,

The easiest way is use bridge and let the dhcp/dhcpv6 to take care:
https://www.vagrantup.com/docs/networking/public_network.html

Or you can create 2 networks, one for ipv4 other for ipv6 and set the ip like this:
https://www.vagrantup.com/docs/networking/private_network.html

Alvaro.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/484eca69-6808-4c70-a2bb-17c3e0299699%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Robert F

unread,
May 10, 2016, 5:28:49 PM5/10/16
to Vagrant
I have reasons for not wanting to use DHCP in this situation.  And the Vagrant doc which you mentioned, and which I had already read, does not provide a way to differentiate between specifying an IPv4 address versus an IPv6 address. The config.vm.network directives are identical which suggests there may be no way to do this.

Alvaro Miranda Aguilera

unread,
May 10, 2016, 5:35:46 PM5/10/16
to vagra...@googlegroups.com
did you try them?

pixel fairy

unread,
May 11, 2016, 1:00:25 AM5/11/16
to Vagrant
Heres three examples.

the first one is all static. hostmanager only takes the first ip address, in this case the v4 one, which is why alice has to ping bob the second time by ip address. you could get around it by running a nameserver or your own script to populate /etc/hosts

# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION
= "2"

v4prefix
= "10.11.12."
v6prefix
= "fddd::"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config
.hostmanager.enabled = true
  config
.hostmanager.include_offline = true
  config
.vm.box = "ubuntu/trusty64"

  config
.vm.define "bob" do |bob|
    bob
.vm.hostname = "bob"
    bob
.vm.network "private_network", ip: v4prefix + "10"
    bob
.vm.network "private_network", ip: v6prefix + "10"
 
end

  config
.vm.define "alice" do |alice|
    alice
.vm.hostname = "alice"
    alice
.vm.network "private_network", ip: v4prefix + "11"
    alice
.vm.network "private_network", ip: v6prefix + "11"
    alice
.vm.provision "shell", inline: "ping -c 1 bob"
    alice
.vm.provision "shell", inline: "ping6 -c 1 #{v6prefix + "10"}"
 
end

end


This one routes v6 out miredo, good if your not on a v6 network, but want your vagrant network to go there. its technically NAT. but with v6 you dont need nat. which means, technically, this vagrant file does not exist ;) the static ip on client is just a dummy value.

# -*- mode: ruby -*-
# vi: set ft=ruby :

v4net
="192.168.45."
v6net
="fd12::"

router_script
= <<SCRIPT
sysctl
-w net.ipv6.conf.all.forwarding=1

mkdir
/etc/iptables
cat
<<EOF > /etc/iptables/rules.v6
*nat
-A POSTROUTING -o teredo -s #{v6net}/64 -j MASQUERADE
COMMIT
EOF

cat
<<EOF > /etc/radvd.conf
interface eth1
{
 
AdvSendAdvert on;
  prefix
#{v6net}/64
 
{
   
AdvOnLink on;
   
AdvAutonomous on;
 
};
};
EOF

apt
-get -y install miredo radvd
ip6tables
-restore < /etc/iptables/rules.v6
SCRIPT

client_script
= <<SCRIPT
cat
<<EOF > /etc/network/interfaces.d/eth1.cfg
auto eth1
iface eth1 inet manual
iface eth1 inet6
auto
EOF
ifup eth1
SCRIPT

VAGRANTFILE_API_VERSION
= "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config
.hostmanager.enabled = true
  config
.hostmanager.include_offline = true
  config
.vm.box = "ubuntu/trusty64"

  config
.vm.define "router" do |router|
    router
.vm.hostname = "router"
    router
.vm.network "private_network", ip: v6net + "10"
    router
.vm.provision "shell", inline: router_script
 
end

  config
.vm.define "client" do |client|
    client
.vm.hostname = "client"
    client
.vm.network "private_network", ip: v6net + "11", auto_config: false
    client
.vm.provision "shell", inline: client_script
 
end

end


if you want more of a v6 network to play on, https://gitlab.com/pixelfairy/oasix

Robert F

unread,
May 11, 2016, 1:38:53 PM5/11/16
to Vagrant
Thanks pixel fairy!  I'll give this a try.  Much appreciated!
Reply all
Reply to author
Forward
0 new messages