I tried to build a group of Virtual machine in Virtualbox, and connect them with NAT network. The main information shows as below:
The Virtualbox version: 6.0.12
The Ubuntu guest version: ubuntu-18.04.2
The NAT network info: NetworkName: natnet22 IP: 192.168.13.1 Network: 192.168.13.0/24 IPv6 Enabled: No IPv6 Prefix: fd17:625c:f037:2::/64 DHCP Enabled: Yes Enabled: Yes loopback mappings (ipv4) 127.0.0.1=2When I finish creating an Ubuntu machine, the DHCP server maybe assign ip 192.168.13.4 for it. But when I cloned the machine and I change the mac address of the cloned one. The DHCP server still assign ip 192.168.13.4 for the cloned one.
Why the cloned Ubuntu one get the same ip with source? I need them have different ip in the NAT network to control them. Please help me solve the problem.
33 Answers
In newer Ubuntu versions, netplan is used for configuring the network. The file /etc/machine-id is used to create the DHCP identifier by default, rather than using the MAC address of the NIC.
When a Ubuntu system is cloned, the cloning process may change the MAC address of the NIC but it typically doesn't automatically change /etc/machine-id.
On your two systems, you can compare the contents of /etc/machine-id and they're probably the same.
You have two options:
Change the machine-id on at least one of the servers (huangjunpo's answer)
user@host:~$ cat /etc/machine-id d8dcd93cd8bffce0f7ed73875eb5be3a user@host:~$ sudo rm /etc/machine-id user@host:~$ sudo systemd-machine-id-setup Initializing machine ID from random generator. user@host:~$ cat /etc/machine-id 4b603489b08541ce9127791047081f46If using netplan, change the way netplan constructs the client identifer for DHCP to use the MAC address by adding
dhcp-identifier: macto your netplan config file in/etc/netplan. Add it under any interface you need to, and be careful of indentation in the yaml file. (see netplan.io - examples)user@host:~$ cat /etc/netplan/00-installer-config.yaml # This is the network config written by 'subiquity' network: ethernets: enp3s0: dhcp4: true dhcp-identifier: mac version: 2
After making this edit, you will have to apply it to make it have effect.
sudo netplan applyNote that /var/lib/dbus/machine-id is linked to /etc/machine-id.
user@host:~$ ls -l /var/lib/dbus/machine-id
lrwxrwxrwx 1 root root 15 May 8 20:30 /var/lib/dbus/machine-id -> /etc/machine-id Try the following commands on cloned vm:
sudo ip address flush scope global
sudo dhclient -v 1 Run below commands in bash shell. Use machine's id as identifier.
sudo rm /etc/machine-id
sudo systemd-machine-id-setup 2