The mystery of /etc/custom.list - can we have its functionality back please?

It seems that at some point, when upgrading to a new version, Pi-hole arranged to read /etc/pihole/custom.list, and move it into /etc/pihole/hosts. This file is now automatically updated if you fiddle with the web local domain interface. I presume that the intention is to provide an easy source for /etc/hosts. The local DNS names are now stored in /etc/pihole/pihole.toml, initially loaded when the custom.list file was moved, but which is now only changed by the web interface.

I now have about 40+ systems that I want to name and number on my local network, some are computers, some are WiFi routers for the local WiFi, some are Tapo plugs etc etc. I really don't want to have to type all these names one at a time into a web interface. When a name disappears, I don't want to have to remember to remove it.

I support my local network from a local authoritative DNS server assisted by DHCP, both running on my gateway machine. Pi-hole is only used as a blocking DNS that some machines see. When Pi-hole was new, I could extract the necessary information to make custom.list and load it into Pi-Hole. I’d like to be able to do that again.

So what I've done as a work-around is write a simple editor in Python that replaces the relevant part of the pihole.toml file with data from my DNS, which is the essentially the custom.list file. The editor takes a copy of /etc/pihole/pihole.toml, checks that a change is needed, and inserts the revised information in the appropriate place in the file. My editor follows the layout in pihole.toml, so a diff can be run to see what changes it has made before installation. After replacing /etc/pihole/pihole.toml, it seems that something notices, wakes up, reads it, and writes it back again. It incorporates the contents into the Pi-hole nameserver, and also updates /etc/pihole/hosts/custom.list. I presume this functionality assists the web interface.

Now, I would much rather have Pi-hole provide me a 'legit' way to do what custom.list did when Pi-hole was newish. I would like to suggest that one of the pihole or pihole-FTL commands is given a new option to replace the local DNS names from a list in a file putting back the ability to load Pi-hole local domains from a file.

Of course, I could be completely wrong, and there is a way to do what I want, I just haven't found it.

/etc/pihole/dnsmasq.conf includes: hostsdir=/etc/pihole/hosts

This means that every file in /etc/pihole/hosts will be read in host-style format.

The same behavior of custom.list can be achieved this way.

Just use /etc/pihole/hosts/yourhostfile (or any filename).

Pi-hole will pick up any file changes automatically(no need for a manual restart) and serve the records.

1 Like

pihole.toml is meant to be edited, and Pi-hole will monitor this file for changes to be picked up and applied immediately (see also Introducing Pi-hole v6).
But you are replacing the file with a copy, and Pi-hole may react to a change of file handles by applying its last known configuration.

Your script should work if you edit pihole.toml directly, instead of replacing it by a copy.

Alternatively, you could also replace the section via CLI, using the appropriate pihole-FTL --config , e.g.

sudo pihole-FTL --config dns.hosts '[ "192.168.0.21 laptop.lan", "192.168.0.22 smartphone.lan", "1.2.3.4 another" ]'

When adopting, take care of the correct ' and " placements.

darkexplosiveqwx's explanation is correct, and using a custom hosts file would also work.

The extra file in /etc/hosts has some problems for me. The names are not shown in the web interface because they are not added to pihole.toml. Names provided by files in /etc/hosts are not visible unless you use dns lookup tool with server set to localhost to see if the DNS understands the name. The names are not shown in the web interface.

Also, there is not enough information in file to tell the system to delete old names, or replace names that have changed their IP, or IPs that have changed names. Try creating a file with a local ip address with a name like fred.localdomain, wait a little, then use nslookup to see it. Now edit fred to jim. Jim will appear with the IP address, but fred is still there. I cannot see a way of getting rid of fred on my system without restarting things. This is just not reliable enough for automatic use.

Not sure about your qualms about editing /etc/pihole.toml, lsof doesn’t seem to say that it’s open. However, you are right that it might be creating problems because I am not obeying the backup policy, saving versions in /etc/pihole/config_backups.

However using the pihole-FTL cli seems the best solution, and thanks for that. I can also get the current values. I initially wondered about length of command lines, but that doesn’t seem to be a real problem, I’ll write something in python to avoid shell quoting problems.

Still seems to me that the real solution is to add something to pihole to read a file, replacing the functionality that was there before.

You have the option of just editing the file /etc/hosts on the Pi. That’s how I have always done it.

pi@Pi3BDev:~ $ nslookup printer

Server:		127.0.0.1

Address:	127.0.0.1#53

Name:	printer

Address: 192.168.0.4

Name:	printer

Address: ::

pi@Pi3BDev:~ $ nslookup 192.168.0.4

4.0.168.192.in-addr.arpa	name = printer.

pi@Pi3BDev:~ $ cat /etc/hosts | grep Printer

192.168.0.4	Printer

I am unhappy about trying to update /etc/hosts automatically, there are other things at stake if things go wrong. Anyway, I like to see the list of my local names in the web interface.

The solution of using –config works and is reasonably easy to achieve with Python.