如何使用VMware Provisioner在Vagrant中设置eth0 MAC地址? [英] How to set eth0 MAC address in Vagrant with the VMware provisioner?

查看:295
本文介绍了如何使用VMware Provisioner在Vagrant中设置eth0 MAC地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Vagrant依靠VMware(Workstation和Fusion)在从机箱中部署的来宾上生成eth0(第一个也是默认的以太网接口)的MAC地址.

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.

我想修复此MAC地址,以便它是静态的,而不是在每次重新创建VM时都重新生成,以便VMware DHCP服务可以每次为其分配相同的IP地址.

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.

推荐答案

首先通过编辑vmnetdhcp.conf来确保VMware DHCP服务将IP地址分配给指定的MAC地址,该vmnetdhcp.conf具有不同的位置取决于操作系统.在文件末尾放置一个条目,将主机名,MAC和IP替换为所需的值:

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;
}

重新启动VMware DHCP服务以加载这些更改.

Restart the VMware DHCP service to load these changes.

Vagrantfile中,使用以下设置来配置默认网络接口:

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

虚拟机下次使用vagrant up启动时,它将分配静态MAC并从DHCP接收相同的IP地址.

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.

其他 vmx密钥也可以使用此方法为ethernet0进行操作

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

这篇关于如何使用VMware Provisioner在Vagrant中设置eth0 MAC地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆