Total Pageviews

Wednesday 27 January 2016

DNSCrypt for Android 简单安装步骤

简单说下配置过程。下面的步骤看着复杂,其实就 3 步:复制文件,配置自启脚本,修改 DNS 指向。

1. 首先是一些相关链接
    官网地址:http://dnscrypt.org




2. 下载的压缩包不是个 Android apk 程序。解压压缩包,解压里就一个文件是有用的:/sbin/dnscrypt-proxy

3. 这是个 shell 程序,把这个文件放到任何可以加执行权限并且系统启动时能找到的目录下,比如 /system/xbin, 加上执行权限

4. 在自启动脚本(比如 /system/etc/install-recovery.sh)里 加入一行:

/system/xbin/dnscrypt-proxy  --daemonize --loglevel=0 --max-active-requests=16 --edns-payload-size=1252 --local-address=127.0.0.1 --resolver-address=106.186.17.181:2053 --provider-name=2.dnscrypt-cert.ns2.jp.dns.opennic.glue --provider-key=8768:C3DB:F70A:FBC6:3B64:8630:8167:2FD4:EE6F:E175:ECFD:46C9:22FC:7674:A1AC:2E2A

最后 3 个参数既是 DNS 参数,可以参考官网的自己改适合的

这里你也可以在机子上安装 Script Manager,新建个脚本,脚本里添加上面这行代码,让 SM 在系统启动时自动加载这个脚本。

5. 将机子的 DNS 指向 127.0.0.1 ( Play 上有一些 App 能做这个,如果只是用在 Wifi 下,修改更容易——直接自定义 Wifi 链接即可)

至此大功告成!

PS.
1. 机子得 ROOT
2. 如果想切回国内普通 DNS,不必关闭或修改脚本,修改 DNS 指向到国内 DNS 脚本即可。不向 dnscrypt 发送查询,它不会运行(当然,会占些些内存),不会费电.
-----------
手机安装dnscrypt-proxy 

确实比较好地解决了DNS污染问题。
安装dnscrypt-proxy还是比较简单的,前提是手机必须root。
首先下载dnscrypt-proxy,网址:
http://download.dnscrypt.org/dnscrypt-proxy/
选择适合android的版本,目前是1.3.3版的:
http://download.dnscrypt.org/dnscrypt-proxy/dnscrypt-proxy-android-1.3.3.tar.gz

下载以后,解开压缩包,提出里面sbin下面的dnscrypt-proxy文件,复制到/system/xbin下,设置属性为可执行。

cd /system/xbin
chown root.root dnscrypt-proxy
chmod 755 dnscrypt-proxy

启用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 2 for Android

A flexible DNS proxy, with support for modern encrypted DNS protocols such as DNSCrypt v2 and DNS-over-HTTP/2.

Features

Installation

  • Download .zip module, flash it in Magisk Manager App or in Recovery and follow the instructions.

Set DNS server manually with 3rd-party app (not included in this module)

  • DNS server address is 127.0.0.1:5354 for ipv4 and [::1]:5354 for ipv6
  • If you use AfWall, you can write this enter custom script
    iptables -t nat -A OUTPUT -p tcp ! -d 9.9.9.9 --dport 53 -j DNAT --to-destination 127.0.0.1:5354
    iptables -t nat -A OUTPUT -p udp ! -d 9.9.9.9 --dport 53 -j DNAT --to-destination 127.0.0.1:5354
    ip6tables -t nat -A OUTPUT -p tcp ! -d 9.9.9.9 --dport 53 -j DNAT --to-destination [::1]:5354
    ip6tables -t nat -A OUTPUT -p udp ! -d 9.9.9.9 --dport 53 -j DNAT --to-destination [::1]:5354
    
    and this shutdown script
    iptables -t nat -D OUTPUT -p tcp ! -d 9.9.9.9 --dport 53 -j DNAT --to-destination 127.0.0.1:5354
    iptables -t nat -D OUTPUT -p udp ! -d 9.9.9.9 --dport 53 -j DNAT --to-destination 127.0.0.1:5354
    ip6tables -t nat -D OUTPUT -p tcp ! -d 9.9.9.9 --dport 53 -j DNAT --to-destination [::1]:5354
    ip6tables -t nat -D OUTPUT -p udp ! -d 9.9.9.9 --dport 53 -j DNAT --to-destination [::1]:5354
    

Configuration (post-installing)


  • Configuration located on /sdcard/dnscrypt-proxy/dnscrypt-proxy.toml [or /data/media/0/dnscrypt-proxy/dnscrypt-proxy.toml]
  • For more detailed configuration please refer to official documentation