Expected Behaviour:
Pi-hole v5.12.2 FTL Version: 5.18.1, Web Interface v5.15.1
Adding a local record to the pihole Local DNS Records page results in a green notification:
Custom DNS added
rasp.ap: 10.3.141.1
It is expected that the local machine and any clients connected to it will resolve the custom domain to the IP address added.
Actual Behaviour:
No custom DNS record is added to /etc/pihole/custom.list and the domain does not resolve with nslookup on the machine.
I have also added the rasp.ap domain to the /etc/hosts file after which, the domain will resolve on the console of the machine running pihole, but clients using pihole as the DNS server cannot resolve the local domain.
The pihole log shows:
Oct 8 12:15:18 dnsmasq[803]: query[A] rasp.ap from 192.168.4.101
Oct 8 12:15:18 dnsmasq[803]: forwarded rasp.ap to 1.1.1.1
Which indicates that local resolution is not taking place.
The lighttpd error-pihole.log contains the following error:
2022-10-08 12:16:30: (mod_fastcgi.c.421) FastCGI-stderr: PHP Warning: Executing sudo pihole -a addcustomdns 10.3.141.1 rasp.ap failed. in /var/www/html/admin/scripts/pi-hole/php/func.php on line 154
There is no further information on the cause of the failure.
The user:group for /var/www/html/admin/scripts/pi-hole/php/func.php (and for all parent directories) is root:root and permissions for that particular file is 644 which should be readable by everyone.
The function where the error occurs on line 154 is:
/**
* More safely execute a command with pihole shell script.
*
* For example,
*
* pihole_execute("-h");
*
* would execute command
*
* sudo pihole -h
*
* and returns output of that command as a string.
*
* @param $argument_string String of arguments to run pihole with
*/
function pihole_execute($argument_string)
{
$escaped = escapeshellcmd($argument_string);
$output = null;
$return_status = -1;
$command = 'sudo pihole '.$escaped;
exec($command, $output, $return_status);
if ($return_status !== 0) {
trigger_error("Executing {$command} failed.", E_USER_WARNING); // Line 154
}
return $output;
}
However, running the command as root from the console successfully adds the record as follows:
root@raspbx:/etc/pihole# pihole -a addcustomdns 10.3.141.1 rasp.ap
[✓] Adding custom DNS entry...
[✓] Restarting DNS server
Therefore the command appears to work when executed from the console as root, but not from php when invoked as sudo.
I have tried adding pihole and the lighttpd user (default is www-data) to the sudo group, but with no success. For now, the console command is a workaround for Local DNS, but this function pihole_execute()
will fail every time it is invoked.
I would be grateful for any suggestions as to why sudo does not work?