Home

Using Mikrotik? Make an mDNS repeater on your pi-hole

Original idea from chrisreinking.com (archive link), but slightly modified for an issue I was having. More on that in a bit.

Why would you do this?

Modern consumer networked devices like printers, speakers, and casting devices rely on mDNS aka Bonjour to allow other devices to easily find and use them. With a normal networking setup, this usually works great, until it doesn't.

On a bit more complex setup, where you start to include VLANs in the network and try to keep your smart home devices in a separate network, the difficulty ramps up. After all, you're trying to keep 'em separated, right? Well, you may not want those "smart" devices to be able to initiate communication with the rest of your home, but you'll likely want your phone, tablet, or laptop to be able to see them.

Some network equipment vendors, like Ubiquit, understand this as a consumer-level need and have built-in the ability to do it via a single checkbox. Others, like Mikrotik, don't, although it sounds like they may have seen the light and will eventually do it.

The setup

My home router is a Mikrotik RB5009UG+S+IN. It has a lot of power, and lot of complexity, and is an endless source of fun-to-me learning. It replaced my old Edgerouter X-SFP that I ran for years.

Find some hardware

I run pi-hole at home in order to help filter out unwanted network traffic and since it's a known system across my network and I've ensured all of my VLANs have access to it, I decided to include this functionality on it as well.

You may not prefer that, and that's okay! Any tiny Linux host will be more than capable. (Pi-hole runs on 2 cores and 1GB of memory for me, which even that is overkill)

Install avahi

On your host, install avahi. If you log in as root, leave off the sudo from the following commands.

$ sudo apt install avahi-daemon avahi-utils vlan

Depending on your host, use a different package management tool as necessary. This command installs avahi itself, some utilities for managing it, and vlan awareness.

Edit the avahi configuration

$ sudo nano /etc/avahi/avahi-daemon.conf

In the file, under the [reflector] heading, uncomment #enable-reflector=no and change it to yes. Save and exit your editor.

Add VLAN-specific virtual adapters

This sounds scary, but isn't really. For each VLAN that you know you want to reflect from and to, run the following command like I do for VLAN 10 below, and then turn on DHCP for the virtual adapter you just created:

$ sudo vconfig add eth0 10
$ sudo dhclient eth0.10

Repeat this for any additional VLANs you want to include.

Then make these adapter changes something that survives a reboot by editing /etc/network/interfaces and adding the following (again repeating for each VLAN):

auto eth0.10
iface eth0.10 inet dhcp

Test it out

Restart avahi to make sure the changes apply:

$ sudo service avahi-daemon restart

Test what it's seeing using the utilities we installed earlier:

$ sudo avahi-browse -a

This will sit and watch for new entries and then print them to your terminal.

If that's working, you should be good!

Oh yeah, that problem

An issue I experienced after getting this set up is that it aggressively cached entries in addition to repeating them across VLANs. This meant (thanks Apple) that my laptop would see itself when it broadcasted because I turned it back on and would rename itself because it thought the machine name was already in use.

To fix that issue, edit the avahi configuration again:

$ sudo nano /etc/avahi/avahi-daemon.conf

This time find and uncomment a line under the [server] section and change its value to 0:

cache-entries-max=0

Probable downside to that is that reflected values won't be cached so the device itself will need to rebroadcast before a new device sees it, upside is that all of your Apple devices won't constantly rename themselves.

Categories:

homelab mikrotik mdns pihole