# dnsmasq assigning same IP to 2 machines



## stratacast1 (Apr 24, 2021)

On FreeBSD 13.0 I have vm-bhyve set up to manage some virtual machines (in this case Ubuntu 20.04). It seems that for some reason dnsmasq is not doing a good job at dolling out IPs, as each time my machines end up getting the same IP. These are cloned VMs, have different IDs, and have different MAC addresses. Yet for some reason dnsmasq is still giving them both the same IP. I'm copying the example off of the vm-bhyve wiki, not sure if it's correct or not...here's my config


```
port=0
domain-needed
resolv-file=/usr/local/etc/dnsmasq-resolv.conf
except-interface=lo0
bind-interfaces
local-service
dhcp-authoritative

interface=vm-public
dhcp-range=172.16.10.5,172.16.10.100
```

I also have a nat rule in my pf.conf file for the network:


```
nat on $interface from <vmnets> to any -> ($interface)
```

I've tried releases and renews as well and it seems that CAN work sometimes, other times it will just get the IP back. Maybe holding onto a lease? However I've tried stopping/starting the service too to see if that would help since it should drop the lease table


----------



## OlivierW (Apr 25, 2021)

You said you cloned the VM. Did you first start a VM, got an IP address and then clone it? So, you probably a the DHCP lease file cloned too.
On each VM, check if you have file(s):
/var/db/dhclient.leases.*

Delete this file(s) and reboot the VMs (or restart dhclient): it will request a new IP and hopefully it will be the correct one 

PS: dnsmasq default lease time is 1 hour, so the problem may have solved by itself.


----------



## stratacast1 (Apr 27, 2021)

OlivierW said:


> You said you cloned the VM. Did you first start a VM, got an IP address and then clone it? So, you probably a the DHCP lease file cloned too.
> On each VM, check if you have file(s):
> /var/db/dhclient.leases.*
> 
> ...


Ooooh that very well could be the case. I am trying to find out what/where Ubuntu Server puts it, since that is the OS I am cloning right now. There is no /var/db/dhclient.leases file, and looking at the man pages I see it could be in /var/lib/dhcp, but even there I am not seeing the file. I believe that is my problem though, as you put it so I'm going to hunt for where Ubuntu puts this file. Thanks!


----------



## OlivierW (Apr 28, 2021)

I don't have any Ubuntu, but their man mention it should be in "/var/lib/dhcp/", like you said.
I have a Debian Buster VM and the leases file is in this directory.

You have a few ways to find the leases file, connected as root in your VM:

```
# ps aux | grep dhclient
root       363  0.0  0.2   9488  5628 ?        Ss   mars16   0:00 /sbin/dhclient -4 -v -i -pf /run/dhclient.enp0s5.pid -lf /var/lib/dhcp/dhclient.enp0s5.leases -I -df /var/lib/dhcp/dhclient6.enp0s5.leases enp0s5
root     14174  0.0  0.0   6092   888 pts/0    R+   09:47   0:00 grep dhclient
```


```
# lsof | grep leases
dhclient    363                             root    4w      REG                8,1      1250    3408002 /var/lib/dhcp/dhclient.enp0s5.leases
```

of course you can also use "find" to search on the whole HDD


----------

