Uma maneira segura é fazer isso através do ssh. Crie um usuário específico do serviço ("dhcpkiller") e um par de chaves privada / pública para que o cliente possa executar este comando:
ssh dhcpkiller@dhcpserver pkill dnsmasq
Este script de uma linha é acionado pelo ambiente dhcp, que pode acontecer de várias maneiras, dependendo do pacote DHCP no cliente. Citando os manpages do dhclient / RHEL:
Immediately after dhclient brings an interface UP with a new IP address, subnet mask, and routes, in the REBOOT/BOUND states, it will check for the existence of an executable
/etc/dhcp/dhclient-up-hooks script, and source it if found. This script can handle DHCP options in the environment that are not handled by default.When dhclient needs to invoke the client configuration script, it defines a set of variables in the environment, and then invokes /sbin/dhclient-script. In all cases, $reason is set to the name of the reason why the script has been invoked. The following reasons are currently defined: MEDIUM, PREINIT, BOUND, RENEW, REBIND, REBOOT, EXPIRE, FAIL, STOP, RELEASE, NBI and TIMEOUT