The primary network interface of a Vagrant (VMware) machine typically obtains a dynamic IP address from the vmnet-dhcpd process bound to the vmnet8 network. In a multi-machine Vagrant environment, it is preferable to reserve a static IP address for this interface to simplify connectivity with the Mac host for automation purposes.

Prerequisites

Steps

  1. Quit the VMware Fusion application.

  2. Open your favorite terminal emulator.

  3. Generate a unique MAC address for the Vagrant machine primary network interface.

printf '00:0C:29:%02X:%02X:%02X\n' $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%256))

output:

00:0C:29:26:C5:EF
  1. Identify an available IP address from the vmnet8 virtual network.
grep -A16 subnet /Library/Preferences/VMware\ Fusion/vmnet8/dhcpd.conf

output:

subnet 172.16.239.0 netmask 255.255.255.0 {
        range 172.16.239.128 172.16.239.254;
        option broadcast-address 172.16.239.255;
        option domain-name-servers 172.16.239.2;
        option domain-name localdomain;
        default-lease-time 1800;                # default is 30 minutes
        max-lease-time 7200;                    # default is 2 hours
        option netbios-name-servers 172.16.239.2;
        option routers 172.16.239.2;
}
host vmnet8 {
        hardware ethernet 00:50:56:C0:00:08;
        fixed-address 172.16.239.1;
        option domain-name-servers 0.0.0.0;
        option domain-name "";
        option routers 0.0.0.0;
}
  • The range declaration has defined 128 to 254 for dynamic allocation.
  • Name servers and gateway use 2.
  • The VMnet adapter uses 1.

This leaves 3 to 127 for use within the /24 network. I select the 172.16.239.101 IP address for my example.

  1. Add the base_mac and base_address attributes to the machine definition in the Vagrantfile.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
Vagrant.configure('2') do |config|
  config.vm.box = 'bento/ubuntu-24.04'
  config.vm.box_check_update = false
  config.vm.hostname = 'ubuntu'
  config.ssh.insert_key = false
  config.vm.provider 'vmware_desktop' do |v|
    v.ssh_info_public = true
    v.allowlist_verified = 'disable_warning'
    v.vmx['numvcpus'] = '2'
    v.vmx['memsize'] = '2048'
    v.base_mac = '00:0C:29:26:C5:EF'
    v.base_address = '172.16.239.101'
  end
end
  1. Start the Vagrant machine.
vagrant up
  1. Verify the host declaration has been added to the dhcpd.conf file.
grep -A7 'host 172.16.239.101' /Library/Preferences/VMware\ Fusion/vmnet8/dhcpd.conf

output:

host 172.16.239.101 {
        hardware ethernet 00:0C:29:26:C5:EF;
        fixed-address 172.16.239.101;
        option domain-name-servers 172.16.239.2;
        option domain-name localdomain;
        option netbios-name-servers 172.16.239.2;
        option routers 172.16.239.2;
}
  1. Optionally, verify inside the Vagrant machine.
vagrant ssh

Get the MAC and IP address for the eth0 network interface.

for n in link addr; do ip -br ${n} sh eth0 | awk '{ print $3 }'; done

output:

00:0c:29:26:c5:ef
172.16.239.101/24