Setting up a web interface for DNSmasq with PHPDNS

Publish: 2018-07-10 | Modify: 2018-08-02

DNSmasq is a small and convenient tool for configuring DNS and DHCP. It is suitable for small networks and provides DNS functionality and optional DHCP functionality. With DNSmasq, it is easy to set up a recursive DNS (public DNS, such as 8.8.8.8), and it can be easily managed with PHPDNS.

DNSmasq

Requirements

  • CentOS 6/7
  • PHP 5.6+ (with PDO component support)
  • SQLite 3

Recursive DNS and Authoritative DNS

Well, someone asked me if this supports GEO functionality. Of course not, because these are features of authoritative DNS. DNSmasq belongs to recursive DNS, which is used for resolving on your local computer, just like Google's public DNS (8.8.8.8).

  • Authoritative DNS is built by domain name service providers and provides domain management services and maintains domain resolution records.
  • Recursive DNS is built by network operators and provides domain query resolution services.

For detailed explanations, please refer to the following links:

Advantages of Self-built DNS

  • Custom DNS resolution
  • Ad blocking
  • Prevent DNS hijacking

Running Principle Explanation

  1. When adding a host, PHPDNS generates a configuration file suitable for DNSmasq and saves it to the application/conf directory.

  2. After adding the configuration, DNSmasq needs to be restarted to take effect. But DNSmasq does not know that the administrator has added a host list. By using a simple shell script, the find command is used to detect whether the application/conf configuration file has been modified within 1 minute. If it has been modified, DNSmasq will be restarted to take effect, as shown in the following command.

#!/bin/bash
find /data/wwwroot/xxx.com/application/conf/ -name '*.conf' -mmin -1 -exec /usr/bin/systemctl restart dnsmasq.service {} \;
  1. Combined with crontab, the shell command is executed every minute to detect, ultimately achieving real-time effect of DNSmasq when the administrator adds a host. The advantage of this approach is that it does not require PHP to execute the backend shell, and it is relatively safer to let the server handle the subsequent work. However, the drawback is that it takes at least 1 minute to take effect after adding, but it is still acceptable. Currently, it is not possible to detect whether the DNSmasq configuration syntax generated by PHPDNS is correct. Once the administrator triggers a bug or adds some illegal hosts, DNSmasq may fail to run.

  2. About the principle of ad blocking: it is actually to point the ad domain name, such as ad.baidu.com, to 127.0.0.1, so that the ad cannot be loaded normally, thus achieving ad blocking. The advantage is that you don't need to install additional ad blocking plugins, and DNS can complete all these tasks.

Get the Donor Version

The donor version of PHPDNS has no difference in functionality. The donor version of PHPDNS can provide initial installation and debugging.

Donate

Help Documentation: https://doc.xiaoz.org/docs/phpdns/ Source Code: https://github.com/helloxz/phpdns


Comments