Setting a VM's mac address in Vagrant

*爱你&永不变心* 提交于 2019-12-20 09:10:50

问题


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?


回答1:


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.




回答2:


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



回答3:


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 =)




回答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"



回答5:


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"


来源:https://stackoverflow.com/questions/12538162/setting-a-vms-mac-address-in-vagrant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!