Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge #1971

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

merge #1971

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 37 additions & 152 deletions ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,161 +1,46 @@
# SmartDNS

**[English](ReadMe_en.md)**

![SmartDNS](doc/smartdns-banner.png)
SmartDNS 是一个运行在本地的 DNS 服务器,它接受来自本地客户端的 DNS 查询请求,然后从多个上游 DNS 服务器获取 DNS 查询结果,并将访问速度最快的结果返回给客户端,以此提高网络访问速度。
SmartDNS 同时支持指定特定域名 IP 地址,并高性匹配,可达到过滤广告的效果; 支持DOT(DNS over TLS)和DOH(DNS over HTTPS),更好的保护隐私。

与 DNSmasq 的 all-servers 不同,SmartDNS 返回的是访问速度最快的解析结果。

支持树莓派、OpenWrt、华硕路由器原生固件和 Windows 系统等。

## 使用指导

SmartDNS官网:[https://pymumu.github.io/smartdns](https://pymumu.github.io/smartdns)

## 软件效果展示
在SmartDNS基础上,domain-set增加geosite域名匹配规则文本文件的支持,以便实现域名服务器分组。

### 仪表盘
##域名规则支持以下几种匹配方式:
1) 以 domain: 开头,域匹配。e.g: domain:google.com 会匹配自身 google.com,以及其子域名 www.google.com, maps.l.google.com 等。
2) 以 full: 开头,完整匹配。e.g: full:google.com 只会匹配自身。
3) 以 keyword: 开头,关键字匹配。e.g: keyword:google.com 会匹配包含这个字段的域名,如 google.com.hk, www.google.com.hk。
4) 以 regexp: 开头,正则匹配。e.g: "regexp:\.goo.*\.com$" 匹配 "www.google.com" 或 "fonts.googleapis.com",但不匹配 "google.com"。

![SmartDNS-WebUI](doc/smartdns-webui.png)
如果没有指定匹配方式,默认为域匹配。

### 速度对比
匹配方式按如下顺序生效: full、domain优先, regexp、keyword次之,regexp 和 keyword 规则生效顺序为规则导入的顺序。

**阿里 DNS**
使用阿里 DNS 查询百度IP,并检测结果。

```shell
$ nslookup www.baidu.com 223.5.5.5
Server: 223.5.5.5
Address: 223.5.5.5#53

Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 180.97.33.108
Name: www.a.shifen.com
Address: 180.97.33.107

$ ping 180.97.33.107 -c 2
PING 180.97.33.107 (180.97.33.107) 56(84) bytes of data.
64 bytes from 180.97.33.107: icmp_seq=1 ttl=55 time=24.3 ms
64 bytes from 180.97.33.107: icmp_seq=2 ttl=55 time=24.2 ms

--- 180.97.33.107 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 24.275/24.327/24.380/0.164 ms
pi@raspberrypi:~/code/smartdns_build $ ping 180.97.33.108 -c 2
PING 180.97.33.108 (180.97.33.108) 56(84) bytes of data.
64 bytes from 180.97.33.108: icmp_seq=1 ttl=55 time=31.1 ms
64 bytes from 180.97.33.108: icmp_seq=2 ttl=55 time=31.0 ms

--- 180.97.33.108 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 31.014/31.094/31.175/0.193 ms
##编译cre2:
```

**SmartDNS**
使用 SmartDNS 查询百度 IP,并检测结果。

```shell
$ nslookup www.baidu.com
Server: 192.168.1.1
Address: 192.168.1.1#53

Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 14.215.177.39

$ ping 14.215.177.39 -c 2
PING 14.215.177.39 (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39: icmp_seq=1 ttl=56 time=6.31 ms
64 bytes from 14.215.177.39: icmp_seq=2 ttl=56 time=5.95 ms

--- 14.215.177.39 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
apt-get install libssl-dev libre2-dev automake libtool texinfo
git clone https://github.com/marcomaggi/cre2.git
cd cre2
./autogen.sh
touch ./doc/version.texi
mkdir build && cd build
../configure
make
make install
ldconfig
```
##编译v2dat:
```
git clone https://github.com/urlesistiana/v2dat.git
cd v2dat
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o v2dat -trimpath -ldflags "-s -w -buildid=" .
```
##数据下载及转换:
```
wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat
./v2dat unpack geosite -f google geosite.dat
```
##配置smartdns.conf:
```
domain-set -name geosite_google -type geosite -file /etc/smartdns/geosite_google.txt
nameserver /domain-set:geosite_google/google
server 8.8.8.8 -group google -exclude-default-group
```
SmartDNS官网:[https://pymumu.github.io/smartdns](https://pymumu.github.io/smartdns)

从对比看出,SmartDNS 找到了访问 `www.baidu.com` 最快的 IP 地址,比阿里 DNS 速度快了 5 倍。

## 特性

1. **多虚拟DNS服务器**
支持多个虚拟DNS服务器,不同虚拟DNS服务器不同的端口,规则,客户端。

1. **多 DNS 上游服务器**
支持配置多个上游 DNS 服务器,并同时进行查询,即使其中有 DNS 服务器异常,也不会影响查询。

1. **支持每个客户端独立控制**
支持基于MAC,IP地址控制客户端使用不同查询规则,可实现家长控制等功能。

1. **返回最快 IP 地址**
支持从域名所属 IP 地址列表中查找到访问速度最快的 IP 地址,并返回给客户端,提高网络访问速度。

1. **支持多种查询协议**
支持 UDP、TCP、DOT 和 DOH 查询及服务,以及非 53 端口查询;支持通过socks5,HTTP代理查询;

1. **特定域名 IP 地址指定**
支持指定域名的 IP 地址,达到广告过滤效果、避免恶意网站的效果。

1. **域名高性能后缀匹配**
支持域名后缀匹配模式,简化过滤配置,过滤 20 万条记录时间 < 1ms。

1. **域名分流**
支持域名分流,不同类型的域名向不同的 DNS 服务器查询,支持iptable和nftable更好的分流;支持测速失败的情况下设置域名结果到对应ipset和nftset集合。

1. **Windows / Linux 多平台支持**
支持标准 Linux 系统(树莓派)、OpenWrt 系统各种固件和华硕路由器原生固件。同时还支持 WSL(Windows Subsystem for Linux,适用于 Linux 的 Windows 子系统)。

1. **支持 IPv4、IPv6 双栈**
支持 IPv4 和 IPV 6网络,支持查询 A 和 AAAA 记录,支持双栈 IP 速度优化,并支持完全禁用 IPv6 AAAA 解析。

1. **支持DNS64**
支持DNS64转换。

1. **高性能、占用资源少**
多线程异步 IO 模式,cache 缓存查询结果。

1. **主流系统官方支持**
主流路由系统官方软件源安装smartdns。

## 架构

![Architecture](https://github.com/pymumu/test/releases/download/blob/architecture.png)

1. SmartDNS 接收本地网络设备的DNS 查询请求,如 PC、手机的查询请求;
1. 然后将查询请求发送到多个上游 DNS 服务器,可支持 UDP 标准端口或非标准端口查询,以及 TCP 查询;
1. 上游 DNS 服务器返回域名对应的服务器 IP 地址列表,SmartDNS 则会检测从本地网络访问速度最快的服务器 IP;
1. 最后将访问速度最快的服务器 IP 返回给本地客户端。

## 编译

- 代码编译:

SmartDNS 提供了编译软件包的脚本(`package/build-pkg.sh`),支持编译 LuCI、Debian、OpenWrt 和 Optware 安装包。

- 文档编译:

文档分支为`doc`,安装`mkdocs`工具后,执行`mkdocs build`编译。

## 捐赠

如果你觉得此项目对你有帮助,请捐助我们,使项目能持续发展和更加完善。

### 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 Pay 微信支付

![wechat](doc/wechat_donate.jpg)

## 开源声明

SmartDNS 基于 GPL V3 协议开源。
178 changes: 37 additions & 141 deletions ReadMe_en.md
Original file line number Diff line number Diff line change
@@ -1,151 +1,47 @@
# SmartDNS
Based on SmartDNS, the domain-set adds support for geosite domain matching rule text files to enable grouping of domain servers.

![SmartDNS](doc/smartdns-banner.png)
SmartDNS is a local DNS server. SmartDNS accepts DNS query requests from local clients, obtains DNS query results from multiple upstream DNS servers, and returns the fastest access results to clients. supports secure DNS protocols like DoT (DNS over TLS), DoH (DNS over HTTPS), better protect privacy,
Avoiding DNS pollution and improving network access speed, supports high-performance ad filtering.
###Domain rules support the following matching methods:

Unlike dnsmasq's all-servers, smartdns returns the fastest access resolution.
Starting with domain: for domain matching. e.g., domain:google.com will match google.com itself and its subdomains like www.google.com, maps.l.google.com, etc.

Support Raspberry Pi, openwrt, ASUS router, Windows and other devices.
Starting with full: for exact matching. e.g., full:google.com will only match itself.

## Usage
Starting with keyword: for keyword matching. e.g., keyword:google.com will match domains containing this field, such as google.com.hk, www.google.com.hk.

Please visit website: [https://pymumu.github.io/smartdns](https://pymumu.github.io/smartdns/en)
Starting with regexp: for regular expression matching. e.g., "regexp:\.goo.*\.com$" matches www.google.com or fonts.googleapis.com but not google.com.

## Software Show
If no matching method is specified, domain matching is used by default.

### Dashboard
The matching methods take effect in the following order: full and domain have priority, followed by regexp and keyword. The order of effectiveness for regexp and keyword rules depends on their import sequence.

![SmartDNS-WebUI](doc/smartdns-webui.png)

### Speed Comparison

**Ali DNS**
Use Ali DNS to query Baidu's IP and test the results.

```shell
pi@raspberrypi:~/code/smartdns_build $ nslookup www.baidu.com 223.5.5.5
Server: 223.5.5.5
Address: 223.5.5.5#53

Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 180.97.33.108
Name: www.a.shifen.com
Address: 180.97.33.107

pi@raspberrypi:~/code/smartdns_build $ ping 180.97.33.107 -c 2
PING 180.97.33.107 (180.97.33.107) 56(84) bytes of data.
64 bytes from 180.97.33.107: icmp_seq=1 ttl=55 time=24.3 ms
64 bytes from 180.97.33.107: icmp_seq=2 ttl=55 time=24.2 ms

--- 180.97.33.107 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 24.275/24.327/24.380/0.164 ms
pi@raspberrypi:~/code/smartdns_build $ ping 180.97.33.108 -c 2
PING 180.97.33.108 (180.97.33.108) 56(84) bytes of data.
64 bytes from 180.97.33.108: icmp_seq=1 ttl=55 time=31.1 ms
64 bytes from 180.97.33.108: icmp_seq=2 ttl=55 time=31.0 ms

--- 180.97.33.108 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 31.014/31.094/31.175/0.193 ms
###Compile cre2:
```

**smartdns**
Use SmartDNS to query Baidu IP and test the results.

```shell
pi@raspberrypi:~/code/smartdns_build $ nslookup www.baidu.com
Server: 192.168.1.1
Address: 192.168.1.1#53

Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 14.215.177.39

pi@raspberrypi:~/code/smartdns_build $ ping 14.215.177.39 -c 2
PING 14.215.177.39 (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39: icmp_seq=1 ttl=56 time=6.31 ms
64 bytes from 14.215.177.39: icmp_seq=2 ttl=56 time=5.95 ms

--- 14.215.177.39 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms

apt-get install libssl-dev libre2-dev automake libtool texinfo
git clone https://github.com/marcomaggi/cre2.git
cd cre2
./autogen.sh
touch ./doc/version.texi
mkdir build && cd build
../configure
make
make install
ldconfig
```

From the comparison, smartdns found the fastest IP address to visit www.baidu.com, so accessing Baidu's DNS is 5 times faster than Ali DNS.

## Features

1. **Multiple Virtual DNS server**
Support multiple virtual DNS servers with different ports, rules, and clients.

1. **Multiple upstream DNS servers**
Support configuring multiple upstream DNS servers and query at the same time.the query will not be affected, Even if there is a DNS server exception.

1. **Support per-client query control**
Support controlling clients using different query rules based on MAC and IP addresses, enabling features such as parental control.

1. **Return the fastest IP address**
Support finding the fastest access IP address from the IP address list of the domain name and returning it to the client to avoid DNS pollution and improve network access speed.

1. **Support for multiple query protocols**
Support UDP, TCP, DOT(DNS over TLS), DOH(DNS over HTTPS) queries and service, and non-53 port queries, effectively avoiding DNS pollution and protect privacy, and support query DNS over socks5, http proxy.

1. **Domain IP address specification**
Support configuring IP address of specific domain to achieve the effect of advertising filtering, and avoid malicious websites.

1. **Domain name high performance rule filtering**
Support domain name suffix matching mode, simplify filtering configuration, filter 200,000 recording and take time <1ms.

1. **Linux/Windows multi-platform support**
Support standard Linux system (Raspberry Pi), openwrt system various firmware, ASUS router native firmware. Support Windows 10 WSL (Windows Subsystem for Linux).

1. **Support IPV4, IPV6 dual stack**
Support IPV4, IPV6 network, support query A, AAAA record, dual-stack IP selection, and filter IPV6 AAAA record.

1. **DNS64**
Support DNS64 translation.

1. **High performance, low resource consumption**
Multi-threaded asynchronous IO mode, cache cache query results.

1. **DNS domain forwarding**
Support DNS forwarding, ipset and nftables. Support setting the domain result to ipset and nftset set when speed check fails.

## Architecture

![Architecture](doc/architecture.png)

1. SmartDNS receives DNS query requests from local network devices, such as PCs and mobile phone query requests.
1. SmartDNS sends query requests to multiple upstream DNS servers, using standard UDP queries, non-standard port UDP queries, and TCP queries.
1. The upstream DNS server returns a list of Server IP addresses corresponding to the domain name. SmartDNS detects the fastest Server IP with local network access.
1. Return the fastest accessed Server IP to the local client.

## Compile

smartdns contains scripts for compiling packages, supports compiling luci, debian, openwrt, optware installation packages, and can execute `package/build-pkg.sh` compilation.

## [Donate](#donate)

If you feel that this project is helpful to you, please donate to us so that the project can continue to develop and be more perfect.

### 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)

## Open Source License

Smartdns is licensed to the public under the GPL V3 License.
###Compile v2dat:
```
git clone https://github.com/urlesistiana/v2dat.git
cd v2dat
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o v2dat -trimpath -ldflags "-s -w -buildid="
```
###Data download and conversion:
```
wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat
./v2dat unpack geosite -f google geosite.dat
```
###Configure smartdns.conf:
```
domain-set -name geosite_google -type geosite -file /etc/smartdns/geosite_google.txt
nameserver /domain-set:geosite_google/google
server 8.8.8.8 -group google -exclude-default-group
```
SmartDNS official website: https://pymumu.github.io/smartdns
2 changes: 1 addition & 1 deletion etc/smartdns/smartdns.conf
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ log-level info
# the domain-set can be used with /domain/ for address, nameserver, ipset, etc.
# domain-set -name [set-name] -type list -file [/path/to/file]
# [-n] -name [set name]: domain set name
# [-t] -type [list]: domain set type, list only now
# [-t] -type [list|geosite|geositelist]: domain set type
# [-f] -file [path/to/set]: file path of domain set
#
# example:
Expand Down
Loading