Automatically assign static IPs for certain hostnames



I often create virtual machines in my network.
They are automatically assigned hostnames like this: “preisschild-vserver-105”

Currently I need to assign it then manually in pihole to ip addresses like “” (where 105 is the id, like in the hostname).

Has anyone an idea how I could automatically do this?

It would be good if it would also overwrite an old record (if there is one), so when I delete a vserver and create a new with the same id, there shouldn’t be any problems.

If someone could point me in the right direction I think I should be able to write a bash-script.




Find the host that assigns these names.
If it runs a DNS service (nslookup preisschild-vserver-105 <IP_ADDRESS_HOST>), you can point your Pi-hole upstream custom DNS server setting to it:


In above case, select only one upstream DNS server or else it will break again.

Or use the “Conditional Forwarding” settings on the same settings page to forward names to any DNS host that knows bout those names.
If select this one, you can select any upstream DNS server to your liking.



Thanks for your answer.
I think I didn’t write it so good.

The hostnames are just assigned directly in the VMs ($ hostname preisschild-vserver-105).
PiHole detects those hostnames just fine. But they are using the automatically assigned IPs (from the pihole pool), but I would rather have them use IPs from a different range (e.g. 192.168.5.x in my case).

Since the hostnames already have that ID (like 105 in preisschild-vserver-105), I think I could automatically assign the proper IP ( in that case) with a shell script.

I don’t know where to start though.



This gets complicated very quickly and is a bit off topic for the help section.
As pihole-FTL is forked from the dnsmasq source code, you should check out tag 's on the dnsmasq man page and maybe the “-4, --dhcp-mac=set:<tag>,<MAC address>” directive can do something for you detecting which MAC addresses originate from your VM host and tag them:

EDIT: That is if you are using Pi-hole’s DHCP service!


closed #5

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