How to set eth0 MAC address in Vagrant with the VMware provisioner?

自古美人都是妖i 提交于 2020-01-06 06:45:05

问题


Vagrant relies on VMware (Workstation and Fusion) to generate the MAC address of eth0 (the first and default ethernet interface) on a guest being deployed from a box.

I would like to fix this MAC address so it is static and not regenerated each time the VM is recreated so that the VMware DHCP service can assign it the same IP address each time.


回答1:


First make sure that the VMware DHCP service will assign an IP address to a specified MAC address by editing vmnetdhcp.conf which has different locations depending on OS. Place an entry at the end of the file replacing the hostname, MAC and IP with desired values:

host hostname {
    hardware ethernet 00:0A:AA:AA:AA:AA;
    fixed-address 192.168.1.1;
}

Restart the VMware DHCP service to load these changes.

In your Vagrantfile use the following settings to configure the default network interface:

Vagrant.configure("2") do |config|
    config.vm.define 'hostname' do |hostname|
        hotname.vm.box = box
        hostname.ssh.host = '192.168.1.1'
        puppet.vm.provider :vmware_fusion do |v, override|
            v.vmx['ethernet0.addressType'] = 'static'
            v.vmx['ethernet0.address'] = '00:0A:AA:AA:AA:AA'
       end
       puppet.vm.provider :vmware_workstation do |v, override|
            v.vmx['ethernet0.addressType'] = 'static'
            v.vmx['ethernet0.address'] = '00:0A:AA:AA:AA:AA'
        end
    end
end

Next time the virtual machine is brought up with vagrant up it will assigned the static MAC and recieve the same IP address from DHCP.

Other vmx keys could also be manipulated for ethernet0 using this method.



来源:https://stackoverflow.com/questions/26246840/how-to-set-eth0-mac-address-in-vagrant-with-the-vmware-provisioner

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