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.
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).
For detailed explanations, please refer to the following links:
When adding a host, PHPDNS generates a configuration file suitable for DNSmasq and saves it to the application/conf
directory.
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 {} \;
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.
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.
The donor version of PHPDNS has no difference in functionality. The donor version of PHPDNS can provide initial installation and debugging.
Help Documentation: https://doc.xiaoz.org/docs/phpdns/ Source Code: https://github.com/helloxz/phpdns
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.