Setup Pihole as home's DNS server on MacOS (M4 Mac Mini)
Background
The M4 Mac Mini is a new released product from Apple. The CPU is so powerful and the effeiceny is incredible. It’s a perfect dev machine to reduce the load for my current MBP, the last generation of Intel CPU. And meanwhile, it can replace my current tiny home server, an old Thinkpad T61 with Debian. It had been running for a few years and very stable. Pihole is one of the severice should be migrated.
What’s the goals
- Only use Pihole as DNS server, not the DHCP server.
- Pihole shoud show the devices’ local LAN ip.
- Pihole is managed by docker container.
Tl;dr
Don’t waste time to setup Pihole docker on MacOS, setup a Linux virtual machine on MacOS and run Pihole docker within Linux.
Why
Docker runtime doesn’t support macvlan
network config on MacOS. issue. Both of the Docker Desktop on Mac and colima won’t work. VirtualBox can use the Bridged Adapter
network on MacOS so the host machine will be assigned a dedicated LAN ip address and Pihole can use it on port 53.
Bridge Network
in Docker is more like the NAT Network
, Docker’s equivalent of VMWare or VirtualBox bridged network is macvlan
.
Failed Setup
Colima
Colima is a light weight container runtime and is running for AWS SAM and Postgres on my laptop. I set it with Portainer CE on Mac Mini.
We can use two network modes for Pihole:
- host mode
Pihole would use the Mac Mini’s network, so the ip address is same to Pihole and Mac Mini.
However, host
mode is not supported on MacOS. Even the Pihole can start up succesffuly, can’t ping Pihole from other devices.
Another issue you may encounter, the port 53
is occupied by mDnsResponder
process invoked by Apple. 53
is used for DNS query, so Pihole can’t get start up. issue
- Port Forwarding Mode
Pihole uses the colima’s network, it means there is a separated network for Pihole and colima.
Two possible issues. Pihole may fail with 53
is not assigned in start up. This issue can be solved with Pihole Docker guide. I spent a lot of time on this. Colima’s VM is Ubuntu.
Now Pihole starts up well, but it’s running in a different network and the devices in local LAN can’t ping it. It can only be accessed from Mac Mini using ip 192.168.65.x
. Use colima ssh
to login runtime, ip a
will show the network, Colima has two networks, one is 192.168.65.1/24
and bind with Mac Mini, another one is 172.xx.0.0/16
and bind with Pihole.
Docker Desktop
the host
network mode is a beta feature in Docker Desktop. However, like one of the above issues, the port 53
is occupied by mDnsResponder
process if Docker Destop running. Pihole doesn’t work.
Also tried macvlan
network mode, no luck. issue
Succeeded Setup
I ended up setting docker in a Linux virtual machine and running Pihole within docker. It’s VirtualBox + Ubuntu Server + Docker + Pihole.
Network setting for VM in VirtualBox
Have to follow Pihole Docker guide to release the port 53
in Ubuntu Server, also need a static local LAN ip address assigned by DHCP server (the router device).
Pihole compose file
Pihole uses the same network (host
mode) with the VM (Ubuntu Server). INTERFACE
tells Pihole the network interface assigned the static address. When use above Bridged Adapter
, VirtualBox creates a network interface for Ubuntu Server and the network interface will be assigned this static ip address.
VirtualBox headless and auto start up
It’s possible to setup VirtualBox running as headless and add in MacOS’s login items if you prefer to no manual start up on VM. Remeber, you also need to setup a user to login automatically if Mac Mini gets reboot by any cases.
Create below plist
file in ~/Library/LaunchAgents
, for example, the name is org.virtualbox.launch.UbuntuOnMac.plist
UbuntuOnMac
is the VM’s name created in VirtualBox. using CLI VBoxManage list vms
can list all VM names.
Updates
Created on 2024-11-25