用ssh加密DNS查询的方法

2011年8月13日 | 分类: 翻墙相关 | 标签: , ,

现在解决DNS污染的方法一般是通过修改使DNS使用TCP协议传输和通过延迟DNS查询舍弃GFW干扰的IP来获得真实IP。这两种方法的原理不同,通过修改使DNS使用TCP协议传输的原理是DNS传输默认使用UDP传输所以GFW的DNS污染也是在UDP传输层,至少现在还没有干扰TCP传输层的DNS请求,所以使用TCP协议请求的DNS查询目前是不受DNS污染的,不过不能保证以后GFW不会这么干;通过延迟DNS查询的原理是这样的,GFW的DNS污染是这样的,比如你电脑发出一个域名的DNS查询请求就会通过域名服务器查询,这个过程中GFW检测在其黑名单里的域名,然后迅速返回给你的电脑一个假IP,而你的电脑却把它当成真的了,等一会DNS服务器查询到的真实IP返回给你就会被系统舍弃,DNS污染就这么着发生了,如果你通过软件延迟DNS查询,等待真实IP返回再返回给系统,这样就解决了DNS污染。(域名服务器缓存污染

不过即使这两种都被干扰了你也可以使用VPN或ssh加密DNS查询。

使用VPN的方法可以参考 http://igfw.net/archives/2483 修改路由表让8.8.8.8通过vpn然后设置本机DNS为8.8.8.8,不过这个对个人翻墙就画蛇添足了。

用ssh加密DNS查询的方法还是有用的,以下是网友路人甲提供的方法,有兴趣的可以研究下。

我找到一个可以用ssh加密DNS查询的方法
用plink命令, 把下文“密码”“用户名”“SSH服务器端口”“SSH服务器地址” 改成你找到的SSH帐号

plink -N -v -D 127.0.0.1:5123 -L 8853:8.8.8.8:53 -pw 密码 -l 用户名 -P SSH服务器端口 SSH服务器地址

这条命令运行后可以把本地的127.0.0.1:8853当成是8.8.8.8:53的google DNS,因为做了端口转发。在网卡
的DNS设定上改成127.0.0.1:8853就可以用SSH加密向8.8.8.8做DNS查询了。
(同时这命令也开了一个127.0.0.1:5123的本地端口做socks5代理,这样SSH帐号就物尽其用了)

再结合dnsproxy.exe的cn域名用国内DNS查询的功能就十分完美了。既100%不被DNS污染也不会损失速度。

==========================================================================

说漏了,127.0.0.1:8853要加在dnsproxy.exe的data/dnsproxy.conf里用,windows不能直用127.0.0.1:8853
因为windows只支持标准的53端口DNS服务器。

不过在XP里可以把8.8.8.8的53端口转成本机的53端口,那命令改成这样
plink -N -v -D 127.0.0.1:5123 -L 53:8.8.8.8:53 -pw 密码 -l 用户名 -P SSH服务器端口 SSH服务器地址

win7里如果不想用dnsproxy.exe,又想用8.8.8.8就用psexec那招来绑定本机53端口吧。

===========================================================================

这个是为了以后,如果TCP查询DNS的方式也被关键字过滤封杀,预先作打算。

Linux里也能用这样的端口转发,把plink改成ssh就行了(本来plink就是win版的ssh)

ssh -N -v -D 127.0.0.1:5123 -L 53:8.8.8.8:53 -pw 密码 -l 用户名 -P SSH服务器端口 SSH服务器地址

8.8.8.8的53端口就变成本机127.0.0.1的53端口了,如果本机开了DNS服务不能转发成本机53,
那就改成别的端口,然后加到本机DNS服务的上游DNS列表里。
比如改成8853端口

plink -N -v -D 127.0.0.1:5123 -L 8853:8.8.8.8:53 -pw 密码 -l 用户名 -P SSH服务器端口 SSH服务器地址

==================================================================================

把命令写到批处理文件里就行了(bat或cmd后缀的txt文件),以后双击批处理运行就不用次次打一样的命令了。

顺便说说plink从哪下,去putty主页下载plink新版, 在那堆文件列表里点plink.exe
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

之前的命令去掉端口转发就是一个纯粹连接ssh做socks5代理的命令。
例如连接SSH做个127.0.0.1:1080的socks5代理

plink -N -v -D 127.0.0.1:1080 -pw 密码 -l 用户名 -P SSH服务器端口 SSH服务器地址

注意:
那些参数 -N -v -D 之类的都是大小写敏感的,大写N或D之类的不能换成小写的。

快可以写一个plink教程了…..

有些内容可能要参考http://igfw.net/archives/4300路人甲提供的方法。

本文原始地址http://igfw.net/archives/4408

  1. yourshell.info
    2012年9月19日00:32

    应该是把 8.8.8.8:53 改成 127.0.0.1:8853,之后在 网络 中的 DNS 指向 127.0.0.1

  2. i5Mao
    2011年8月15日21:22

    上文有点乱,没完全看懂:

    1.“127.0.0.1:8853要加在dnsproxy.exe的data/dnsproxy.conf里用”,是用“127.0.0.1:8853”来对第29行
    “listen_tcp(53, “127.0.0.1”)”进行修改吗,还是下一行“listen_udp(53, “127.0.0.1”)”。

    2.我使用的是WIN7,是跟XP一样使用命令
    plink -N -v -D 127.0.0.1:5123 -L 53:8.8.8.8:53 -pw 密码 -l 用户名 -P SSH服务器端口 SSH服务器地址
    还是使用原来的命令
    plink -N -v -D 127.0.0.1:5123 -L 8853:8.8.8.8:53 -pw 密码 -l 用户名 -P SSH服务器端口 SSH服务器地址?

    3.执行“plink”命令后,窗口能否关闭,使用时是否需要运行“dnsproxy.exe”。

    4.还没发现……

    上帝,请原谅我的无知,阿门……

    • iGFW
      2011年8月16日10:46

      使用命令plink -N -v -D 127.0.0.1:5123 -L 8853:8.8.8.8:53 -pw 密码 -l 用户名 -P SSH服务器端口 SSH服务器地址
      窗口不关闭
      使用时需要运行“dnsproxy.exe”
      应该是“listen_tcp(53, “127.0.0.1″)”

      • i5Mao
        2011年8月16日21:51

        很可惜,不知道哪出问题了,还是用不了“ssh加密DNS查询”……

        东西设置好后,若先运行“plink”命令,好像能连上SSH,但是运行不了“dnsproxy.exe”,双击后一闪就关了,经过截图后看到出现了一句“Couldn’t listen on 127.0.0.1:8853: [Errno 10048]”;尝试使用“psexec -s -i cmd.exe”、“start dnsproxy.exe”命令,但结果还是一样……

        若先运行“dnsproxy.exe”,“dnsproxy.exe”也能连上,但是运行“plink”命令后会出现“Local port 8853 forwarding to 8.8.8.8:53 failed: Networ error: Permission denied”,同样失败。看来这玩儿不适合我……

        • iGFW
          2011年8月17日08:01

          呵呵,这玩意我也搞不定。

  3. AS
    2011年8月15日13:18

    http://www.trishtech.com/downloads/dnstool/index.php
    “Public DNS Server Tool is a small utility for changing the DNS servers in Windows XP, Vista and 7 on the fly.”
    “I have seen that recently many public DNS servers have been made available for everyone’s use. Some of them are OpenDNS, Google, Norton etc. These DNS servers offer many security and protection layers in addition to being very fast. Even though these public DNS servers are available for everyone’s use, setting DNS servers in Windows is not an easy task. Therefore, I have created this little tool Public DNS Servers Tool, using which you can easily set your DNS servers in Windows.
    It has been tested to work in Windows XP Professional SP3 (32-bit), Windows XP Professional SP2 (64-bit), Windows Vista SP2 (32-bit) and Windows 7 (32-bit).
    You can use a Public DNS Server Tool to either set a group of DNS servers manually, or you can choose a preset pair of public DNS servers. Currently, it has seven preset pair of DNS servers —
    Google Public DNS
    OpenDNS
    OpenDNS Family Shield
    Norton DNS
    Comodo Secure DNS
    Scrub DNS
    DNS Advantage

    Setting public DNS servers
    Download Public DNS Server Tool to your computer.
    Unzip it to any folder you want on your hard disk.
    Run Public DNS Server Tool by double-clicking on public_dns_tool.exe………”

    http://www.softpedia.com/get/Internet/Other-Internet-Related/Google-DNS-Helper.shtml
    “DNS Helper (formerly Google DNS Helper) description
    A simple utility to quickly switch over to popular free DNS providers and also your own custom DNSs with backup/restore functionality.
    DNS Helper is the successor to the hugely popular Google DNS Helper. It’s a small tool that will backup your current DNS address and then switch it to Google Public DNS for a faster, safer, more reliable internet experience. It runs in the system notification area and provides a popup menu to switch your DNS servers in a single click.”

    http://mayakron.altervista.org/support/browse.php?path=Acrylic&name=Home

    (用ssh加密DNS查询的方法)

    • iGFW
      2011年8月15日13:26

      感谢支持。

      • 2011年8月15日14:03

        不知道你有没有注意到,8.8.8.8这个IP是有被DNS污染,而8.8.4.4却没有

        • iGFW
          2011年8月15日14:37

          嗯,这个我注意到了,所以我以前的多篇文字中都是使用8.8.4.4代替8.8.8.8

  4. AS
    2011年8月14日18:02

    http://code.google.com/p/endlessssh/
    “endlessssh(all characters in lower case), is a tool written in Python, includes an SSH ProxyCommand and a ProxyServer. It gives you a chance to keep a ssh session never break, even if you move you computer(ssh client runs on) from office to home.

    endlessssh use a protocol that looks like HTTP to tunnelling SSH. In future, the protocol will be imporved to work more like HTTP, as to use SSH when the firewall forbids SSH – as long as the firewall doesn’t forbid HTTP.

    Usage:
    1. Proxy Server usally runs on the same machine on which sshd(SSH server) is running. Edit server_conf.py, add the IP address of ssh_proxy to allow hosts list, the run:

    python server.py 8888
    2. SSH client, connect to sshd

    ssh -o “ProxyCommand python ssh_proxy.py sshd_host 8888 %h %p” user@sshd_host
    工具有两个特点:

    1. Tunneling SSH over REAL HTTP(完善中)

    让 SSH 工作在 HTTP 协议上, 从而穿越防火墙.

    2. 持续的会话

    即使 TCP 网络连接断开(这时, SSH 会话会失效), SSH 会话仍然保持, 直到网络重连后, 会话继续”
    http://code.google.com/p/endlessssh/downloads/list

  5. 2011年8月13日23:27

    路人甲真是热心肠,如果他有blog的话,一定得订阅

    • iGFW
      2011年8月14日08:04

      呵呵呵

    • 路人甲
      2011年8月15日03:15

      iGFW 和 AS 才是真的热心肠,我只是路过打酱油的。
      感谢iGFW 和 AS