Setting a VM's mac address in Vagrant

后端 未结 5 996
不思量自难忘°
不思量自难忘° 2021-01-31 15:39

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?

相关标签:
5条回答
  • 2021-01-31 16:15

    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.

    0 讨论(0)
  • 2021-01-31 16:28

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

    0 讨论(0)
  • 2021-01-31 16:34

    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"
    
    0 讨论(0)
  • 2021-01-31 16:35

    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
    0 讨论(0)
  • 2021-01-31 16:37

    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"
    
    0 讨论(0)
提交回复
热议问题