Note

Quick note!

I have automated this process outlined in this blog post and documented all about it in a new post. Check it out below!

💡 Automated integration from Eero into Pihole

What I have

With the first post of the year, I thought I should start off with documenting an issue that I have been trying to resolve, which seems to come up quite a bit on the internet, but no fully documented solution for it.

Last year I switched over to fibre broad band (finally), and with it I received an Eero Pro 6. I was quite excited about this, as most other routers I had, whilst functionally were fine, just were a bit of a pain to manage. So with the Eero it was all managed via an app, and give you a good enough configuration and a good view of your network.

In addition to that I currently run PiHole on my home “server” (a synology device) that allows me to route and block any DNS traffic. This for the time being has been great.

The problem

The problem I was facing was that all my client names in PiHole all show up as IP addresses, which isn’t entirely useful if I want to quickly see what device is causing issues.

There are 3 documented solutions to this issue:

  1. Let PiHole manage the DHCP - This solution would essentially put the Eero into bridge mode, and I would loose all the cool functionality of the Eero. I wouldn’t be able to see devices on the app, block devices. The Eero just becomes really dumb, which rules out this option.
  2. Use Conditional Forwarding - Whilst this feature will fix the issue when working with most routers, the Eero for some reason just doesn’t support this option and any mention on support forums to resolve this has been ignored for the past 4 years. So this option is also ruled out.
  3. Maintain a list of hostnames - The final approach is more manual which request you to maintain a mapping of IP’s to Hostnames in the Hostnames file. Whilst this is a manual approach, it is the only one I hav available.

The (Hacky) Solution

The solution was obvious - update the host file manually. Surely there is a more automated way….

In fact there is! I managed to hook into the Eero API to retrieve a list of hostname and IP mappings, and put it in the correct format. Now all I need to do is to rerun the script whenever I need to update a name.

There are a few steps that needs to be followed which I have listed below.

1. Create a IP reservation for each client in Eero

This setting ensures that each device has a unique IP address which is always set for that device. E.g my server will always live on 192.168.1.200.

I have set up my own network so that DHCp is provided for the 2-99 range. And then the 100+ range is all allocated.

  • 100-109 - Laptops
  • 110-119 - Phones
  • 150-199 - IOT devices
  • etc

2. Name each device

I set each device up with a friendly network name. This is what is shown up in the Eero itself, but also what PiHole will map the IP address to.

3. Create the PiHole Config files

2 file are needed for this to work, and have been listed below.

File: /etc/dnsmasq.d/20-eero-home-config.conf

addn-hosts=/etc/pihole/custom-home.list

File: /etc/pihole/custom-home.list

# Blank for now

Both of these directories have been volume mapped into my docker containers, so this was as simple as creating the files in my local folders, which get mapped into the container.

4. Generate the host file

I use the script that I have created and linked in the appendix to generate the hostfile output from the Eero. It take the allocated IP and the hostname and constructs the output.

Update /etc/pihole/custom-home.list to look something like this

192.168.1.100 Personal-Laptop
192.168.1.110 Amish-Pixel-7
192.168.1.130 Amish-Firestick
# Snip Snip
192.168.1.157 Nest-Mini-Bedroom
192.168.1.200 vault
192.168.1.210 Mango-Repeater

5. Restart

Finally restart the PiHole or run the command pihole restartdns to see the update immediately!

Output

As you can see from the image below, this config now allows my PiHole to look something like this.

I am extremely happy with this quick approach. The next steps if one was so inclined would be to integrate this directly into PiHole itself, or have some other updating method. For now the 30 seconds this takes is fine for me.

Appendix - Python Script

The below python python script is a quick and dirty script which generate the host file.

# pip install eero

import eero

PHONE_NUMBER = "+44....."

class CookieStore(eero.SessionStorage):
    def __init__(self, cookie_file):
        from os import path
        self.cookie_file = path.abspath(cookie_file)

        try:
            with open(self.cookie_file, 'r') as f:
                self.__cookie = f.read()
        except IOError:
            self.__cookie = None

    @property
    def cookie(self):
        return self.__cookie

    @cookie.setter
    def cookie(self, cookie):
        self.__cookie = cookie
        with open(self.cookie_file, 'w+') as f:
            f.write(self.__cookie)

def get_host_list(session):
    network = eero_session.account()['networks']['data'][0]
    devices = eero_session.devices(network['url'])
    
    ip_device_list = sorted(
        [
            (
                list(map(int, x['ip'].split("."))),
                x['nickname']
            )
            for x in devices
        ],
        key=lambda y: y[0][3]
    )        
    
    return ip_device_list

# Setup
eero_session = eero.Eero(CookieStore('session.cookie'))

# Authenticate with Eero
if eero_session.needs_login():
    user_token = eero_session.login(PHONE_NUMBER)
    verification = input("Verificiation Code")
    eero_session.login_verify(verification, user_token)

# Get and construct the host list
for row in get_host_list(eero_session):
    SUBDICT = {"_":"-", "---":"-", "--":"-" } 
    
    ip = '.'.join(map(str, row[0]))
    hostname = row[1]
    for key in SUBDICT.keys():
        hostname = hostname.replace(key, SUBDICT[key])
        
    print(f"{ip} {hostname}")

# OUTPUT

# 192.168.1.100 Personal-Laptop
# 192.168.1.110 Amish-Pixel-7
# 192.168.1.130 Amish-Firestick
# .....
# 192.168.1.157 Nest-Mini-Bedroom
# 192.168.1.200 vault
# 192.168.1.210 Mango-Repeater