Can Pi-hole's DHCP server send a notification when a client is requesting an IP?

Does this possibility already exist? every new ip request by the integrated dhcp display some notification, leave it registered in log.

Sorry my bad english. Inuse Google translate

Yes, you can either

  • add log-dhcp as an extra option to some files you create in /etc/dnsmasq.d/ to get any DHCP activity logged in /var/log/pihole/pihole.log, or
  • create a script (either using lua or bash) and specify it using dhcp-script=<scriptfile> or dhcp-luascript=<scriptfile>.
    This script will be called whenever a new DHCP lease is created, or an old one destroyed, or a TFTP file transfer completes.

You will find details about what is supported here: Man page of DNSMASQ - just search for the terms log-dhcp, dhcp-script or dhcp-luascript

As this is already possible but somewhat out-of-scope for Pi-hole, I will modify your request from a feature-request to a community-help-request.

Thanks, I already found the instructions on the MAN Page and I'm going to try to write the bash.

You would have to create a file in /etc/dnsmasq.d/ that will call your bash script that will notify

I use it like this:

dhcp-script=/etc/pihole/new_dhcp_device

This is in the file located in /etc/dnsmasq.d/

This config file passes the op, mac, ip and hostname parameter to the selected script.

You can then process them for notification purposes and store them in variables:

op="${1:-op}"
mac="${2:-mac}"
ip="${3:-ip}"
hostname="${4}"

This way you can pass them further into your chosen notification string.

Op will be “add” “del” “old”. Based on that the lease is assigned, deleted, renewed …

My implementation is a bit more hardcore as i have several automation triggers based on lease assignment but, my notifications look like this:

Enjoy poking at it. It’s really nice to know if/when something (new?) joins your network.

3 Likes

can you share with me your script? and how did you make these altomacoes?

Sharing is caring

Here you go:

Happy implementation.

2 Likes

Thank you for Sharing.
I am new to all this and am not sure what I do with the script.
Where do I save the Script on the RaspberryPI?
Does it need a specific name / naming format?

I am happy to log log in and review the logs occasionally to see all the Device names and IP addresses that were assigned. Is this logged to a log file? if yes, how do I access the file?
is there a way to capture the ipV6 address? TIA

See the post above:

I’m not using ipv6 in my LAN but i know it will capture the IPV6 too and I don’t recall it doing it (i was confusing my automations).

L.E. This does not store the leases assigned. Those are stored in a different file.
The script above only passes the lease information (one time, per transaction), to your notification channel of choice.

You can always review what IP was assigned to what hostname/MAC in the /admin interface under the Settings/DHCP.
In order for this to work though, Pi-Hole MUST BE the sole DHCP server in your network.

That's not quite the purpose of the script.
If you just need that, Currently active DHCP leases on Pi-hole's DHCP settings pane would provide that already.

It would likely not capture anything.
Pi-hole doesn't run a stateful DHCPv6 server (i.e it doesn't hand out DHCPv6 leases), as most modern OSs would join IPv6 networks via NDP/SLAAC anyway, rather then utilising stateless or stateful DHCPv6.
Some OSs (e.g. Android) do not even support DHCPv6 at all.

1 Like

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