Why does Vagrant/Virtualbox assign the same MAC and IP address, and how to avoid

629 views
Skip to first unread message

Michael Ascenzi

unread,
Mar 1, 2022, 7:48:09 AM3/1/22
to Vagrant
Hello, 

I'm attempting to spin up multiple VM's utilizing Vagrant. However, no matter the number of VM's they all share the same MAC address and IP address. I need all VM's to be able to communicate with each other over sockets, and thus need to have unique IP's. 

I could assign them static addresses, which I'm doing temporarily as a short-term fix, but I need the DHCP to assign addresses for the VM's.

# -*- mode: ruby -*-
# vi: set ft=ruby :


$veh = 1
$vehCount = 2

$vehList ={}


while $veh <= $vehCount do
  $vehList["veh#{$veh}"] = "525400" + Array.new(6){[*"A".."F", *"0".."9"].sample}.join
  $veh+=1
end

Vagrant.configure("2") do |config|

  $vehList.each do |vehName, macADDR|

    $name = vehName
    $mac = macADDR

    config.vm.define vehName do |vmConfig|

      vmConfig.vm.box = "dcop"
      # dcop.vm.base_mac = nil
     
      vmConfig.vm.network "public_network", bridge: "eno1", :mac => macADDR
    end
  end
end

Through my reading, I've come across some saying its because its using the same MAC address, so i updated the Vagrantfile to generate a random MAC, and assigned it to the VM. But even with different MAC they are still assigning the same IP for each VM. 

Michael Ascenzi

unread,
Mar 1, 2022, 2:22:24 PM3/1/22
to Vagrant
Hello again. I've posted a queston on the Vagrant Community forum as well. The post actually has more details and steps that I've taken to try to resolve the issue. 

Reply all
Reply to author
Forward
0 new messages