Why are my two virtual machines getting the same IP address?

VirtualBox DHCP is working properly.

There is nothing wrong with having all of your machines getting the same address in NAT configuration. All VMs are isolated from each other so there is no risk of conflict. They are also not on the same adapter. Each VM has its own virtualized hardware including NICs.

The default gateway also need not to be 10.0.2.1. Although it is a common practice to have it at the lower IP address, it can be any IP in the subnet range.

Also, there is no "real" dhcp service, everything is hardcoded in the VirtualBox code, although if you are not happy with the default IP addresses you can fine tune the NAT engine.


In VirtualBox control panel go to File -> Preferences -> Network

Select NAT Networks tab, create a new "NatNetwork" by clicking + button at side and press OK.

Now select each VM go to Settings -> Network

In Attached to: option choose NAT Network and select "NatNetwork" and press OK.

Restart all the VMs.

Now VMs have different network address.


Your virtual machines will get the same IP address from any DHCP service as long as they have the same Ethernet MAC address (a hardware address, unique like a fingerprint, set by the hardware manufacturer of your network device).

Since you are running virtual machines, they have virtual hardware and therefore they "fake" the MAC address. You have to make sure no two machines have the same Ethernet hardware address.

You can set the Ethernet MAC address of your virtual machine in VirtualBox in the hardware network section (it looks like this: 3c:08:51:05:24:8a)

You can check it in your running VM:

sudo ifconfig

en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=2b<RXCSUM,TXCSUM,VLAN_HWTAGGING,TSO4>
    ether 3c:08:51:05:24:8a 
    media: autoselect (none)
    status: inactive