Problem Overview
When cloning virtual machines in Unraid, each cloned VM unexpectedly receives the same IP address from the Unifi Cloud Gateway (UCG) DHCP server. This occurs because the DHCP client identifier remains unchanged across clones, causing the DHCP server to treat all cloned VMs as the same client.
Step 1: Remove Existing DHCP Lease File
First, remove the existing DHCP lease file that contains the cached client identifier. This file stores information about previous DHCP transactions, including the client ID that's causing conflicts.
1sudo rm /var/lib/dhcp/dhclient.leasesWhat this does:
- Deletes the persistent DHCP lease information
- Forces the DHCP client to request a new lease with fresh parameters
- Clears any cached client identifiers from the previous VM instance
Alternative locations (depending on your Linux distribution):
1# For systems using dhcpcd2sudo rm /var/lib/dhcpcd/*.lease3
4# For NetworkManager-based systems5sudo rm /var/lib/NetworkManager/*.leaseStep 2: Configure Netplan to Use MAC Address Identification
Edit the netplan configuration file to explicitly use MAC address as the DHCP identifier:ntains a DHCP lease file with the original client identifier 2. The cloned VM inherits this same identifier 3. The Unifi Cloud Gateway DHCP server sees the identical client ID 4. The server assigns the same IP address to all clones, causing network conflicts
Configuration parameters explained:
dhcp-identifier: mac- Forces the DHCP client to use the network interface's MAC address as the unique identifier instead of the default client-id
The complete configuration should look like this:
The fix involves two steps:
- Remove the old DHCP lease file to clear cached identifiers
- Configure netplan to use MAC address identification so each clone gets a unique identifier
This ensures that each VM clone, with its unique MAC address, receives a distinct IP address from the DHCP server.
Important notes:
ens2is the network interface name (yours might be different, such aseth0,enp0s3, etc.)- Check your interface name with:
ip link show - The indentation must be exactly 2 spaces per level (YAML format)
Step 3: Apply Configuration and Test
After editing the netplan configuration, apply the changes:
1# Test the configuration syntax2sudo netplan try3
4# If successful, apply the changes5sudo netplan apply6
7# Verify the network configuration8ip addr show9
10# Check DHCP lease information11cat /var/lib/dhcp/dhclient.leasesStep 4: Prepare for Cloning
Shut down the VM cleanly:
1sudo shutdown -h nowNow you can clone this VM as many times as needed. Each clone will:
- Receive a new MAC address from Unraid
- Use that MAC address as its DHCP identifier
- Obtain a unique IP address from the Unifi Cloud Gateway
Verification After Cloning
On each new cloned VM, verify it received a unique IP:
1# Check assigned IP address2hostname -I3
4# Verify DHCP lease details5sudo cat /var/lib/dhcp/dhclient.leases | grep dhcp-server-identifier6
7# Check network connectivity8ping -c 4 8.8.8.8Additional Configuration Options
For Multiple Network Interfaces
If your VM has multiple network interfaces, configure each one:
1network:2 ethernets:3 ens2:4 dhcp4: true5 dhcp-identifier: mac6 ens3:7 dhcp4: true8 dhcp-identifier: mac9 version: 2Static Fallback Configuration
For production environments, you might want a static IP fallback if DHCP fails:
1network:2 ethernets:3 ens2:4 dhcp4: true5 dhcp-identifier: mac6 addresses:7 - 192.168.1.100/248 routes:9 - to: default10 via: 192.168.1.111 nameservers:12 addresses: [8.8.8.8, 1.1.1.1]13 version: 2IPv6 Support
If you're also using IPv6 with DHCP:
1network:2 ethernets:3 ens2:4 dhcp4: true5 dhcp6: true6 dhcp-identifier: mac7 version: 2Troubleshooting
Issue: Configuration not applying
1# Check netplan syntax errors2sudo netplan --debug apply3
4# View system logs for network errors5sudo journalctl -u systemd-networkd -fIssue: No IP address assigned
1# Restart the network service2sudo systemctl restart systemd-networkd3
4# Manually request DHCP lease5sudo dhclient -v ens2Issue: Wrong interface name
1# List all network interfaces2ip link show3
4# Check current netplan configuration5ls -la /etc/netplan/6cat /etc/netplan/*.yamlBest Practices
- Always test on one VM before mass cloning
- Document MAC addresses for each VM in your inventory
- Use DHCP reservations in Unifi for critical VMs to ensure consistent IPs
- Set meaningful hostnames for each clone to avoid confusion:
bash1sudo hostnamectl set-hostname vm-clone-01
- Consider cloud-init for automated VM provisioning in larger deployments
Understanding DHCP Client Identifiers
DHCP clients can identify themselves using different methods:
- MAC Address (hardware address): Unique per network interface, changes when cloned with new virtual NIC
- Client ID (duid): Often based on machine-id, remains the same when cloned
- Hostname: Less reliable, can have duplicates
By forcing dhcp-identifier: mac, we ensure each VM clone with a unique MAC address is treated as a distinct client by the Unifi DHCP server.
Related Unifi Configuration
In your Unifi Cloud Gateway, you can also:
- View DHCP leases: Network → Settings → DHCP → Active Leases
- Create static mappings: Assign fixed IPs based on MAC addresses
- Adjust lease time: Longer leases reduce renewal traffic, shorter leases free IPs faster
- Enable DHCP logging: Help → System Logs → Filter by "dhcp" sudo rm /var/lib/dhcp/dhclient.leases
add ID by mac address
```bash copy
sudo nano nano /etc/netplan/00-installer-config.yaml
dhcp-identifier: mac
this should be like this
1network:2 ethernets:3 ens2:4 dhcp4: true5 dhcp-identifier: mac6 version: 2Shut down. Clone as many as you want this VM. Now every clone of VM will have different IP address.