3

I'm trying to set up a DHCP server using dnsmasq on Mac OS (Ventura) so that it can serve IP addresses to virtual machines that I am running.

I have included this line into my /opt/homebrew/etc/dnsmasq.conf:

dhcp-range=192.168.1.2,192.168.1.100,255.255.255.0,12h

and restarted the service using

sudo brew services restart dnsmasq

I have also disabled the built-in Mac OS DHCP server so that it does not interfere with dnsmasq:

sudo /bin/launchctl unload -w /System/Library/LaunchDaemons/bootps.plist

I'm running a Linux VM using QEMU, with the following network configuration:

-nic vmnet-shared,start-address=192.168.1.1,end-address=192.168.1.254,subnet-mask=255.255.255.0,mac=52:52:52:00:00:00

Unfortunately, the DHCP server is silent when I try to contact it from the VM:

$ sudo dhclient -v
Internet Systems Consortium DHCP Client 4.4.1
Copyright 2004-2018 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/enp0s1/52:52:52:00:00:00 Sending on LPF/enp0s1/52:52:52:00:00:00 Sending on Socket/fallback DHCPREQUEST for 192.168.1.4 on enp0s1 to 255.255.255.255 port 67 (xid=0x74f39476) DHCPREQUEST for 192.168.1.4 on enp0s1 to 255.255.255.255 port 67 (xid=0x74f39476)

It seems like there's nothing listening on the DHCP port (67) - the sudo lsof -i4UDP:67 lists nothing.

If I use the built-in Mac OS DHCP server, everything works fine. The VM is getting an IP address and the system shows that something is listening on DHCP port:

$ sudo lsof -i4UDP:67
COMMAND PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
launchd   1 root   14u  IPv4 0x6ff053dbd93d2625      0t0  UDP *:bootps
launchd   1 root   22u  IPv4 0x6ff053dbd93d2625      0t0  UDP *:bootps

How to make dnsmasq work as a DHCP server?

ghik
  • 181
  • 1
  • 7

1 Answers1

5

I found the cause.

dnsmasq binds both as a DHCP and DNS server, and I did not disable the DNS server (because I was planning to configure it later).

When I run the VM, Mac OS starts its own DNS, to serve the VM. If I try to start/restart dnsmasq after that point, it will fail to bind the DNS port and won't start. Unfortunately, I did not notice that because homebrew outright lies to me regarding the status of dnsmasq service, saying:

==> Successfully started `dnsmasq` (label: homebrew.mxcl.dnsmasq)

This is false. When I look at sudo brew services list (note: dnsmasq requires sudo), I see:

dnsmasq           error  512 root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

Also, there don't seem to be any logs from dnsmasq anywhere so I can't see what the problem is until I try to run dnsmasq manually:

sudo dnsmasq --no-daemon --log-queries

Only then I actually get some message that points me to the problem.

So, summarizing, I got royally confused mostly because of these two factors:

  • misleading homebrew messages
  • the situation depending on whether the VM is currently running or not
ghik
  • 181
  • 1
  • 7