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