1
votes

I'm trying to get vagrant to provision a VM with two network interfaces:

  • eth0: NAT(virtualbox) type interface that talks to DHCP
  • eth1: host-only(virtualbox) interface with a static IP

On virtualbox everything works. I get eth0 as a NAT type inteface that connects to the internet via DHCP and eth1 as a static IP with which I can connect to from the virtualbox host (I just need to add a private subnet to the virtualbox settings). However when I package this VM and try to deploy it as a box from vagrant I am unable to get eth1 to be brought up automatically as the MAC address gets changed by Vagrant (which means the static network configuration won't apply to it)

By default on vagrant the first adapter is always set as a NAT-ed interfance. This means I don't need to actually add anything in the vagrantfile for eth0.

For eth1 I've added the following in the Vagrantfile:

config.vm.network :private_network,ip:"192.168.100.201",:mac => "080027df863a", :adapter => 2

The problem: when I boot the vm (vagrant up) a new MAC is assigned for eth1. As a result the static IP mapping that I already have in /etc/sysconfig/network-scripts/ifcfg-eth1 is invalid (as it points to the MAC that was assigned when I create the VM in virtualbox).

If I delete the VM from virtualbox, repackage it and deploy a VM via vagrant with the same configuration the interface will get added but again the MAC address is different (and no initialization script will exist in /etc/sysconfig/network-scripts/)

TLDR: I want to create a vagrant box that has eth0 as a NAT-ed interface (DHCP) and eth1 as a static host-only interface (static IP). What's the best way to get it done as automated as possible? I don't want to have to be doing anything after the VM gets provision from the box.

Thanks

1
Try to put the config.vm.network instruction in a Vagrantfile and use the --vagrantfile option of the package command for adding it to the box.Emyl
That didn't work. After vagrant up I still get an eth2 (instead of eth1) with a different MAC than what I assigned in the vagrantfile.keftes

1 Answers

2
votes

The MAC address is being set by Virtualbox when it is first being brought up or provisioned. This means that you will most likely need to modify Virtualbox itself instead of the vm. Here are some links that might help:

http://docs.vagrantup.com/v2/virtualbox/configuration.html

http://www.virtualbox.org/manual/ch08.html

This is some code that might work also but I haven't actually tested it.

config.vm.provider :virtualbox do |vb|
    # Don't boot with headless mode
    #vb.gui = true

    # Use VBoxManage to customize the VM. For example to change memory:
    #vb.customize ["modifyvm", :id, "--memory", "1024"]

    # This might be an example of modifying the MAC address:
    vb.customize ["modifyvm", :id, "--macaddress2", "080027df863a"]
end

As far as I can tell this is what needs to be added to your Vagrantfile for the MAC address to be modified on vagrant up or vagrant reload --provision.

Most of the code above is default in a Vagrantfile but add this line to the Virtualbox provider line: vb.customize ["modifyvm", :id, "--macaddress2", "080027df863a"]