Highest priority custom hostfile

The issue I am facing:
I'm using Pi-hole mainly for the ad-blocking.
I'd like to add a separate host-file that gets total priority over everything. So if the entry is in this specific hostfile, Pi-hole answers with this, and ignore all further checks.

I'll generate the file from a php script so if it needs to be in a specific format (ie. non standard hosts format) I can work that out.

TTL should be small as the file will be updated every hour.

Details about my system:
Fresh PiHole setup on simple Ubuntu VM, dedicated to Pi-hole.

The order of precedence for hosts files is:

  1. Configured in a config file in /etc/dnsmasq.d/
  2. Read from /etc/hosts
  3. Read from the list containing the device's host name and pi.hole (stored in /etc/pihole/local.list)
  4. Read from the "custom DNS" list (stored in /etc/pihole/custom.list)

Only the first record will trigger an address-to-name association.

1 Like

Thanks!

I ended up with adding /etc/dnsmasq.d/30-x.conf
After I generate the file I do service pihole-FTL restart
Seems to work as desired.

A follow up question....
if I define the same host in /etc/dnsmasq.d/30-x.conf and /etc/dnsmasq.d/40-x.conf with different IPs, which one will be used?

All of them. Hosts can have multiple IP addresses, e.g. for load balancing purposes. When multiple addresses are specified for a host, they will be rotated (round-robin).

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.