diff --git a/ReadMe.md b/ReadMe.md
index ab7cb0b..65eeea9 100755
--- a/ReadMe.md
+++ b/ReadMe.md
@@ -181,16 +181,16 @@ Download the matching version of the SmartDNS installation package. The correspo
1. Check if the service is configured successfully
- Query domain name with `nslookup -querytype=ptr 127.0.0.1`
+ Query domain name with `nslookup -querytype=ptr 0.0.0.0`
Check if the `name` item in the command result is displayed as `smartdns` or `hostname`, such as `smartdns`
```shell
- pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 127.0.0.1
+ pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
- 1.0.0.127.in-addr.arpa name = smartdns.
+ 0.0.0.0.in-addr.arpa name = smartdns.
```
### openwrt/LEDE
@@ -221,20 +221,20 @@ Download the matching version of the SmartDNS installation package. The correspo
* **Enable SmartDNS port 53 port redirection**
- Log in to the router, click on `Services`->`SmartDNS`, check the `Redirect` option to enable port 53 forwarding.
+ Log in to the router, click on `Services`->`SmartDNS`->`redirect`, select `Redirect 53 port to SmartDNS` option to enable port 53 forwarding.
* **Check if the service is configured successfully**
- Query domain name with `nslookup -querytype=ptr 127.0.0.1`
+ Query domain name with `nslookup -querytype=ptr 0.0.0.0`
See if the `name` item in the command result is displayed as `smartdns` or `hostname`, such as `smartdns`
```shell
- pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 127.0.0.1
+ pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
- 1.0.0.127.in-addr.arpa name = smartdns.
+ 0.0.0.0.in-addr.arpa name = smartdns.
```
* **The interface prompts that the redirect failed**
@@ -251,23 +251,25 @@ Download the matching version of the SmartDNS installation package. The correspo
1. Method 2: SmartDNS as upstream DNS Server of DNSMASQ
- * **Disable SmartDNS port 53 port redirection**
-
- Log in to the router, click on `Services`->`SmartDNS`, uncheck the `Redirect` option to disable port 53 forwarding.
-
* **Forward dnsmasq's request to SmartDNS**
- Log in to the router, click `Network`->`DHCP and DNS`, and modify `DNS forwardings` to:
-
- ```shell
- /#/127.0.0.1#5053
- ```
-
- Where `#5053` is the service port number of smartdns. If it is not modified, the default is 5053.
+ Log in to the router, click on `Services`->`SmartDNS`->`redirect`, select `Run as dnsmasq upstream server` option to forwarding dnsmasq request to Smartdns.
* **Check if the service is configured successfully**
- Use `nslookup` to query the `www.baidu.com` domain name to see if the IP address of Baidu in the result is `only one. If there are multiple IP addresses returned, it means that it is not valid. Please try to check several domain names.
+ * Method 1: Query domain name with `nslookup -querytype=ptr 0.0.0.1`
+ See if the `name` item in the command result is displayed as `smartdns` or `hostname`, such as `smartdns`
+
+ ```shell
+ pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0
+ Server: 192.168.1.1
+ Address: 192.168.1.1#53
+
+ Non-authoritative answer:
+ 0.0.0.0.in-addr.arpa name = smartdns.
+ ```
+
+ * Method 2: Use `nslookup` to query the `www.baidu.com` domain name to see if the IP address of Baidu in the result is `only one. If there are multiple IP addresses returned, it means that it is not valid. Please try to check several domain names.
```shell
pi@raspberrypi:~ $ nslookup www.baidu.com 192.168.1.1
@@ -319,16 +321,16 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
1. Restart router
- After the router is started, use `nslookup -querytype=ptr 127.0.0.1` to query the domain name.
+ After the router is started, use `nslookup -querytype=ptr 0.0.0.0` to query the domain name.
See if the `name` item in the command result is displayed as `smartdns` or `hostname`, such as `smartdns`
```shell
- pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 127.0.0.1
+ pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
- 1.0.0.127.in-addr.arpa name = smartdns.
+ 0.0.0.0.in-addr.arpa name = smartdns.
```
1. Note
@@ -381,6 +383,10 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
|log-file|log path|/var/log/smartdns.log|File Pah|log-file /var/log/smartdns.log
|log-size|log size|128K|number+K,M,G|log-size 128K
|log-num|archived log number|2|Integer|log-num 2
+|audit-enable|audit log enable|no|[yes\|no]|audit-enable yes
+|audit-file|audit log file|/var/log/smartdns-audit.log|File Path|audit-file /var/log/smartdns-audit.log
+|audit-size|audit log size|128K|number+K,M,G|audit-size 128K
+|audit-num|archived audit log number|2|Integer|audit-num 2
|conf-file|additional conf file|None|File path|conf-file /etc/smartdns/smartdns.more.conf
|server|Upstream UDP DNS server|None|[ip][:port], Repeatable| server 8.8.8.8:53
|server-tcp|Upstream TCP DNS server|None|[IP][:port], Repeatable| server-tcp 8.8.8.8:53
diff --git a/ReadMe_zh-CN.md b/ReadMe_zh-CN.md
index a8f3a23..c132e95 100644
--- a/ReadMe_zh-CN.md
+++ b/ReadMe_zh-CN.md
@@ -181,16 +181,16 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
1. 检测服务是否配置成功。
- 使用`nslookup -querytype=ptr 127.0.0.1`查询域名
+ 使用`nslookup -querytype=ptr 0.0.0.0`查询域名
看命令结果中的`name`项目是否显示为`smartdns`或`主机名`,如`smartdns`则表示生效
```shell
- pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 127.0.0.1
+ pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
- 1.0.0.127.in-addr.arpa name = smartdns.
+ 0.0.0.0.in-addr.arpa name = smartdns.
```
### openwrt/LEDE
@@ -221,20 +221,20 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
* **启用smartdns的53端口重定向**
- 登录路由器,点击`Services`->`SmartDNS`,勾选`Redirect`选项,启用53端口转发。
+ 登录路由器,点击`Services`->`SmartDNS`->`redirect`,选择`重定向53端口到SmartDNS`启用53端口转发。
* **检测转发服务是否配置成功**
- 使用`nslookup -querytype=ptr 127.0.0.1`查询域名
+ 使用`nslookup -querytype=ptr 0.0.0.0`查询域名
看命令结果中的`name`项目是否显示为`smartdns`或`主机名`,如`smartdns`则表示生效
```shell
- pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 127.0.0.1
+ pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
- 1.0.0.127.in-addr.arpa name = smartdns.
+ 0.0.0.0.in-addr.arpa name = smartdns.
```
* **界面提示重定向失败**
@@ -251,23 +251,25 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
1. 方法二:作为DNSMASQ的上游
- * **停用smartdns的53端口重定向**
-
- 登录路由器,点击`Services`->`SmartDNS`,去勾选`Redirect`选项,停用53端口转发。
-
* **将dnsmasq的请求发送到smartdns**
- 登录路由器,点击`Network`->`DHCP and DNS`,修改`DNS forwardings(DNS转发)`为:
-
- ```shell
- /#/127.0.0.1#5053
- ```
-
- 其中`#5053`为smartdns的服务端口号,未修改的情况下,默认为5053。
+ 登录路由器,点击`Services`->`SmartDNS`->`redirect`,选择`作为dnsmasq的上游服务器`设置dnsmasq的上游服务器为smartdns。
* **检测上游服务是否配置成功**
- 使用`nslookup`查询`www.baidu.com`域名,查看结果中百度的IP地址是否`只有一个`,如有多个IP地址返回,则表示未生效,请多尝试几个域名检查。
+ * 方法一:使用`nslookup -querytype=ptr 0.0.0.0`查询域名
+ 看命令结果中的`name`项目是否显示为`smartdns`或`主机名`,如`smartdns`则表示生效
+
+ ```shell
+ pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0
+ Server: 192.168.1.1
+ Address: 192.168.1.1#53
+
+ Non-authoritative answer:
+ 0.0.0.0.in-addr.arpa name = smartdns.
+ ```
+
+ * 方法二:使用`nslookup`查询`www.baidu.com`域名,查看结果中百度的IP地址是否`只有一个`,如有多个IP地址返回,则表示未生效,请多尝试几个域名检查。
```shell
pi@raspberrypi:~ $ nslookup www.baidu.com 192.168.1.1
@@ -319,16 +321,16 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
1. 重启路由器生效服务
- 待路由器启动后,使用`nslookup -querytype=ptr 127.0.0.1`查询域名
+ 待路由器启动后,使用`nslookup -querytype=ptr 0.0.0.0`查询域名
看命令结果中的`name`项目是否显示为`smartdns`或`主机名`,如`smartdns`则表示生效
```shell
- pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 127.0.0.1
+ pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
- 1.0.0.127.in-addr.arpa name = smartdns.
+ 0.0.0.0.in-addr.arpa name = smartdns.
```
1. 额外说明
@@ -381,6 +383,10 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
|log-file|日志文件路径|/var/log/smartdns.log|路径|log-file /var/log/smartdns.log
|log-size|日志大小|128K|数字+K,M,G|log-size 128K
|log-num|日志归档个数|2|数字|log-num 2
+|audit-enable|设置审计启用|no|[yes\|no]|audit-enable yes
+|audit-file|审计文件路径|/var/log/smartdns-audit.log|路径|audit-file /var/log/smartdns-audit.log
+|audit-size|审计大小|128K|数字+K,M,G|audit-size 128K
+|audit-num|审计归档个数|2|数字|audit-num 2
|conf-file|附加配置文件|无|文件路径|conf-file /etc/smartdns/smartdns.more.conf
|server|上游UDP DNS|无|[ip][:port],可重复| server 8.8.8.8:53
|server-tcp|上游TCP DNS|无|[IP][:port],可重复| server-tcp 8.8.8.8:53
diff --git a/package/luci/files/luci/controller/smartdns.lua b/package/luci/files/luci/controller/smartdns.lua
index 3d51462..c3f0e86 100644
--- a/package/luci/files/luci/controller/smartdns.lua
+++ b/package/luci/files/luci/controller/smartdns.lua
@@ -22,13 +22,24 @@ end
function act_status()
local e={}
local ipv6_server;
+ local redirect_mode="none";
+
e.ipv6_works = 2;
e.ipv4_works = 2;
e.ipv6_server = 1;
- e.redirect = smartdns.get_config_option("smartdns", "smartdns", "redirect", nil);
+ e.dnsmasq_forward = 0;
+ redirect_mode = smartdns.get_config_option("smartdns", "smartdns", "redirect", nil);
+ if redirect_mode == "redirect" then
+ e.redirect = 1
+ elseif redirect_mode == "dnsmasq-upstream" then
+ e.redirect = 2
+ else
+ e.redirect = 0
+ end
+
e.local_port = smartdns.get_config_option("smartdns", "smartdns", "port", nil);
ipv6_server = smartdns.get_config_option("smartdns", "smartdns", "ipv6_server", nil);
- if e.redirect == "1" then
+ if e.redirect == 1 then
if e.local_port ~= nil and e.local_port ~= "53" then
e.ipv4_works = luci.sys.call("iptables -t nat -nL PREROUTING 2>/dev/null | grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1" % e.local_port) == 0
if ipv6_server == "1" then
@@ -39,6 +50,15 @@ function act_status()
else
e.redirect = 0
end
+ elseif e.redirect == 2 then
+ local str;
+ local dnsmasq_server = luci.sys.exec("uci get dhcp.@dnsmasq[0].server")
+ if e.local_port ~= nil then
+ str = "127.0.0.1#" .. e.local_port
+ if string.sub(dnsmasq_server,1,string.len(str)) == str then
+ e.dnsmasq_forward = 1
+ end
+ end
end
e.running = is_running()
diff --git a/package/luci/files/luci/i18n/smartdns.zh-cn.po b/package/luci/files/luci/i18n/smartdns.zh-cn.po
index 1b6fe3f..3dc5234 100644
--- a/package/luci/files/luci/i18n/smartdns.zh-cn.po
+++ b/package/luci/files/luci/i18n/smartdns.zh-cn.po
@@ -40,6 +40,9 @@ msgstr "IPV4 53端口重定向失败"
msgid "IPV6 53 Port Redirect Failure"
msgstr "IPV6 53端口重定向失败"
+msgid "Dnsmasq Forwared To Smartdns Failure"
+msgstr "重定向dnsmasq到smartdns失败"
+
msgid "TCP Server"
msgstr "TCP服务器"
@@ -55,8 +58,14 @@ msgstr "启用IPV6服务器"
msgid "Redirect"
msgstr "重定向"
-msgid "Redirect standard dns query from 53 to smartdns, as default DNS server"
-msgstr "将53端口的DNS请求重定向到SmartDNS, 替换默认DNS服务"
+msgid "SmartDNS redirect mode"
+msgstr "SmartDNS 重定向模式"
+
+msgid "Run as dnsmasq upstream server"
+msgstr "作为dnsmasq的上游服务器"
+
+msgid "Redirect 53 port to SmartDNS"
+msgstr "重定向53端口到SmartDNS"
msgid "Cache Size"
msgstr "缓存大小"
diff --git a/package/luci/files/luci/model/cbi/smartdns.lua b/package/luci/files/luci/model/cbi/smartdns.lua
index cb21f16..77e1c99 100644
--- a/package/luci/files/luci/model/cbi/smartdns.lua
+++ b/package/luci/files/luci/model/cbi/smartdns.lua
@@ -31,8 +31,8 @@ o.rempty = false
---- Port
o = s:taboption("settings", Value, "port", translate("Local Port"), translate("Smartdns local server port"))
-o.placeholder = 5053
-o.default = 5053
+o.placeholder = 6053
+o.default = 6053
o.datatype = "port"
o.rempty = false
@@ -52,12 +52,14 @@ o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "1"
end
-o = s:taboption("settings", Flag, "redirect", translate("Redirect"), translate("Redirect standard dns query from 53 to smartdns, as default DNS server"))
-o.rmempty = false
-o.default = o.enabled
-o.cfgvalue = function(...)
- return Flag.cfgvalue(...) or "1"
-end
+---- Redirect
+o = s:taboption("settings", ListValue, "redirect", translate("Redirect"), translate("SmartDNS redirect mode"))
+o.placeholder = "none"
+o:value("none", translate("none"))
+o:value("dnsmasq-upstream", translate("Run as dnsmasq upstream server"))
+o:value("redirect", translate("Redirect 53 port to SmartDNS"))
+o.default = "none"
+o.rempty = false
---- cache-size
o = s:taboption("settings", Value, "cache_size", translate("Cache Size"), translate("DNS domain result cache size"))
@@ -93,7 +95,6 @@ function custom.write(self, section, value)
nixio.fs.writefile("/etc/smartdns/custom.conf", value)
end
-
-- Upstream servers
s = m:section(TypedSection, "server", translate("Upstream Servers"), translate("Upstream Servers, support UDP, TCP protocol. " ..
"Please configure multiple DNS servers, including multiple foreign DNS servers."))
diff --git a/package/luci/files/luci/view/smartdns/smartdns_status.htm b/package/luci/files/luci/view/smartdns/smartdns_status.htm
index b67e790..c56dc20 100644
--- a/package/luci/files/luci/view/smartdns/smartdns_status.htm
+++ b/package/luci/files/luci/view/smartdns/smartdns_status.htm
@@ -6,14 +6,20 @@ XHR.poll(3, '<%=luci.dispatcher.build_url("admin", "services", "smartdns", "stat
var links = "";
if (data.running) {
links = 'SmartDNS - <%:RUNNING%>';
- if (data.redirect && data.redirect == 1) {
- if (data.ipv4_works == 0) {
- links += "
<%:IPV4 53 Port Redirect Failure%>"
- }
-
- if (data.ipv6_works != 2) {
- if (data.ipv6_works == 0) {
- links += "
<%:IPV6 53 Port Redirect Failure%>"
+ if (data.redirect) {
+ if (data.redirect == 1) {
+ if (data.ipv4_works == 0) {
+ links += "
<%:IPV4 53 Port Redirect Failure%>"
+ }
+
+ if (data.ipv6_works != 2) {
+ if (data.ipv6_works == 0) {
+ links += "
<%:IPV6 53 Port Redirect Failure%>"
+ }
+ }
+ } else if (data.redirect == 2) {
+ if (data.dnsmasq_forward == 0) {
+ links += "
<%:Dnsmasq Forwared To Smartdns Failure%>"
}
}
}
diff --git a/package/openwrt/control/control b/package/openwrt/control/control
index 6928014..5aa8f48 100644
--- a/package/openwrt/control/control
+++ b/package/openwrt/control/control
@@ -3,6 +3,7 @@ Architecture:
Priority: optional
Section: net
Version:
+Depends: libc, libopenssl, libpthread
Maintainer: pymumu
Source: http://127.0.0.1/
Description: A smart dns server
diff --git a/package/openwrt/files/etc/init.d/smartdns b/package/openwrt/files/etc/init.d/smartdns
index 02cce70..b634a21 100644
--- a/package/openwrt/files/etc/init.d/smartdns
+++ b/package/openwrt/files/etc/init.d/smartdns
@@ -2,15 +2,39 @@
# Copyright (C) 2018 Nick Peng (pymumu@gmail.com)
START=99
+NAME=smartdns
SERVICE_USE_PID=1
SERVICE_WRITE_PID=1
SERVICE_DAEMONIZE=1
+SERVICE_PID_FILE="/var/run/smartdns.pid"
BASECONFIGFILE="/etc/smartdns/smartdns.conf"
SMARTDNS_CONF="/var/etc/smartdns.conf"
ADDRESS_CONF="/etc/smartdns/address.conf"
CUSTOM_CONF="/etc/smartdns/custom.conf"
SMARTDNS_CONF_TMP="${SMARTDNS_CONF}.tmp"
+set_forward_dnsmasq()
+{
+ SMARTDNS_PORT="$1"
+ addr="127.0.0.1#$SMARTDNS_PORT"
+ uci add_list dhcp.@dnsmasq[0].server=$addr
+ uci delete dhcp.@dnsmasq[0].resolvfile
+ uci set dhcp.@dnsmasq[0].noresolv=1
+ uci commit dhcp
+ /etc/init.d/dnsmasq restart
+}
+
+stop_forward_dnsmasq()
+{
+ SMARTDNS_PORT="$1"
+ addr="127.0.0.1#$SMARTDNS_PORT"
+ uci del_list dhcp.@dnsmasq[0].server=$addr 2>/dev/null
+ uci set dhcp.@dnsmasq[0].resolvfile=/tmp/resolv.conf.auto 2>/dev/null
+ uci delete dhcp.@dnsmasq[0].noresolv 2>/dev/null
+ uci commit dhcp
+ /etc/init.d/dnsmasq restart
+}
+
set_iptable()
{
local ipv6_server=$1
@@ -100,7 +124,7 @@ start_service() {
conf_append "server-name" "$server_name"
fi
- config_get "port" "$section" "port" "5053"
+ config_get "port" "$section" "port" "6053"
config_get "ipv6_server" "$section" "ipv6_server" "1"
config_get "tcp_server" "$section" "tcp_server" "1"
if [ "$ipv6_server" = "1" ]; then
@@ -160,10 +184,14 @@ start_service() {
conf_append "log-file" "$log_file"
fi
+ config_get "redirect" "$section" "redirect" "none"
+
clear_iptable
- config_get_bool "redirect" "$section" "redirect" '0'
- if [ "$redirect" -eq 1 ]; then
+ stop_forward_dnsmasq "$SMARTDNS_PORT"
+ if [ "$redirect" = "redirect" ]; then
set_iptable $ipv6_server
+ elif [ "$redirect" = "dnsmasq-upstream" ]; then
+ set_forward_dnsmasq "$SMARTDNS_PORT"
fi
config_foreach load_server "server"
diff --git a/package/openwrt/make.sh b/package/openwrt/make.sh
index 83200e4..79d134b 100644
--- a/package/openwrt/make.sh
+++ b/package/openwrt/make.sh
@@ -42,7 +42,7 @@ build()
sed -i "s/^Architecture.*/Architecture: $ARCH/g" $ROOT/control/control
sed -i "s/Version:.*/Version: $VER/" $ROOT/control/control
- sed -i "s/^\(bind .*\):53/\1:5053/g" $ROOT/root/etc/smartdns/smartdns.conf
+ sed -i "s/^\(bind .*\):53/\1:6053/g" $ROOT/root/etc/smartdns/smartdns.conf
if [ ! -z "$INST_SIZE" ]; then
echo "Installed-Size: $INST_SIZE" >> $ROOT/control/control
fi
diff --git a/src/conf.c b/src/conf.c
index 58fa0d4..02177e2 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -26,7 +26,7 @@ int dns_conf_log_level = TLOG_ERROR;
char dns_conf_log_file[DNS_MAX_PATH];
int dns_conf_log_size = 1024 * 1024;
int dns_conf_log_num = 8;
-int dns_conf_audit_enable;
+int dns_conf_audit_enable = 0;
char dns_conf_audit_file[DNS_MAX_PATH];
int dns_conf_audit_size = 1024 * 1024;
int dns_conf_audit_num = 2;
diff --git a/src/dns_server.c b/src/dns_server.c
index 0814a0b..a5722a8 100644
--- a/src/dns_server.c
+++ b/src/dns_server.c
@@ -929,6 +929,10 @@ static int _dns_server_process_ptr(struct dns_request *request, struct dns_packe
}
}
+ if (strstr(request->domain, "0.0.0.0") != NULL) {
+ found = 1;
+ }
+
if (found == 0) {
goto errout;
}