Skip to content

Instantly share code, notes, and snippets.

View wen-long's full-sized avatar
☘️
wish to be lucky

wen-long

☘️
wish to be lucky
View GitHub Profile

##1.准备linux下编译环境

sudo apt-get install gcc g++ binutils patch bzip2 flex bison make autoconf gettext texinfo unzip sharutils git libncurses5-dev ncurses-term zlib1g-dev gawk libssl-dev python wget subversion xz-utils

64位系统还需

sudo apt-get install lib32gcc1 libc6-dev-i386

##2.下载源码

  • trunk (开发版):

介绍

由于GFW的域名黑名单是不断变化的,如果所有DNS查询都走VPN会丧失CDN加速功能,经常出现本地电信线路,但是却访问网站的联通线路,而且当VPN线路不稳定的时候,会影响所有网站的访问。如果使用域名白名单或黑名单,对于经常访问外国网站的用户,体验很不好,需要用户自己维护域名列表。 该文章介绍如何通过判断并丢弃包含特征IP的DNS包来防止DNS污染,但是又不会失去本地DNS的CDN加速功能,而且还不需要VPN。

前期准备

  • 一台Openwrt路由器
  • 使用dnsmasq作为Openwrt的dns服务器
  • 安装 dig (opkg install bind-dig bind-libs)
  • 安装 iptables 的 string 模块及对应的内核模块 (opkg install iptables-mod-filter kmod-ipt-filter)

##DNS

  1. 使用国内的干净的 DNS ([OPENERDNS][1] PandaDNS 中科大 DNS)
  2. 使用 TCP 或其他尚未被 GFW 干扰的 DNS 查询方式查询国外 DNS
    1. pdnsd 支持 TCP
    2. [Tcp-DNS-proxy][2]
    3. 非标准端口,[德国隐私基金会][3], [OPENDNS][4], [V2EX DNS]5
    4. [dnscrypt-proxy][7]
  3. 本地忽略虚假 DNS 应答
  4. [AntiDNSPoisoning]8[(可以参考)][9]

参考了以下两篇文献: http://blog.ch3n2k.com/2013/09/openwrt.html http://www.right.com.cn/forum/thread-128967-1-1.html

tomato路由器上已经成功部署,并且一直很稳定,openwrt的部署步骤是我按照上面的两篇文献以及tomato上的部署经验写的,但我没有真正搭建过。下面是详细的解决方案:

#一、tomato路由器 1、设置好jffs和ipkg安装环境;把附件中的geoip压缩包的内容放入/opt/etc/geoip(或者/jffs/opt/etc/geoip)目录下。

2、在系统管理——脚本设置——wan连线中输入以下内容:

介绍
IPTables是一个比较灵活的模块化的防火墙。如果它当前不能够精确的检测具有某些特征的包,你可以选择自己写一个或者是修改一个现存的检测模块。但问题是我们大多数人并不是程序员,虽然有那么多开源的dd。
我们有一个选择是不需要写代码的。好心的Don Cohen写了个IPTables的模块,该模块从数据包中抽出你所感兴趣的一些字节,进行一些操作,看看得到的结果是否在指定的范围之内。比如,我可以获取IP头的Fragmentation信息,丢弃More Fragments标记以外所有的东西,看看它是否设置了这个标记。
根本不需要写任何的C代码 ;-)
我在这里所要做的就是介绍核心概念,还加入了希望是足够多的带注释的例子,使你能够编写自己的检测模块。
iptables -t nat -N SHADOWSOCKS
iptables -t nat -A SHADOWSOCKS -p tcp --dport 23596 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 10.0.0.0/8 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 127.0.0.0/8 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 169.254.0.0/16 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 172.16.0.0/12 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 192.168.0.0/16 -j RETURN
@wen-long
wen-long / 0_reuse_code.js
Created March 30, 2014 14:30
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@wen-long
wen-long / openwrt 端口重定向设置.config
Created March 31, 2014 14:36
LUCI下使用的,文件在`/etc/config/firewall`
config redirect
option target 'DNAT'
option src 'wan'
option dest 'lan'
option proto 'tcp'
option src_dport '80-90'
option dest_ip '192.168.8.216'
option dest_port '80'
option name '树莓派 WEB'

注意: 这篇文章假设你有GitHub账号以及了解基本的Git知识

页面访问地址: http://username.github.io/repository/

创建GitHub仓库

  // 拉取远程仓库至本地  
  git clone https://github.com/user/repository.git
  // 打开本地仓库
  cd repository