Total Pageviews

Thursday 14 April 2016

在mac上,编译dnscrypt-proxy v1.x版

git clone https://github.com/dyne/dnscrypt-proxy dnscrypt-proxy-by-dyne
cd dnscrypt-proxy-by-dyne

./autogen.sh
./configure
make

yudeMacBook-Air:dnscrypt-proxy-by-dyne brite$ find . -name dnscrypt-proxy
./src/proxy/dnscrypt-proxy
yudeMacBook-Air:dnscrypt-proxy-by-dyne brite$ ./src/proxy/dnscrypt-proxy -h
dnscrypt-proxy 1.9.5

Compilation date: Jul 11 2019
Support for plugins: present
Plugins root directory: [/usr/local/lib/dnscrypt-proxy/]
Support for the XChaCha20-Poly1305 cipher: present

Options:

  -R --resolver-name=...
  -a --local-address=...
  -d --daemonize
  -E --ephemeral-keys
  -K --client-key=...
  -L --resolvers-list=...
  -l --logfile=...
  -m --loglevel=...
  -p --pidfile=...
  -X --plugin=...
  -N --provider-name=...
  -k --provider-key=...
  -r --resolver-address=...
  -S --syslog
  -Z --syslog-prefix=...
  -n --max-active-requests=...
  -u --user=...
  -t --test=...
  -T --tcp-only
  -e --edns-payload-size=...
  -I --ignore-timestamps
  -V --version
  -h --help

Please consult the dnscrypt-proxy(8) man page for details.

yudeMacBook-Air:dnscrypt-proxy-by-dyne brite$ ./src/proxy/dnscrypt-proxy --version
dnscrypt-proxy 1.9.5

Compilation date: Jul 11 2019
Support for plugins: present
Plugins root directory: [/usr/local/lib/dnscrypt-proxy/]
Support for the XChaCha20-Poly1305 cipher: present
yudeMacBook-Air:dnscrypt-proxy-by-dyne brite$

https://github.com/krattai/dnscrypt-proxy-opennic 这个仓库也行,他也是v1.x版。必须是v1.x版,v2.x版是不行的。
至此,你可以暂时不用往下看了。
--------------------------------------------

命令为brew install dnscrypt-proxy
(这样安装的dnscrypt-proxy是2.x版)
途中显示:
...
/usr/local/sbin/dnscrypt-proxy
/usr/local/bin/hostip
...
After starting dnscrypt-proxy, you will need to point your
local DNS server to 127.0.0.1. You can do this by going to
System Preferences > "Network" and clicking the "Advanced..."
button for your interface. You will see a "DNS" tab where you
can click "+" and enter 127.0.0.1 in the "DNS Servers" section.

By default, dnscrypt-proxy runs on localhost (127.0.0.1), port 53,
and under the "nobody" user using the dnscrypt.eu-dk DNSCrypt-enabled
resolver. If you would like to change these settings, you will have to edit
the plist file (e.g., --resolver-address, --provider-name, --provider-key, etc.)

To check that dnscrypt-proxy is working correctly, open Terminal and enter the
following command. Replace en1 with whatever network interface you're using:

    sudo tcpdump -i en1 -vvv 'port 443'

You should see a line in the result that looks like this:

    resolver2.dnscrypt.eu.https

To have launchd start dnscrypt-proxy at startup:
  sudo cp -fv /usr/local/opt/dnscrypt-proxy/*.plist /Library/LaunchDaemons
  sudo chown root /Library/LaunchDaemons/homebrew.mxcl.dnscrypt-proxy.plist
Then to load dnscrypt-proxy now:
  sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnscrypt-proxy.plist
==> Summary
/usr/local/Cellar/dnscrypt-proxy/1.6.0: 14 files, 548K
yudeMacBook-Air:dnscrypt-proxy brite$ brew link --overwrite dnscrypt-proxy

Linking /usr/local/Cellar/dnscrypt-proxy/1.6.0... 6 symlinks created

然后,
yudeMacBook-Air:dnscrypt-proxy brite$ hostip
Usage: hostip [-6] [-r resolver_ip[:port]] host_name
  -6, --ipv6: ask for AAAA records
  -h, --help: show usage
  -r, --resolver-address=<ip>: the resolver IP address
  -V, --version: show version number

Example: hostip www.example.com

yudeMacBook-Air:dnscrypt-proxy brite$ dnscrypt-proxy
-bash: dnscrypt-proxy: command not found
yudeMacBook-Air:dnscrypt-proxy brite$ ln -s /usr/local/sbin/dnscrypt-proxy /usr/local/bin/dnscrypt-proxy
yudeMacBook-Air:dnscrypt-proxy brite$ dnscrypt-proxy (现在可以运行dnscrypt-proxy了,显示如下内容)
[ERROR] Resolver information required.
[ERROR] The easiest way to do so is to provide a resolver name.
[ERROR] Example: dnscrypt-proxy -R mydnsprovider
[ERROR] See the file [/usr/local/Cellar/dnscrypt-proxy/1.6.0/share/dnscrypt-proxy/dnscrypt-resolvers.csv] for a list of compatible public resolvers
[ERROR] The name is the first column in this table.
[ERROR] Alternatively, an IP address, a provider name and a provider key can be supplied.
[ERROR] Please consult http://dnscrypt.org and the dnscrypt-proxy(8) man page for details.
yudeMacBook-Air:dnscrypt-proxy brite$
-----------------

这里有2个自动安装脚本:
https://github.com/simonclausen/dnscrypt-autoinstall
https://github.com/alterstep/dnscrypt-autoinstall
----------

A tool for securing communications between a client and a DNS resolver 

dnscrypt-proxy provides local service which can be used directly as your local resolver or as a DNS forwarder, authenticating requests using the DNSCrypt protocol and passing them to an upstream server.
The DNSCrypt protocol uses high-speed high-security elliptic-curve cryptography and is very similar to DNSCurve, but focuses on securing communications between a client and its first-level resolver.
While not providing end-to-end security, it protects the local network, which is often the weakest point of the chain, against man-in-the-middle attacks.
dnscrypt-proxy is only a client-implementation of the protocol. It requires a DNSCrypt server on the other end.

Download and integrity check

dnscrypt-proxy can be downloaded here: dnscrypt-proxy download
Note: dnscrypt.org is now blocked by the Great Firewall of China. But the source code can also be downloaded on Github, in the "releases" section.
After having downloaded a file, compute its SHA256 digest. For example:
$ openssl dgst -sha256 dnscrypt-proxy-1.6.1.tar.bz2
Verify this digest against the expected one, that can be retrieved using a simple DNS query:
$ drill -aD TXT dnscrypt-proxy-1.6.1.tar.bz2.download.dnscrypt.org
or
$ dig +dnssec TXT dnscrypt-proxy-1.6.1.tar.bz2.download.dnscrypt.org
If the content of the TXT record doesn't match the SHA256 digest you computed, please file a bug report on Github as soon as possible and don't go any further.
Signatures can also be verified with the Minisign tool:
$ minisign -VP RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3 -m dnscrypt-proxy-1.6.1.tar.bz2

Installation

The daemon is known to work on recent versions of OSX, OpenBSD, Bitrig, NetBSD, Dragonfly BSD, FreeBSD, Linux, iOS (requires a jailbroken device), Android (requires a rooted device), and Windows (requires MingW).
Install libsodium. On Linux, don't forget to run ldconfig if you installed it from source.
A "minimal" build of libsodium (--enable-minimal) works equally well as a full build with this proxy.
On Fedora, RHEL and CentOS, you may need to add /usr/local/lib to the paths the dynamic linker is going to look at. Before issuing ldconfig, type:
# echo /usr/local/lib > /etc/ld.so.conf.d/usr_local_lib.conf
Now, download the latest dnscrypt-proxy version and extract it:
$ bunzip2 -cd dnscrypt-proxy-*.tar.bz2 | tar xvf -
$ cd dnscrypt-proxy-*
Compile and install it using the standard procedure:
$ ./configure && make -j2
# make install
Replace -j2 with whatever number of CPU cores you want to use for the compilation process.
The proxy will be installed as /usr/local/sbin/dnscrypt-proxy by default.
Command-line switches are documented in the dnscrypt-proxy(8) man page.

GUIs for dnscrypt-proxy

If you need a simple graphical user interface in order to start/stop the proxy and change your DNS settings, check out the following project:
  • Simple DNSCrypt: an all-in-one, standalone client - using DNSCrypt on Windows has never been so simple.
  • DNSCrypt WinClient: Easily enable/disable DNSCrypt on multiple adapters. Supports different ports and protocols, IPv6, parental controls and the proxy can act as a gateway service. Windows only, written in .NET.
  • DNSCrypt Windows Service Manager: Assists in setting up DNSCrypt as a service, configure it and change network adapter DNS settings to use DNSCrypt. It includes the option to use TCP/UDP protocol, IPV4/IPV6 connectivity, choice of network adapter to configure, as well as configurations for currently available DNSCrypt providers.
  • DNSCrypt OSXClient: Mac OSX application to control the DNSCrypt Proxy.
  • DNSCrypt Tools for Linux: A set of tools for dnscrypt-proxy. Features a start and stop button as well as options to enable or disable from startup. Developed for Porteus Linux.

DNSCrypt-enabled resolvers

To get started, you can use any of the public DNS resolvers supporting DNSCrypt.
This file is constantly updated, and its minisign signature can be verified with the following command:
minisign -VP RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3 -m dnscrypt-resolvers.csv
If you want to add DNSCrypt support to your own public or private resolver, check out DNSCrypt-Wrapper, a server-side dnscrypt proxy that works with any name resolver.
DNSCrypt server Docker image is also available to deploy a non-logging, DNSSEC and DNSCrypt-capable resolver without having to manually compile or configure anything.

Usage

Having a dedicated system user, with no privileges and with an empty home directory, is highly recommended. For extra security, DNSCrypt will chroot() to this user's home directory and drop root privileges for this user's uid as soon as possible.
The easiest way to start the daemon is:
# dnscrypt-proxy --daemonize --resolver-name=<resolver name>
Replace <resolver name> with the name of the resolver you want to use (the first column in the list of public resolvers).
The proxy will accept incoming requests on 127.0.0.1, tag them with an authentication code, forward them to the resolver, and validate each answer before passing it to the client.
Given such a setup, in order to actually start using DNSCrypt, you need to update your /etc/resolv.conf file and replace your current set of resolvers with:
nameserver 127.0.0.1
Other common command-line switches include:
  • --daemonize in order to run the server as a background process.
  • --local-address=<ip>[:port] in order to locally bind a different IP address than 127.0.0.1
  • --logfile=<file> in order to write log data to a dedicated file. By default, logs are sent to stdout if the server is running in foreground, and to syslog if it is running in background.
  • --loglevel=<level> if you need less verbosity in log files.
  • --max-active-requests=<count> to set the maximum number of active requests. The default value is 250.
  • --pidfile=<file> in order to store the PID number to a file.
  • --user=<user name> in order to chroot()/drop privileges.
  • --resolvers-list=<file>: to specity the path to the CSV file containing the list of available resolvers, and the parameters to use them.
  • --test in order to check that the server-side proxy is properly configured and that a valid certificate can be used. This is useful for monitoring your own dnscrypt proxy. See the man page for more information.
The --resolver-address=<ip>[:port]--provider-name=<certificate provider FQDN> and --provider-key=<provider public key> switches can be specified in order to use a DNSCrypt-enabled recursive DNS service not listed in the configuration file.

Running dnscrypt-proxy using systemd

On a system using systemd, and when compiled with --with-systemd, the proxy can take advantage of systemd's socket activation instead of creating the sockets itself. The proxy will also notify systemd on successful startup.
Two sockets need to be configured: a UDP socket (ListenStream) and a TCP socket (ListenDatagram) sharing the same port.
The source distribution includes the dnscrypt-proxy.socket and dnscrypt-proxy.service files that can be used as a starting point.

Installation as a service (Windows only)

The proxy can be installed as a Windows service.
See README-WINDOWS.markdown for more information on DNSCrypt on Windows.

Using DNSCrypt in combination with a DNS cache

The DNSCrypt proxy is not a DNS cache. This means that incoming queries will not be cached and every single query will require a round-trip to the upstream resolver.
For optimal performance, the recommended way of running DNSCrypt is to run it as a forwarder for a local DNS cache, such as unbound or powerdns-recursor.
Both can safely run on the same machine as long as they are listening to different IP addresses (preferred) or different ports.
If your DNS cache is unbound, all you need is to edit the unbound.conf file and add the following lines at the end of theserver section:
do-not-query-localhost: no

forward-zone:
  name: "."
  forward-addr: 127.0.0.1@40
The first line is not required if you are using different IP addresses instead of different ports.
Then start dnscrypt-proxy, telling it to use a specific port (40, in this example):
# dnscrypt-proxy --local-address=127.0.0.1:40 --daemonize

IPv6 support

IPv6 is fully supported. IPv6 addresses with a port number should be specified as [ip]:port
# dnscrypt-proxy --local-address='[::1]:40' ...

Queries using nonstandard ports / over TCP

Some routers and firewalls can block outgoing DNS queries or transparently redirect them to their own resolver. This especially happens on public Wifi hotspots, such as coffee shops.
As a workaround, the port number can be changed using the --resolver-port=<port> option.
By default, dnscrypt-proxy sends outgoing queries to UDP port 443.
In addition, the DNSCrypt proxy can force outgoing queries to be sent over TCP. For example, TCP port 443, which is commonly used for communication over HTTPS, may not be filtered.
The --tcp-only command-line switch forces this behavior. When an incoming query is received, the daemon immediately replies with a "response truncated" message, forcing the client to retry over TCP. The daemon then authenticates the query and forwards it over TCP to the resolver.
--tcp-only is slower than UDP because multiple queries over a single TCP connections aren't supported yet, and this workaround should never be used except when bypassing a filter is actually required.

Public-key client authentication

By default, dnscrypt-proxy generates non-deterministic client keys every time it starts, or for every query (when the ephemeral keys feature is turned on).
However, commercial DNS services may want to use DNSCrypt to authenticate the sender of a query using public-key cryptography, i.e. know what customer sent a query without altering the DNS query itself, and without using shared secrets.
Resolvers that should be accessible from any IP address, but that are supposed to be used only by specific users, can also take advantage of DNSCrypt to only respond to queries sent using a given list of public keys.
In order to do so, dnscrypt-proxy 1.6.0 introduced the --client-key (or -K) switch. This loads a secret client key from a file instead of generating random keys:
# dnscrypt-proxy --client-key=/private/client-secret.key
This file has to remain private, and its content doesn't have to be known by the DNS service provider.
Versions 1 and 2 of the DNSCrypt protocol use Curve25519 keys, and the format of this file for Curve25519 keys is a hexadecimal string, with optional :[space] and - delimiters, decoding to 34 bytes:
01 01 || 32-byte Curve25519 secret key

EDNS payload size

DNS packets sent over UDP have been historically limited to 512 bytes, which is usually fine for queries, but sometimes a bit short for replies.
Most modern authoritative servers, resolvers and stub resolvers support the Extension Mechanism for DNS (EDNS) that, among other things, allows a client to specify how large a reply over UDP can be.
Unfortunately, this feature is disabled by default on a lot of operating systems. It has to be explicitly enabled, for example by adding options edns0 to the /etc/resolv.conf file on most Unix-like operating systems.
dnscrypt-proxy can transparently rewrite outgoing packets before authenticating them, in order to add the EDNS0 mechanism. By default, a conservative payload size of 1252 bytes is advertised.
This size can be made larger by starting the proxy with the --edns-payload-size=<bytes> command-line switch. Values up to 4096 are usually safe, but some routers/firewall/NAT boxes block IP fragments.
If you can resolve test-tcp.dnscrypt.org, increasing the maximum payload size is probably fine. If you can't, or just to stay on the safe side, do not tweak this; stick to the default value.
A value below or equal to 512 will disable this mechanism, unless a client sends a packet with an OPT section providing a payload size.

The hostip utility

The DNSCrypt proxy ships with a simple tool named hostip that resolves a name to IPv4 or IPv6 addresses.
This tool can be useful for starting some services before dnscrypt-proxy.
Queries made by hostip are not authenticated.

Plugins

dnscrypt-proxy can be extended with plugins. A plugin acts as a filter that can locally inspect and modify queries and responses.
The plugin API is documented in the README-PLUGINS.markdown file.
Any number of plugins can be combined (chained) by repeating the --plugin command-line switch.
The default distribution ships with some example plugins:
  • libdcplugin_example_ldns_aaaa_blocking: Directly return an empty response to AAAA queries
Example usage:
# dnscrypt-proxy ... \
--plugin libdcplugin_example_ldns_aaaa_blocking.la
If IPv6 connectivity is not available on your network, this plugin avoids waiting for responses about IPv6 addresses from upstream resolvers. This can improve your web browsing experience.
  • libdcplugin_example_ldns_blocking: Block specific domains and IP addresses.
This plugin returns a REFUSED response if the query name is in a list of blacklisted names, or if at least one of the returned IP addresses happens to be in a list of blacklisted IPs.
Recognized switches are:
--domains=<file>
--ips=<file>
A file should list one entry per line.
IPv4 and IPv6 addresses are supported. For names, leading and trailing wildcards (*) are also supported (e.g. *xxx*,*.example.comads.*)
# dnscrypt-proxy ... \
--plugin libdcplugin_example,--ips=/etc/blk-ips,--domains=/etc/blk-names
  • libdcplugin_example-logging: Log client queries
This plugin logs the client queries to the standard output (default) or to a file.
# dnscrypt-proxy ... \
--plugin libdcplugin_example_logging,/var/log/dns.log
  • Extra plugins
Additional plugins can be found on Github: Masquerade pluginGeoIP plugin.

from https://github.com/jedisct1/dnscrypt-proxy
https://github.com/jedisct1/dnscrypt-proxy/wiki/Installation-macOS
------------------------------

各种“连接被重置(connection reset)”是很烦人的,比如谷歌上进行搜索时,可能会出现“连接被重置”啥的,这是ISP的DNS污染(什么是DNS污染DNS cache poisoning )造成的.即使你修改了DNS服务器,仍然会被污染.
OpenDNS公布了DNSCrypt ,即DNS加密,来阻止ISP污染你的DNS.
完成安装dnscrypt-proxy后,输入命令来查看dnscrypt-proxy的使用帮助:
dnscrypt-proxy -h
可以看到帮助里有很多参数的设置:
yudeMacBook-Air:dnscrypt-proxy brite$ dnscrypt-proxy -h
dnscrypt-proxy 1.6.0

Options:

  -a --local-address=...
  -d --daemonize
  -e --edns-payload-size=...
  -E --ephemeral-keys
  -K --client-key=...
  -h --help
  -L --resolvers-list=...
  -R --resolver-name=...
  -l --logfile=...
  -m --loglevel=...
  -n --max-active-requests=...
  -p --pidfile=...
  -X --plugin=...
  -N --provider-name=...
  -k --provider-key=...
  -r --resolver-address=...
  -u --user=...
  -t --test=...
  -T --tcp-only
  -V --version
Please consult the dnscrypt-proxy(8) man page for details.
yudeMacBook-Air:dnscrypt-proxy brite$
yudeMacBook-Air:~ brite$ dnscrypt-proxy -t52 --tcp-only --resolver-name=dnscrypt.eu-dk
[INFO] + DNS Security Extensions are supported
[INFO] - [dnscrypt.eu-dk] does not support Namecoin domains
[INFO] + Provider supposedly doesn't keep logs
[NOTICE] Starting dnscrypt-proxy 1.6.0
[INFO] Generating a new session key pair
[INFO] Done
[INFO] Server certificate #808464433 received
[INFO] This certificate looks valid
[INFO] Chosen certificate #808464433 is valid from [2015-09-11] to [2016-09-10]
[INFO] Server key fingerprint is 164E:1AD6:4356:777D:2019:F2F9:D389:2DDB:BC75:8AF0:9172:8E0C:A874:10C7:3BE8:423B
yudeMacBook-Air:~ brite$

这里,-t 参数(即tcp-port=)
sudo dnscrypt-proxy -t443
sudo dnscrypt-proxy -t53
这样就将我们的DNS加密服务启动了(关闭这个终端以关闭),但是这个DNS服务是我们的本机,所以,我们要将自己的DNS指向我们的本机:127.0.0.1
设置DNS指向
客户端下载完成后,下面来修改DNS指向LocalHost
Ubuntu 、MacOS的话打开右上角的Network-Manager,编辑链接,然后在IPv4设置里设置DNS为127.0.0.1就行了。注意设置好了以后,要断开再链接;
Windows是在“控制面板\网络和 Internet\网络连接”里找到所使用的网卡,在里面的IPv4设置里指定DNS服务器为127.0.0.1 .
然后下载类似ForceSSL的强制https的插件(Opera用户推荐“Swiss Knife”插件)。
好了,现在试试Google Plus、Facebook吧!注意如果是那些“本来就不能正常的网站”一定得是https模式哦!比如https://plus.google.com,https://www.facebook.com

相关服务商:https://dnscrypt.eu
---

先编译“依赖”libsodium:
git clone https://github.com/jedisct1/libsodium
cd libsodium
bash autogen.sh (此命令会生存configure文件)
./configure
make
make install
----------

使用DNSCrypt-proxy建立安全的本地DNS解析服务 
DNS污染是防火长城的一部分,具体说明可以去维基下。防DNS污染工具比较多,如Pcap_DNSProxy、DNSForwarder、ChinaDNS等等都是非常优秀的抵制DNS投毒工具,但使用配置较为复杂,而DNSCrypt则简单多了。
【dnscrypt在windows的使用方法】
1.首先下载LATEST-win32-full.zip后解压。
2.将文件重命名为DNSCrypt-Proxy放置c:\目录下。
3.下载dnscrypt-resolvers.csv,将DNSCrypt-Proxy里的替换。
4.看看列表公共DNS服务器并选择要使用的一个(例如: fvz-rec-hk-ztw-01 )。
5.打开CMD命令运行: dnscrypt-proxy -R fvz-rec-hk-ztw-01 --test=0
如果出现错误,重试不同的服务器。
6.启用该服务: dnscrypt-proxy -R fvz-rec-hk-ztw-01 --install
7.到目前为止已经配置好,最后记得修改本地DNS服务器为 127.0.0.1  。
注意:在Windows 8.1和Windows 10,按Windows键+ X键,然后选择“Windows命令提示符(管理员)”或“Windows PowerShell中(管理)”。
【卸载方法】
打开CMD命令运行: dnscrypt-proxy --uninstall
更多服务器:dnsrec
【手机安装方法 – 需root】by Ray Walker
首先下载Android最新版,目前是1.6.0 dnscrypt-proxy-android-armv7-a-1.6.0.zip
下载以后,解开压缩包,提出里面sbin下面的dnscrypt-proxy文件,复制到/system/xbin下,设置属性为可执行。
启用dnscrypt-proxy可通过/system/etc/install-recovery.sh实现,我的手机安装了SuperSU,install-recovery.sh已被SuperSU修改为:
#!/system/bin/sh
# If you’re implementing this in a custom kernel/firmware,
# I suggest you use a different script name, and add a service
# to launch it from init.rc
# Launches SuperSU in daemon mode only on Android 4.3+.
# Nothing will happen on 4.2.x or older, unless SELinux+Enforcing.
# If you want to force loading the daemon, use “–daemon” instead
/system/xbin/daemonsu –auto-daemon &
# Some apps like to run stuff from this script as well, that will
# obviously break root – in your code, just search this file
# for “install-recovery-2.sh”, and if present, write there instead.
/system/etc/install-recovery-2.sh
为避免影响root,通过/system/etc/install-recovery-2.sh启用 dnscrypt-proxy。如果 /system/etc/install-recovery-2.sh存在,则直接编辑。否则创建这个文件,设置为可执行,再编辑。
如果 install-recovery.sh没有被修改过,直接用来启动dnscrypt-proxy即可。
启用dnscrypt-proxy可参考dnscrypt.org网站的指南,一个简单的示例,在shell脚本里增加以下代码:
# start dnscypt-proxy daemon
/system/xbin/dnscrypt-proxy –daemonize \
–provider-name=2.dnscrypt-cert.opendns.com \
–provider-key=B735:1140:206F:225D:3E2B:D822:D7FD:691E:A1C3:3CC8:D666:8D0C:BE04:BFAB:CA43:FB79 \
–resolver-address=208.67.220.220:443 &
# set DNS to localhost
setprop net.dns1 127.0.0.1
虽然DNSCrypt-Proxy能有效防止DNS污染,但是解析国内网站较慢.
---------------------------------------------------------------------------------

有什么用处(dnscrypt-proxy)

  • DNS 流量加密和身份验证(支持 TLS 1.3、DNSCrypt 和 DNS over HTTPS(DoH))
  • DNS 查询监控,具有用于常规和可疑查询的单独日志文件
  • 过滤:屏蔽广告,恶意软件和其他不需要的内容。兼容所有 DNS 服务
  • 基于时间的过滤,具有灵活的每周计划
  • 将特定域透明重定向到特定解析器
  • DNS 缓存,以减少延迟并提高隐私
  • 本地阻止 IPv6 查询,可减少仅 IPv4 网络的延迟
  • 负载均衡:选择一组解析器,dnscrypt-proxy 将自动测量并跟踪其速度,并在最快的可用速率之间平衡流量
  • 伪装:像 hosts 文件一样,可以返回特定名称的预配置地址,或者解析并返回其他名称的 IP 地址。这可用于本地开发以及在 Google、Yahoo 和 Bing 上实施安全搜索结果
  • 解析器列表的自动后台更新
  • 可以强制传出连接使用 TCP 协议
  • 支持前置 Socks 代理
  • 支持 DNSSEC 查询.
------------------------------------------------------------------------------------------------------------------

使用dnscrypt-proxy解决DNS被污染的问题

dnscrypt-proxy是Gayhub上面的一个开源项目,项目本身就提供给了我们很多免费的公共DNS可用,如果你不想自建服务器的话用免费的也是可以的,只是DNS解析的速度会比较慢。
自建的话找一台线路好的机器,解析速度还是比公共的要快不少的,自建也很简单,官方都提供好了docker镜像。下面我在一台CentOS7X64的机器上进行安装。
首先安装docker:
cd
yum -y install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.06.1.ce-3.el7.x86_64.rpm
systemctl start docker
systemctl enable docker.service
然后一条命令就可以安装了:
docker run --name=dnscrypt-server -p 443:443/udp -p 443:443/tcp --net=host jedisct1/dnscrypt-server init -N dns.lala.im -E 1.1.1.1:443
注:
1.dns.lala.im这个可以自己随便更改,即便是一个不存在的域名都可以。
2.1.1.1.1更改为你的服务器公网IP
3.443这个端口不能更改。
稍等一会就安装好了,会回显给你一串类似这样的sdns代码,复制保存好.
启动服务:
docker start dnscrypt-server
设置开机启动:
docker update --restart=unless-stopped dnscrypt-server
这样服务端就搭建好了,接下来是客户端,首先在这里下载符合你系统的客户端:
https://github.com/jedisct1/dnscrypt-proxy/releases
这里我以Win10为例,解压之后先复制一份配置文件保存为dnscrypt-proxy.toml,
然后编辑dnscrypt-proxy.toml,注释掉公共服务器这块.
------------------------------------------------------------------------

TLS 加密实际上就是我们上网的 HTTPS 所用加密了,安全性得到了很好的保障——这东西如果失效了,那整个互联网估计也就完蛋了。

DoT 使用 853 端口,使用 TCP 进行传输——基本上可以理解为加密版本的普通 DNS 了。
现如今,DoT 已经有了相当成熟的客户端,使用 brew install stubby 即可安装,再使用 sudo brew services start stubby 就能启动了,stubby 推荐使用默认配置,已经集成了多个可信的 DoT 服务器。我这边测试查询速度为最慢 1 秒……是的,你还是需要一个前置的 DNS 缓存服务,比如 dnsmasq,这里我就直接用 Surge 充当了。
(运行brew install stubby,显示:
To have launchd start stubby now and restart at startup:
  sudo brew services start stubby
Or, if you don't want/need a background service you can just run:
  sudo stubby -C /usr/local/etc/stubby/stubby.yml
==> Summary

🍺  /usr/local/Cellar/stubby/0.2.6: 20 files, 147.9KB)

https://zh.wikipedia.org/wiki/DNS_over_TLS
https://zh.wikipedia.org/wiki/DNS_over_HTTPS
----------------------------

dnscrypt-autoinstall

Automatic installation and configuration of DNSCrypt (on Debian + Redhat like systems). This script will install DNSCrypt and configure it to start on boot and use an optional dnscrypt service.


A script for installing and automatically configuring DNSCrypt on Linux-based systems.

Description

DNSCrypt is a protocol for securing communications between a client and a DNS resolver by encrypting DNS queries and responses. It verifies that responses you get from a DNS provider have actually been sent by that provider, and haven't been tampered with.
This script will automatically and securely set up DNSCrypt as a background service that runs at system startup using DNSCrypt-proxy, the libsodium cryptography library, and the DNSCrypt service provider of your choice. The script also has options that allow you to change the service provider at any time, turn off DNSCrypt to use regular unencrypted DNS, as well as uninstall DNSCrypt.

Installation

The script supports recent Red Hat-based (CentOS, Fedora, Scientific Linux), Debian-based (Debian, Ubuntu, Linux Mint) distributions and OpenSUSE.
NoteScripts with sysvinit support were moved to the "legacy" branch (CentOS 6, Debian 7, Ubuntu < 16.04)
wget https://raw.githubusercontent.com/simonclausen/dnscrypt-autoinstall/master/dnscrypt-autoinstall
chmod +x dnscrypt-autoinstall
su -c ./dnscrypt-autoinstall

Supported providers

Providers are retrieved from the latest published dnscrypt-resolvers.csv (github.com/jedisct1), with a fallback to those included with the DNSCrypt installation.

Troubleshooting

If the install fails at a particular stage and the script mentions DNSCrypt is already configured, use the forcedelargument to force an uninstallation:
./dnscrypt-autoinstall.sh forcedel
from https://github.com/simonclausen/dnscrypt-autoinstall
---------------

This project is suspended but pull requests are still accepted. I hope I'll be able to work on it at a later time. - RandomDNS makes DNS secure. It's based on DNSCrypt but we've added a bunch of new cool features.

RandomDNS aims to improve the security, privacy and anonymity of DNSCrypt. It can randomize the server choice at runtime and can rotate it frequently.
What is DNSCrypt?
DNSCrypt is a protocol that authenticates communications between a DNS client and a DNS resolver. It prevents DNS spoofing. It uses cryptographic signatures to verify that responses originate from the chosen DNS resolver and haven't been tampered with.
More informations at https://dnscrypt.org/

Features of RandomDNS

  • Randomize the provider at runtime
  • Use (-E)phemeral keys option
  • Securely run DNSCrypt proxy by verifying its hash, copying it in /tmp dir with restricted permissions and launching it as "nobody" user (if reverse proxy is enabled)
  • Watch the proxy process and relaunch it if it dies
  • Can run multiple instances of DNSCrypt and load balance the traffic (EdgeDNS)
  • Have in-memory caching of DNS requests along with Consistent Hashing (EdgeDNS)
  • Can filter the server list by protocols, country and much more
  • Rotate the server with a defined time (default: 10 minutes)
  • Support DNSSEC (EdgeDNS)

How to use it

  1. Update Brew: brew update && brew upgrade
  2. Install DNSCrypt + Node + NPM: brew install dnscrypt-proxy node npm
  3. Download and run RandomDNS: npm install -g randomdns && sudo DEBUG=* randomdns
  4. Set your DNS settings to 127.0.0.1

Help

      ___               __           ___  _  ______
     / _ \___ ____  ___/ /__  __ _  / _ \/ |/ / __/
    / , _/ _ `/ _ \/ _  / _ \/  ' \/ // /    /\ \  
   /_/|_|\_,_/_//_/\_,_/\___/_/_/_/____/_/|_/___/  


     Usage: run [options] [file]

     Options:

       -h, --help                              output usage information
       -V, --version                           output the version number
       -L, --listenOn [string]                 Listen on a specific interface/port [default: 127.0.0.1:53]
       -R, --rotationTime [int]                Define the time to wait before rotating the server (in seconds) [default: 600 seconds]
       -P, --reverseProxy [bool]               Enable EdgeDNS reverse proxy [default: false]
       --reverseProxyChildStartPort [int]      Where childrens (dnscrypt-proxy processes) should start incrementing the port? (will work only if reverseProxy is enabled) [default: 51000]
       -T, --threads [int]                     Number of childs to spawn, set to 1 to disable load balacing (will work only if reverseProxy is enabled) [default: 4]
       -F, --filters [string]                  Use filters [default: IPv6=false;]
       --filters-help                          Get full list of available filters.
       -b, --binaryDNSCryptFile [string]       Use custom DNSCrypt binary, will not work until --binaryDNSCryptFileSignature is changed.
       --binaryDNSCryptFileSignature [string]  SHA512 hash of the DNSCrypt binary.
       -b, --binaryEdgeDNSFile [string]        Use custom EdgeDNS binary, will not work until --binaryEdgeDNSFileSignature is changed.
       --binaryEdgeDNSFileSignature [string]   SHA512 hash of the EdgeDNS binary.
       -r, --resolverListFile [string]         Use custom DNSCrypt resolver list file, will not work until --resolverListFileSignature is changed.
       --resolverListFileSignature [string]    SHA512 hash of the DNSCrypt resolver list file.
------------

dnscrypt-proxy-config

DNSCrypt-proxy 运行命令(管理员身份,适用Win/Mac/Linux)

dnscrypt-proxy -service install    #安装dnscrypt-proxy服务
dnscrypt-proxy -service start      #启动dnscrypt-proxy服务
dnscrypt-proxy -service stop       #停止dnscrypt-proxy服务
dnscrypt-proxy -service restart    #重启dnscrypt-proxy服务
dnscrypt-proxy -service uninstall  #卸载dnscrypt-proxy服务

服务器列表(配置使用了Cisco OpenDNS)

按国家/地区分类列表:https://mastad0n.github.io/

from https://github.com/CNMan/dnscrypt-proxy-config
--------------------------------------

Ending DNS Hijacking with DNSCrypt


I was at a Marriot hotel last week with my family and I noticed that they were doing DNS hijacking and redirecting all my DNS requests to their own servers.
It would not be a big deal, if wasn't for the fact that I had OpenDNS Family Filter setup on the laptop that the kids were using — and it wasn't working due to the DNS hijacking.

DNSCrypt to the rescue

At first, it was frustrating to see that the filters I had manually configured were not working, but I decided to take this opportunity and take my DNS privacy seriously by leveraging DNSCrypt in there.
If you are not familiar with DNSCrypt, it is a new protocol by Frank Denis and Yecheng Fu, that encrypts and authenticates all DNS traffic — Exactly what I needed to prevent any hotel or ISP from hijacking my connections.

Configuring DNSCrypt

The kids laptop are running the latest version of Ubuntu — 17.10, so in this document I will show the steps I took to get DNSCrypt configured and running there. I will be using the awesome DNSCrypt-proxy v2 by Frank Denis.
First, open your terminal and download and untar latest DNSCrypt-proxy version:
cd /opt
tar -zxvf dnscrypt-proxy-linux_x86_64–2.0.7.tar.gz
mv linux-x86_64 dnscrypt
cd dnscrypt
That will download the set the basic files for DNSCrypt-proxy inside /opt/dnscrypt. Once that part is done, you need to run some commands as root (using sudo) to install DNSCrypt:
mv example-dnscrypt-proxy.toml dnscrypt-proxy.toml
sudo ./dnscrypt-proxy -service install
[2018–03–18 19:00:10] [NOTICE] Source [https://download.dnscrypt.info/resolvers-list/v2/public-resolvers.md] loaded
[2018–03–18 19:00:10] [NOTICE] dnscrypt-proxy 2.0.7
sudo ./dnscrypt-proxy -service start
[2018–03–18 19:00:20] [NOTICE] Source [https://download.dnscrypt.info/resolvers-list/v2/public-resolvers.md] loaded
[2018–03–18 19:00:20] [NOTICE] dnscrypt-proxy 2.0.7
[2018–03–18 19:00:20] [NOTICE] Service started
Having done that part, you should have DNSCrypt-proxy running at 127.0.0.1 port 53. You can verify it is working by doing:
dig -t A google.com @127.0.0.1
; <<>> DiG 9.10.3-P4-Ubuntu <<>> -t A google.com @127.0.0.1
;google.com. IN A
google.com. 527 IN A 172.217.194.101
sudo netstat -uanep |grep dnscryp
udp 0 0 127.0.0.1:53 0.0.0.0:* 0 22777 2014/dnscrypt-proxy
All good, but now we need to configure our system to use DNSCrypt-proxy instead of the default resolver at 127.0.0.53 (from systemd). You can do it manually for testing by modifying the /etc/resolv.conf file:
echo “nameserver 127.0.0.1” > /etc/resolv.conf
And test that your DNS still works. However, that won't last after a reboot. Ubuntu have messed up with DNS since they added the systemd-resolved, making it more complicated than what it should be. I tried multiple options to stick to only 127.0.0.1 (where dnscrypt-proxy is running), but none of them would stick — or it would be rotated with the DNS server received via DHCP.
At the end, I actually disabled systemd-resolve to avoid any more issues and set 127.0.0.1 as the default nameserver:
systemctl stop systemd-resolved
systemctl disable systemd-resolved
echo “dns-nameservers 127.0.0.1” >> /etc/network/interfaces
That did the tricky and stuck between restarts. If anyone has a better way to fully override the Name server on Ubuntu 17.10, let me know.

Parental Control with DNSCrypt

The final part was to configure OpenDNS with DNSCrypt-proxy. It took me a while to realize that it is called "cisco-familyshield" in the DNSCrypt configuration (not opendns), so that alone will save you some time there.
Unfortunately, OpenDNS and DNSCrypt did not work as expected. I kept getting a timeout error, and after some troubleshooting it seems that their DNSCrypt port was down from the hotel network.
Because of that, I decided to try some other providers. Both AdGuard, Comodo and CleanBrowsing support DNSCrypt, so I tried all of them:
Mar 16 20:01:22 dnscrypt-proxy[1167]: [2018–03–18 20:01:22] [NOTICE] [adguard-dns-family] OK (crypto v1) — rtt: 204ms
Mar 16 20:01:22 dnscrypt-proxy[1167]: [2018–03–18 20:01:22] [NOTICE] [cleanbrowsing-family] OK (crypto v1) — rtt: 12ms
Mar 16 20:01:22 dnscrypt-proxy[1167]: [2018–03–18 20:01:22] [NOTICE] [comodo-02] OK (crypto v1) — rtt: 58ms
Mar 16 20:01:22 dnscrypt-proxy[1167]: [2018–03–18 20:01:22] [NOTICE] Server with the lowest initial latency: cleanbrowsing-family (rtt: 12ms)
For some reason, having all 3 together also did not work as well. I still have to research what happened, but it seems that on a NXDOMAIN, it was trying a secondary server. Plus, the comodo-02 wasn't restricting adult content via DNSCrypt — still have to understand why.
To avoid wasting more time, I decided to stick with just 1. I chose CleanBrowsing as it had the better performance of the 3 and it fared very well on my comparison between providers.
The DNSCrypt-proxy configuration is very simpple and you can set a specific provider by adding a "server_names" in the /opt/dnscrypt/dnscrypt-proxy.toml configuration file:
server_names = [‘cleanbrowsing-family’]
Once that is done, you need to restart DNSCrypt and verify it is working by trying to do a DNS lookup of an adult site:
/opt/dnscrypt/dnscrypt-proxy -service restart
$ dig por[n[hub dot com
por[n]hub.com. 22 IN SOA cleanbrowsing.rpz.noc.org. accesspolicy.rpz.noc.org. 1 7200 900 1209600 86400
;; Query time: 18 msec
And that's pretty much it. It feels harder than what it should have been, specially due to the issues with the Ubuntu DNS resolver. I envy the time back in the day when only editing /etc/resolv.conf would have been enough.
Thanks Marriot for your DNS hijacking. You made me paranoid enough to learn and setup DNSCrypt-proxy.
-------------------

相关帖子:
http://briteming.blogspot.com/2016/07/dnscrypt-wrapperdns.html (dnscrypt-proxy的服务器端)
https://briteming.blogspot.com/2015/01/dnscryptgoagent.html
https://briteming.blogspot.com/2011/12/dns-proxy-dnsdns.html
https://briteming.blogspot.com/2012/11/dnscrypt-proxy-dns-sshsocks5.html (opendns版)