From a707bf22fd4f426362c10fd4f2afae66e8bc4ebc Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Sun, 22 Jul 2018 19:16:24 +0800 Subject: [PATCH] Add ReadMe.md --- ReadMe.md | 106 ++++++--- ReadMe_zh-CN.md | 219 ++++++++++++++++++ etc/smartdns/smartdns.conf | 3 - .../luci/files/luci/model/cbi/smartdns.lua | 56 ++--- package/openwrt/address.conf | 3 + package/openwrt/files/etc/init.d/smartdns | 4 +- package/optware/make.sh | 1 + 7 files changed, 330 insertions(+), 62 deletions(-) create mode 100644 ReadMe_zh-CN.md diff --git a/ReadMe.md b/ReadMe.md index 14c73d0..c167ad2 100755 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,8 +1,11 @@ SmartDNS ============== + SmartDNS是一个运行在本地的DNS服务器,SmartDNS接受本地客户端的DNS查询请求,从多个上游DNS服务器获取DNS查询结果,并将访问速度最快的结果返回个客户端,避免DNS污染,提高网络访问速度。 同时支持指定特定域名IP地址,并高性匹配,达到过滤广告的效果。 +支持树莓派,openwrt,华硕路由器等设备。 + 特性 -------------- 1. **多DNS上游服务器** @@ -46,19 +49,27 @@ SmartDNS是一个运行在本地的DNS服务器,SmartDNS接受本地客户端 |系统 |安装包|说明 |-----|-----|----- -|标准Linux系统(树莓派)| smartdns.xxxxxxxx.armhf.deb|支持树莓派Raspbian stretch,Debian 9系统。 -|华硕原生固件|asusware.mipsbig.tar.gz|支持MIPS大端架构的系统,如RT-AC55U, RT-AC66U. -|openwrt 15.01|smartdns.xxxxxxxx.ar71xx.ipk|支持AR71XX MIPS系统 -|openwrt LEDE|smartdns.1.2xxxxxxxx.mips_24kc.ipk|支持AR71XX MIPS系统。 -|openwrt LEDE|smartdns.1.2xxxxxxxx.mipsel_24kc.ipk|支持 +|标准Linux系统(树莓派)| smartdns.xxxxxxxx.armhf.deb|支持树莓派Raspbian stretch,Debian 9系统。 +|华硕原生固件(optware)|smartdns.xxxxxxx.mipsbig.ipk|支持MIPS大端架构的系统,如RT-AC55U, RT-AC66U. +|华硕原生固件(optware)|smartdns.xxxxxxx.mipsel.ipk|支持MIPS小端架构的系统,如RT-AC68U。 +|openwrt 15.01|smartdns.xxxxxxxx.ar71xx.ipk|支持AR71XX MIPS系统。 +|openwrt 15.01|smartdns.xxxxxxxx.ramips.ipk|支持MT7620系统 +|openwrt LEDE|smartdns.2xxxxxxxx.mips_24kc.ipk|支持AR71XX MIPS系统。 +|openwrt LEDE|smartdns.xxxxxxxx.mipsel_24kc.ipk|支持 +|openwrt LUCI|luci-app-smartdns.xxxxxxxxx.xxxx.all.ipk|openwrt管理统一界面 + +[此处下载](https://github.com/pymumu/smartdns/releases) 标准Linux系统安装(树莓派) -------------- 1. 安装 +下载配套安装包`smartdns.xxxxxxxx.armhf.deb`,并上传到Linux系统中。 执行如下命令安装 ``` dpkg -i smartdns.xxxxxxxx.armhf.deb ``` 2. 修改配置 +安装完成后,可配置smartdns的上游服务器信息。具体配置参数参考`配置参数`说明。 +一般情况下,只需要增加`server [IP]:port`, `server-tcp [IP]:port`配置项 ``` vi /etc/smartdns/smartdns.conf ``` @@ -67,36 +78,79 @@ vi /etc/smartdns/smartdns.conf systemctl enable smartdns systemctl start smartdns ``` -4. 修改本地路由器DNS指向树莓派 +4. 将DNS请求转发的SmartDNS解析。 +修改本地路由器的DNS服务器,将DNS服务器配置为SmartDNS。 * 登录到本地网络的路由器中,配置树莓派分配静态IP地址。 * 修改WAN口或者DHCP DNS为树莓派IP地址。 注意: I. 每款路由器配置方法不尽相同,请百度搜索相关的配置方法。 II. 华为等路由器可能不支持配置DNS为本地IP,请修改PC端,手机端DNS服务器为树莓派IP。 +5. 检测服务是否配置成功。 +使用nslookup查询域名,看命令结果中的`服务器`项目是否显示为`Linux主机名`,如raspberry则表示生效 +``` +C:\Users\meikechong>nslookup www.baidu.com +服务器: raspberry +Address: 192.168.1.1 + +非权威应答: +名称: www.a.shifen.com +Address: 14.215.177.39 +Aliases: www.baidu.com +``` openwrt/LEDE -------------- -1. 安装 +1. 安装 将软件使用winscp上传到路由器的/root目录,执行如下命令安装 ``` opkg install smartdns.xxxxxxxx.xxxx.ipk +opkg install luci-app-smartdns.xxxxxxxx.xxxx.all.ipk ``` -2. 修改配置 -``` -vi /etc/smartdns/smartdns.conf -``` -3. 启动服务 -``` +2. 修改配置 +登陆openwrt管理页面,打开Services->SmartDNS进行配置。 +* 在Upstream Servers增加上游DNS服务器配置。 +* 在Domain Address指定特定域名的IP地址,可用于广告屏蔽。 + +3. 启动服务 +勾选配置页面中的`Enable(启用)`来启动SmartDNS -``` 华硕路由器原生固件 -------------- +1. 准备 在使用此软件时,需要确认路由器是否支持U盘,并准备好U盘一个。 -1. 解压安装包到U盘根目录,其目录格式如下。(此处仅列出smartdns相关文件) +1. 启用SSH登录 +登录管理界面,点击`系统管理`->点击`系统设置`,配置`Enable SSH`为`Lan Only`。 +SSH登录用户名密码与管理界面相同。 + +2. 下载`Download Master` +在管理界面点击`USB相关应用`->点击`Download Master`下载。 +下载完成后,启用`Download Master`,如果不需要下载功能,此处可以卸载`Download Master`,但要保证卸载前Download Master是启用的。 + +3. 安装SmartDNS +将软件使用winscp上传到路由器的`/tmp/mnt/sda1`目录。(或网上邻居复制到sda1共享目录) +``` +ipkg install smartdns.xxxxxxx.mipsbig.ipk +``` + +4. 重启路由器生效服务 +待路由器启动后,使用nslookup查询域名,看命令结果中的`服务器`项目是否显示为`smartdns`,如显示smartdns则表示生效 +``` +C:\Users\meikechong>nslookup www.baidu.com +服务器: smartdns +Address: 192.168.1.1 + +非权威应答: +名称: www.a.shifen.com +Address: 14.215.177.39 +Aliases: www.baidu.com +``` +5. 额外说明 +上述过程,smartdns将安装到U盘根目录,采用optware的模式运行。 +其目录结构如下: (此处仅列出smartdns相关文件) ``` U盘 └── asusware.mipsbig @@ -113,24 +167,14 @@ U盘 | └── smartdns .... ``` -2. 修改配置 +如要修改配置,可以ssh登录路由器,使用vi命令修改 ``` -vi asusware.mipsbig/etc/smartdns/smartdns.conf +vi /opt/etc/smartdns/smartdns.conf ``` -3. 启动服务 -将U盘插入路由器后方USB插口,并重启路由器。 -4. 检测DNS服务是否生效 -待路由器启动后,使用nslookup查询域名,看命令结果中的`服务器`项目是否显示为`smartdns`,如显示smartdns则表示生效 +也可以通过网上邻居修改,网上邻居共享目录`sda1`看不到`asusware.mipsbig`目录,但可以直接在`文件管理器`中输入`asusware.mipsbig\etc\init.d`访问。 ``` -C:\Users\meikechong>nslookup www.baidu.com -服务器: smartdns -Address: 192.168.1.1 - -非权威应答: -名称: www.a.shifen.com -Address: 14.215.177.39 -Aliases: www.baidu.com +\\192.168.1.1\sda1\asusware.mipsbig\etc\init.d ``` 配置参数 @@ -151,8 +195,10 @@ Aliases: www.baidu.com |server-tcp|上游TCP DNS|无|[IP][:port],可重复| server-tcp 8.8.8.8:53 |address|指定域名IP地址|无|address /domain/ip| address /www.example.com/1.2.3.4 -捐助 +[捐助](#donate) ============== +* PayPal +[![Support via PayPal](https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg)](https://paypal.me/PengNick/) * Alipay 支付宝 ![alipay](doc/alipay_donate.jpg) diff --git a/ReadMe_zh-CN.md b/ReadMe_zh-CN.md new file mode 100644 index 0000000..72463a9 --- /dev/null +++ b/ReadMe_zh-CN.md @@ -0,0 +1,219 @@ +SmartDNS +============== +SmartDNS是一个运行在本地的DNS服务器,SmartDNS接受本地客户端的DNS查询请求,从多个上游DNS服务器获取DNS查询结果,并将访问速度最快的结果返回个客户端,避免DNS污染,提高网络访问速度。 +同时支持指定特定域名IP地址,并高性匹配,达到过滤广告的效果。 + +支持树莓派,openwrt,华硕路由器等设备。 + +特性 +-------------- +1. **多DNS上游服务器** + 支持配置多个上游DNS服务器,并同时进行查询,即使其中有DNS服务器异常,也不会影响查询。 + +1. **返回最快IP地址** + 支持从域名所属IP地址列表中查找到访问速度最快的IP地址,并返回给客户端,避免DNS污染,提高网络访问速度。 + +1. **支持非标准端口** + 支持非53端口查询,支持TCP查询,有效避免DNS污染。 + +1. **特定域名IP地址指定** + 支持指定域名的IP地址,达到广告过滤效果,避免恶意网站的效果。 + +1. **域名高性能后缀匹配** + 支持域名后缀匹配模式,简化过滤配置,过滤20万条记录时间<1ms + +1. **Linux多平台支持** + 支持标准Linux系统(树莓派),openwrt系统各种固件,华硕路由器原生固件。 + +1. **支持IPV4, IPV6双栈** + 支持IPV4,IPV6网络,支持查询A, AAAA记录。 + +1. **高性能,占用资源少** + 多线程异步IO模式,cache缓存查询结果。 + +架构 +------------- +![Architecture](doc/architecture.png) +1. SmartDNS接收本地网络设备的DNS查询请求,如PC,手机的查询请求。 +2. SmartDNS将查询请求发送到多个上游DNS服务器,可采用标准UDP查询,非标准端口UDP查询,及TCP查询。 +3. 上游DNS服务器返回域名对应的Server IP地址列表。SmartDNS检测与本地网络访问速度最快的Server IP。 +4. 将访问速度最快的Server IP返回给本地客户端。 + + +使用 +============== +下载配套安装包 +-------------- +下载配套版本的SmartDNS安装包,对应安装包配套关系如下。 + +|系统 |安装包|说明 +|-----|-----|----- +|标准Linux系统(树莓派)| smartdns.xxxxxxxx.armhf.deb|支持树莓派Raspbian stretch,Debian 9系统。 +|华硕原生固件(optware)|smartdns.xxxxxxx.mipsbig.ipk|支持MIPS大端架构的系统,如RT-AC55U, RT-AC66U. +|华硕原生固件(optware)|smartdns.xxxxxxx.mipsel.ipk|支持MIPS小端架构的系统,如RT-AC68U。 +|openwrt 15.01|smartdns.xxxxxxxx.ar71xx.ipk|支持AR71XX MIPS系统。 +|openwrt 15.01|smartdns.xxxxxxxx.ramips.ipk|支持MT7620系统 +|openwrt LEDE|smartdns.2xxxxxxxx.mips_24kc.ipk|支持AR71XX MIPS系统。 +|openwrt LEDE|smartdns.xxxxxxxx.mipsel_24kc.ipk|支持 +|openwrt LUCI|luci-app-smartdns.xxxxxxxxx.xxxx.all.ipk|openwrt管理统一界面 + +[此处下载](https://github.com/pymumu/smartdns/releases) + +标准Linux系统安装(树莓派) +-------------- +1. 安装 +下载配套安装包`smartdns.xxxxxxxx.armhf.deb`,并上传到Linux系统中。 执行如下命令安装 +``` +dpkg -i smartdns.xxxxxxxx.armhf.deb +``` +2. 修改配置 +安装完成后,可配置smartdns的上游服务器信息。具体配置参数参考`配置参数`说明。 +一般情况下,只需要增加`server [IP]:port`, `server-tcp [IP]:port`配置项 +``` +vi /etc/smartdns/smartdns.conf +``` +3. 启动服务 +``` +systemctl enable smartdns +systemctl start smartdns +``` +4. 将DNS请求转发的SmartDNS解析。 +修改本地路由器的DNS服务器,将DNS服务器配置为SmartDNS。 +* 登录到本地网络的路由器中,配置树莓派分配静态IP地址。 +* 修改WAN口或者DHCP DNS为树莓派IP地址。 + 注意: + I. 每款路由器配置方法不尽相同,请百度搜索相关的配置方法。 + II. 华为等路由器可能不支持配置DNS为本地IP,请修改PC端,手机端DNS服务器为树莓派IP。 + +5. 检测服务是否配置成功。 +使用nslookup查询域名,看命令结果中的`服务器`项目是否显示为`Linux主机名`,如raspberry则表示生效 +``` +C:\Users\meikechong>nslookup www.baidu.com +服务器: raspberry +Address: 192.168.1.1 + +非权威应答: +名称: www.a.shifen.com +Address: 14.215.177.39 +Aliases: www.baidu.com +``` + +openwrt/LEDE +-------------- +1. 安装 +将软件使用winscp上传到路由器的/root目录,执行如下命令安装 +``` +opkg install smartdns.xxxxxxxx.xxxx.ipk +opkg install luci-app-smartdns.xxxxxxxx.xxxx.all.ipk +``` + +2. 修改配置 +登陆openwrt管理页面,打开Services->SmartDNS进行配置。 +* 在Upstream Servers增加上游DNS服务器配置。 +* 在Domain Address指定特定域名的IP地址,可用于广告屏蔽。 + +3. 启动服务 +勾选配置页面中的`Enable(启用)`来启动SmartDNS + + +华硕路由器原生固件 +-------------- +1. 准备 +在使用此软件时,需要确认路由器是否支持U盘,并准备好U盘一个。 + +1. 启用SSH登录 +登录管理界面,点击`系统管理`->点击`系统设置`,配置`Enable SSH`为`Lan Only`。 +SSH登录用户名密码与管理界面相同。 + +2. 下载`Download Master` +在管理界面点击`USB相关应用`->点击`Download Master`下载。 +下载完成后,启用`Download Master`,如果不需要下载功能,此处可以卸载`Download Master`,但要保证卸载前Download Master是启用的。 + +3. 安装SmartDNS +将软件使用winscp上传到路由器的`/tmp/mnt/sda1`目录。(或网上邻居复制到sda1共享目录) +``` +ipkg install smartdns.xxxxxxx.mipsbig.ipk +``` + +4. 重启路由器生效服务 +待路由器启动后,使用nslookup查询域名,看命令结果中的`服务器`项目是否显示为`smartdns`,如显示smartdns则表示生效 +``` +C:\Users\meikechong>nslookup www.baidu.com +服务器: smartdns +Address: 192.168.1.1 + +非权威应答: +名称: www.a.shifen.com +Address: 14.215.177.39 +Aliases: www.baidu.com +``` +5. 额外说明 +上述过程,smartdns将安装到U盘根目录,采用optware的模式运行。 +其目录结构如下: (此处仅列出smartdns相关文件) +``` +U盘 + └── asusware.mipsbig + ├── bin + ├── etc + | ├── smartdns + | | └── smartdns.conf + | └── init.d + | └── S50smartdns + ├── lib + ├── sbin + ├── usr + | └── sbin + | └── smartdns + .... +``` +如要修改配置,可以ssh登录路由器,使用vi命令修改 +``` +vi /opt/etc/smartdns/smartdns.conf +``` + +也可以通过网上邻居修改,网上邻居共享目录`sda1`看不到`asusware.mipsbig`目录,但可以直接在`文件管理器`中输入`asusware.mipsbig\etc\init.d`访问。 +``` +\\192.168.1.1\sda1\asusware.mipsbig\etc\init.d +``` + +配置参数 +============== +|参数|功能|默认值|配置值|例子| +|--|--|--|--|--| +|server-name|DNS服务器名称|操作系统主机名/smartdns|符合主机名规格的字符串|server-name smartdns +|bind|DNS监听端口号|[::]:53|IP:PORT|bind 192.168.1.1:53 +|cache-size|域名结果缓存个数|512|数字|cache-size 512 +|rr-ttl|域名结果TTL|远程查询结果|大于0的数字|rr-ttl 600 +|rr-ttl-min|允许的最小TTL值|远程查询结果|大于0的数字|rr-ttl-min 60 +|rr-ttl-max|允许的最大TTL值|远程查询结果|大于0的数组|rr-ttl-max 600 +|log-level|设置日志级别|error|error,warn,info,debug|log-level error +|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 +|server|上游UDP DNS|114.114.114.114|[ip][:port],可重复| server 8.8.8.8:53 +|server-tcp|上游TCP DNS|无|[IP][:port],可重复| server-tcp 8.8.8.8:53 +|address|指定域名IP地址|无|address /domain/ip| address /www.example.com/1.2.3.4 + +[捐助](#donate) +============== +* PayPal +[![Support via PayPal](https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg)](https://paypal.me/PengNick/) + +* Alipay 支付宝 +![alipay](doc/alipay_donate.jpg) + +* Wechat 微信 +![wechat](doc/wechat_donate.jpg) + +说明 +============== +目前代码未开源,后续根据情况开源。 + + + + + + + + + diff --git a/etc/smartdns/smartdns.conf b/etc/smartdns/smartdns.conf index f917418..e475bb1 100644 --- a/etc/smartdns/smartdns.conf +++ b/etc/smartdns/smartdns.conf @@ -49,9 +49,6 @@ server 119.29.29.29 # alibaba dns server 223.5.5.5 -#OpenDNS -server 208.67.222.222:5353 - #LUG server 202.141.178.13:5353 server 202.141.162.123:53 diff --git a/package/luci/files/luci/model/cbi/smartdns.lua b/package/luci/files/luci/model/cbi/smartdns.lua index 1ce4438..c162567 100644 --- a/package/luci/files/luci/model/cbi/smartdns.lua +++ b/package/luci/files/luci/model/cbi/smartdns.lua @@ -13,59 +13,40 @@ else end -- Basic -s = m:section(TypedSection, "smartdns", translate("SmartDNS Server")) +s = m:section(TypedSection, "smartdns", translate("Settings"), translate("General Settings")) s.anonymous = true -s:tab("settings", translate("Settings")) -s:tab("help", translate("Technical Support")) - ---- Eanble -o = s:taboption("settings", Flag, "enabled", translate("Enable"), translate("Enable or disable smartdns server")) +o = s:option(Flag, "enabled", translate("Enable"), translate("Enable or disable smartdns server")) o.rempty = false ---- Port -o = s:taboption("settings", Value, "port", translate("Local Port"), translate("Smartdns local server port")) +o = s:option(Value, "port", translate("Local Port"), translate("Smartdns local server port")) o.placeholder = 5353 o.default = 5353 o.datatype = "port" o.rempty = false -o = s:taboption("settings", Flag, "redirect", translate("redirect"), translate("redirect standard dns query from 53 to smartdns")) +o = s:option(Flag, "redirect", translate("redirect"), translate("redirect standard dns query from 53 to smartdns")) o.default = true o.rempty = false ---- cache-size -o = s:taboption("settings", Value, "cache_size", translate("Cache Size"), translate("DNS domain result cache size")) +o = s:option(Value, "cache_size", translate("Cache Size"), translate("DNS domain result cache size")) o.rempty = true ---- rr-ttl -o = s:taboption("settings", Value, "rr_ttl", translate("Domain TTL"), translate("TTL for all domain result.")) +o = s:option(Value, "rr_ttl", translate("Domain TTL"), translate("TTL for all domain result.")) o.rempty = true ---- rr-ttl-min -o = s:taboption("settings", Value, "rr_ttl_min", translate("Domain TTL Min"), translate("Minimum TTL for all domain result.")) +o = s:option(Value, "rr_ttl_min", translate("Domain TTL Min"), translate("Minimum TTL for all domain result.")) o.rempty = true ---- rr-ttl-max -o = s:taboption("settings", Value, "rr_ttl_min", translate("Domain TTL Max"), translate("Maximum TTL for all domain result.")) +o = s:option(Value, "rr_ttl_min", translate("Domain TTL Max"), translate("Maximum TTL for all domain result.")) o.rempty = true -o = s:taboption("help", Button, "web") -o.title = translate("SmartDNS official website") -o.inputtitle = translate("open website") -o.inputstyle = "apply" -o.write = function() - luci.http.redirect("https://pymumu.github.io/") -end - -o = s:taboption("help", Button, "Donate") -o.title = translate("Donate to smartdns") -o.inputtitle = translate("Donate") -o.inputstyle = "apply" -o.write = function() - luci.http.redirect("https://pymumu.github.io/smartdns") -end - -- Upstream servers s = m:section(TypedSection, "server", translate("Upstream Servers"), translate("Upstream Servers, support UDP, TCP protocol")) s.anonymous = true @@ -116,5 +97,26 @@ function addr.write(self, section, value) nixio.fs.writefile("/etc/smartdns/address.conf", value) end +-- Doman addresss +s = m:section(TypedSection, "smartdns", translate("Technical Support"), + translate("Technical Support")) +s.anonymous = true + +o = s:option(Button, "web") +o.title = translate("SmartDNS official website") +o.inputtitle = translate("open website") +o.inputstyle = "apply" +o.write = function() + luci.http.redirect("https://pymumu.github.io/smartdns") +end + +o = s:option(Button, "Donate") +o.title = translate("Donate to smartdns") +o.inputtitle = translate("Donate") +o.inputstyle = "apply" +o.write = function() + luci.http.redirect("https://pymumu.github.io/smartdns/#donate") +end + return m diff --git a/package/openwrt/address.conf b/package/openwrt/address.conf index e69de29..b0b79a7 100644 --- a/package/openwrt/address.conf +++ b/package/openwrt/address.conf @@ -0,0 +1,3 @@ +# Add domains which you want to force to an IP address here. +# The example below send any host in example.com to a local webserver. +#address /example.com/127.0.0.1 \ No newline at end of file diff --git a/package/openwrt/files/etc/init.d/smartdns b/package/openwrt/files/etc/init.d/smartdns index 6ed7f64..4af45cb 100644 --- a/package/openwrt/files/etc/init.d/smartdns +++ b/package/openwrt/files/etc/init.d/smartdns @@ -1,5 +1,5 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2008-2011 OpenWrt.org +# Copyright (C) 2018 Nick Peng (pymumu@gmail.com) START=50 SERVICE_USE_PID=1 @@ -97,7 +97,7 @@ start_service() { config_foreach load_server "server" echo "# address" >> $SMARTDNS_CONF_TMP - grep "^ *address" $ADDRESS_CONF >> $SMARTDNS_CONF_TMP + grep "^ *address " $ADDRESS_CONF >> $SMARTDNS_CONF_TMP config_get_bool "enabled" "$section" "enabled" '0' mv $SMARTDNS_CONF_TMP $SMARTDNS_CONF diff --git a/package/optware/make.sh b/package/optware/make.sh index 9f84dda..4101fc9 100644 --- a/package/optware/make.sh +++ b/package/optware/make.sh @@ -33,6 +33,7 @@ build() cp $SMARTDNS_BIN $ROOT/opt/usr/sbin sed -i "s/^\(bind .*\):53/\1:535/g" $ROOT/opt/etc/smartdns/smartdns.conf + sed -i "s/# *server-name smartdns/server-name smartdns/g" $ROOT/opt/etc/smartdns/smartdns.conf sed -i "s/^Architecture.*/Architecture: $ARCH/g" $ROOT/control/control sed -i "s/Version:.*/Version: $VER/" $ROOT/control/control