Skip to content

Commit

Permalink
luci: remove redirect feature and set as main dns server automaticall…
Browse files Browse the repository at this point in the history
…y when port is 53
  • Loading branch information
pymumu committed Aug 30, 2022
1 parent 7b3dcd3 commit e6d533e
Show file tree
Hide file tree
Showing 10 changed files with 1,083 additions and 1,165 deletions.
114 changes: 29 additions & 85 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,92 +258,29 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
*`Domain Address` 指定特定域名的 IP 地址,可用于广告屏蔽。

3. 启用服务

SmartDNS 服务生效方法有两种,一种是**直接作为主 DNS 服务**,另一种是**作为 DNSmasq 的上游**
默认情况下,SmartDNS 采用第一种方式。如下两种方式根据需求选择即可。

- **方法一:作为主 DNS 服务(默认方案)**

* 启用 SmartDNS 的 53 端口重定向

登录 OpenWrt 管理界面,点击 `Services` -> `SmartDNS` -> `redirect`,选择 `重定向 53 端口到 SmartDNS `启用 53 端口转发。

* 检测转发服务是否配置成功

执行

```shell
$ nslookup -querytype=ptr smartdns
```

查看命令结果中的 `name` 是否为 `smartdns` 或你的主机名,如果是则表示生效

```shell
$ nslookup -querytype=ptr smartdns
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
smartdns name = smartdns.
```

* 界面提示重定向失败

* 检查 `iptables` 和/或 `ip6tables` 命令是否正确安装。

* OpenWrt 15.01 系统不支持 IPv6 重定向,如网络需要支持 IPv6,请将 DNSmasq 上游改为 SmartDNS,或者将 SmartDNS 的端口改为53,并停用 DNSmasq。

* LEDE 系统请安装 IPv6 的 NAT 转发驱动。点击 `System` -> `Software`,点击 `Update lists` 更新软件列表后,安装 `ip6tables-mod-nat`

* 使用如下命令检查路由规则是否生效

```shell
iptables -t nat -L PREROUTING | grep REDIRECT
```

* 如转发功能不正常,请使用**方法二:作为 DNSmasq 的上游**

- **方法二:作为 DNSmasq 的上游**

* **将 DNSmasq 的请求发送到 SmartDNS**

登录 OpenWrt 管理界面,点击 `Services` -> `SmartDNS` -> `Redirect`,选择`作为 DNSmasq 的上游服务器`,设置 DNSmasq 的上游服务器为 SmartDNS。

* **检测上游服务是否配置成功**

执行

```shell
$ nslookup -querytype=ptr smartdns
```

查看命令结果中的 `name` 是否为 `smartdns` 或你的主机名,如果是则表示生效

```shell
$ nslookup -querytype=ptr smartdns
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
smartdns name = smartdns.
```

或执行

```shell
$ nslookup smartdns
```

查看命令结果是否有解析出路由器的IP地址,如果是则表示生效。

或执行

```shell
ping smartdns.
```

检测ping是否解析对应主机的IP地址。
* 替换默认Dndmasq为主DNS。

登录 OpenWrt 管理界面,点击 `Services` -> `SmartDNS` -> `port`,设置端口号为`53`,smartdns会自动接管主DNS服务器。

* 检测转发服务是否配置成功

执行

```shell
$ nslookup -querytype=ptr smartdns
```

查看命令结果中的 `name` 是否为 `smartdns` 或你的主机名,如果是则表示生效

```shell
$ nslookup -querytype=ptr smartdns
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
smartdns name = smartdns.
```

4. 启动服务

Expand All @@ -352,7 +289,14 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
5. **注意:**

* 如已经安装 ChinaDNS,建议将 ChinaDNS 的上游配置为 SmartDNS。
* SmartDNS 默认情况下将 53 端口的请求转发到 SmartDNS的 本地端口,此行为由 `Redirect` 配置选项控制。
* 当smartdns的端口为53时,将自动接管dnsmasq为主dns。配置其他端口时,会重新启用dnsmasq为主dns。
* 若在此过程中发生异常,可使用如下命令还原dnsmasq为主DNS

```shell
uci delete dhcp.@dnsmasq[0].port
uci commit dhcp
/etc/init.d/dnsmasq restart
```

### 华硕路由器原生固件 / 梅林固件

Expand Down
56 changes: 11 additions & 45 deletions ReadMe_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ https://github.com/pymumu/smartdns/releases
There are two ways to use the SmartDNS service, `one is directly as the primary DNS service`, `the other is as the upstream of dnsmasq`.
By default, SmartDNS uses the first method. You can choose according to your needs in the following two ways.

1. Method 1: SmartDNS as primary DNS Server (default scheme)
1. Method 1: SmartDNS as primary DNS Server

* **Enable SmartDNS port 53 port redirection**
* **Enable SmartDNS as primary DNS Server**

Log in to the router, click on `Services`->`SmartDNS`->`redirect`, select `Redirect 53 port to SmartDNS` option to enable port 53 forwarding.
Log in to the router, click on `Services`->`SmartDNS`->`port`, input port `53`, smartdns will run as primary DNS Server.

* **Check if the service is configured successfully**

Expand All @@ -260,54 +260,20 @@ https://github.com/pymumu/smartdns/releases
smartdns name = smartdns.
```

* **The interface prompts that the redirect failed**
* Check if iptable, ip6table command is installed correctly.
* The openwrt 15.01 system does not support IPV6 redirection. If the network needs to support IPV6, please change DNSMASQ upstream to smartdns, or change the smartdns port to 53, and disable dnsmasq.
* After LEDE system, please install IPV6 nat forwarding driver. Click `system`->`Software`, click `update lists` to update the software list, install `ip6tables-mod-nat`
* Use the following command to check whether the routing rule takes effect.
```shell
iptables -t nat -L PREROUTING | grep REDIRECT
```
* If the forwarding function is abnormal, please use Method 2: As the upstream of DNSMASQ.
1. Method 2: SmartDNS as upstream DNS Server of DNSMASQ
* **Forward dnsmasq's request to SmartDNS**
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**
* 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 smartdns
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
smartdns name = smartdns.
```
* or Query doman name `smartdns `with `nslookup smartdns`
```shell
$ nslookup smartdns
```
Check whether the command result resolves the IP address of the router, if so, it means it is working.
1. Start Service

Check the `Enable' in the configuration page to start SmartDNS server.
1. Note
* If chinaDNS is already installed, it is recommended to configure the upstream of chinaDNS as SmartDNS.
* SmartDNS defaults to forwarding port 53 requests to the local port of SmartDNS, controlled by the `Redirect` configuration option.
* When the port of smartdns is 53, it will automatically take over dnsmasq as the primary dns. When configuring other ports, dnsmasq is re-enabled as primary dns.
* If an exception occurs during this process, you can use the following command to restore dnsmasq as the primary DNS
```shell
uci delete dhcp.@dnsmasq[0].port
uci commit dhcp
/etc/init.d/dnsmasq restart
```
### ASUS router native firmware / Merlin firmware
Expand Down
40 changes: 0 additions & 40 deletions package/luci-compat/files/luci/controller/smartdns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,47 +37,7 @@ 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.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.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
e.ipv6_works = luci.sys.call("ip6tables -t nat -nL PREROUTING 2>/dev/null| grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1" % e.local_port) == 0
else
e.ipv6_works = 2
end
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()

luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
Loading

0 comments on commit e6d533e

Please sign in to comment.