The documentation lists that the mac address of a VM can be set in the Vagrantfile, however everything I add seems to end up being a syntax error. Anyone successfully done this?
-
http://vagrantup.com/v1/docs/config/vm/network.html should also help! – Vishal Biyani Sep 25 '12 at 21:37
-
@VishalBiyani 404 – shashwat Nov 05 '18 at 09:00
5 Answers
I used this:
config.vm.network :bridged , :mac => "080027XXXXXX"
and got what I wanted.
The docs are unclear on what the syntax for the options hash were, and there seemed to be no example on what this should look like. So, here it is! Bridged with a mac address (edited of course). This brings up eth1 with the mac specified, which makes my DHCP server happy, and gives it a proper fqdn on my network.

- 88,222
- 31
- 159
- 162

- 1,264
- 1
- 10
- 12
-
2This works for a bridged network. However, the presumable equivalents for `:hostonly` network pass the syntax parser, but fail to change mac addresses (at least for VirtualBox anyway). `config.vm.network :hostonly, "192.168.33.10", mac: "5CA1AB1E0001"` `config.vm.network :hostonly, "192.168.33.10", :mac => "5CA1AB1E0001"` – Phil Apr 30 '14 at 18:53
-
1I got this error: `Network type 'bridged' is invalid. Please use a valid network type.` - Solved it with this insrtead: ` `config.vm.network "private_network", ip: "192.168.33.33", netmask: "255.255.255.0", mac: "080027e35dfe" ` - the mac has changed, but now I **cannot connect to the mashine anymore!** `SSH auth method: private key ` How can I reset the private key? – rubo77 Apr 01 '16 at 06:43
-
Have you tried reverting the MAC configuration you set above? If nothing else has changed and you are getting "SSH auth method: private key" that would imply that you aren't connecting to the same machine, which could be possible if you're setting the MAC to the same address as another machine on your network. – Benjamin Apr 01 '16 at 10:34
-
Note: VBoxManage will fail to set a mac address that doesn't match '[0-9A-Fa-f][02468ACEace][0-9A-Fa-f]{10}' with Invalid MAC address format – Lindenk Feb 22 '19 at 19:58
This is an old question, but I had the same issue just now. Vagrant documentation v2 still seems incomplete. In the end I used this line in the Vagrantfile with vagrant 1.2.7:
config.vm.network "public_network", :bridge => 'enp4s0', :mac => "5CA1AB1E0001"
This:
- sets the host interface named 'enp4s0' as the bridge interface,
- which as 'eth0' on the guest is then assigned an ip address by the same DHCP the host uses
- Also sets 5C:A1:AB:1E:00:01 as the guest's mac address

- 311
- 2
- 4
-
gmoney's answer gave me this error: "There are errors in the configuration of this machine. Please fix the following errors and try again: vm: * Network type 'bridged' is invalid. Please use a valid network type. " raddaqii's solution worked for me – Robert Fey Oct 28 '14 at 13:32
hmm, the network config didn't help in my case. After defining the MAC Address directly in the Vagrantfile via config.vm.base_mac = "MyEth0MacAddressWithoutSlashes"
my machine started =)

- 111
- 1
- 4
On Vagrant version 2.0.1, I write in the Vagrantfile for a private_network (provider = VirtualBox ; version 5.2.0) :
config.vm.network "private_network", ip: "X.X.X.X", mac: "080027xxxxxx"

- 1,908
- 2
- 18
- 36
The information provided below is outdated. As per documentation to allow IP to be assigned via DHCP simply use:
config.vm.network "public_network"
This way you don't need to deal with mac address, it will be generated on its own. If you need custom mac address attached to the network device then:
config.vm.network "public_network", :mac=> "080027xxxxxx"

- 3,377
- 3
- 20
- 28