Giter Site home page Giter Site logo

aufow's Introduction

Aufow -- Autoddvpn for OpenWrt

此工程主要贡献来自于autoddvpnopenwrt-smarthosts-autoddvpn。主要在OpenWrt路由上实现autoddvpn的效果。

本来已经在ddwrt路由上搭好audoddvpn,在这里可以找到一些常用的脚本。不过最近从ddwrt转移到OpenWrt上,因为发现OpenWrt更加灵活,可玩度更高一些。此工程是在audoddwrt现有的代码及脚本基础上移植并应用在OpenWrt+Openvpn上的。

效果

实现无痛翻墙并支持翻墙网站及ip的定期自动更新。

条件

本方案在以下条件下测试通过:

  • OpenWrt 12.09
  • Openvpn

openwrt-smarthosts-autoddvpn就是基于OpenWrt+PPTP的,

效果

GFW的手段主要手段及解决办法:

  • DNS污染:利用OpenWrt的dnsmasq来提供dns服务,并指定使用Google DNS来查询这些受污染的网址
  • 连接重置:通过openvpn来访问这些被封的ip

生成routes

openvpn启动后会运行vpnup.sh脚本来加载需要通过vpn访问的ip,关闭时通过vpndown.sh来从路由表中移除这些ip。

vpnup.sh会用到以下4个文件,确保这几个文件在vpnup.sh脚本所定义的PWD目录下。

静态路由

  • basic_routes: 一些最基本的ip,如Google DNS等,这个文件基本固定不变。
  • gfw_routes: 从http://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt上获取的被GFW和谐掉的ip
  • custom_routes: 从自定义的custom_domains文件的域名中解析出来的ip
  • except_routes: 从自定义的except_domains文件的域名中解析出来的ip,这里指定某些特定的ip不通过vpn。
  • fixed_ip_routes: 固定IP的网站(在fixed_ip_domains中定义的)的ip地址。

dnsmasq配置文件

以下文件在要放在/etc/dnsmasq.d文件夹当中,具体见下文。

  • autoddvpn.conf: 最基本的被DNS污染的网站。
  • fixed_ip_domain.conf: 由fixed_ip_domains的生成的固定网站/ip对。

以上4个文件中,basic_routes固定不变,其他3个可以通过以下方法生成:

  • custom_domains里加入你想要通过vpn走的域名
  • excep_domains里加入你不想要通过vpn走的域名
  • 运行 python freeway.py

要有dnspython支持,安装运行:sudo pip install dnspython

dnsmasq

把那些被污染的网址,通过Google DNS查询出真实的ip地址,并把这些ip地址放入dnsmasq的配置中。

在dnsmasq配置文件/etc/dnsmasq.conf中添加以下代码:

conf-dir=/etc/dnsmasq.d

如果此目录不存在的话,新建一个:

mkdir /etc/dnsmasq.d

autoddvpn.confgfwdomains放入此文件夹,并重启dnsmasq:

/etc/init.d/dnsmasq restart

此时你查询返回的就应该是正确的ip地址了lol

DNS设置

网络设置中,打开LAN接口设置,可以在使用自定义DNS服务器中填入以下:

199.91.73.222
8.8.8.8

分别是V2EX和Google的DNS服务器

openvpn

注意:操作前确保你有足够的空间,一般8M的Flash都足够了,4M的可能就不够,可以插个USB上去

主要安装参考openwrt官网

安装

opkg update
opkg install openvpn

新建一个文件夹并把所有与openvpn有关的文件都放在这个目录下

mkdir /mnt/etc/openvpn

注意:也可以在在其他位置,不过与此有关的路径都要做相应的修改

/etc/config/network为openvpn加一个接口

config interface 'vpn'
	    option ifname 'tun0'
    	option defaultroute '0'
    	option peerdns '0'
    	option proto 'none'

openvpn的配置在/mnt/etc/openvpn/openvpn.conf,具体参考autoddvpn。注意vpnup.shvpndown.sh以及那些key的路径。

vi /etc/config/openvpn

package openvpn
config openvpn vpn
    option client 1
    option enabled 1
    option config /mnt/etc/openvpn/openvpn.conf

启动

/etc/init.d/openvpn start

开机启动

/etc/init.d/openvpn enable

配置防火墙

注意:以下的端口与协议要跟你openvpn配置里的一致,以下用的是openvpn的默认配置:udp协议及1194端口。

vi /etc/config/firewall

## 增加以下内容
config 'include'
    option 'path' '/etc/firewall.user'

config 'rule'
    option 'target' 'ACCEPT'
    option 'name' 'VPN'
    option 'src' 'wan'
    option 'proto' 'udp'
    option 'dest_port' '1194'

## 自定义防火墙内容
vi /etc/firewall.user

## 增加以下内容
iptables -t nat -A prerouting_wan -p udp --dport 1194 -j ACCEPT
iptables -A input_wan -p udp --dport 1194 -j ACCEPT

iptables -I INPUT -i tun+ -j ACCEPT
iptables -I FORWARD -i tun+ -j ACCEPT
iptables -I OUTPUT -o tun+ -j ACCEPT
iptables -I FORWARD -o tun+ -j ACCEPT

## 重启firewall
/etc/init.d/firewall restart

自动更新

update_files.sh脚本会从指定网站下载新版本的路由及dnsmasq配置文件。只要在服务器上定时运行freeway.py脚本更新以上文件(主要是GFW路由)。这个脚本利用了wget的时间戳--timestamping or -N,来检查服务器的版本是否比本地的新,如果是的话就下载,不是的话就不下载。

需要根据情况修改路径及网站:

  • DIR: 这些文件所在路径
  • DOMAIN: 放这些文件的网址

定期执行

通过Web界面或直接修改/etc/config/cron来添加cron任务。如:

0 11 * * * /etc/openvpn/update_files.sh 

运行/etc/init.d/cron start后,会自己生成vi /etc/crontabs/root

启动并让它开机运行

/etc/init.d/cron start
/etc/init.d/cron enable

大功告成!😄

测试

重启一下路由,运行下面命令看vpn是否工作正常,正常情况下你应该看到它通过的是你VPN的ip,如10.8.0.1

traceroute facebook.com

aufow's People

Contributors

lincank avatar

Stargazers

 avatar leo avatar  avatar  avatar ObjectNotFound avatar zhoushun avatar Cool avatar  avatar 魏涛 avatar leo avatar Finn avatar Goodev avatar Dapeng Wei avatar  avatar Jinlong Quan avatar  avatar cardozo avatar madfrog avatar Angus H. avatar dongger avatar Simon Ren avatar  avatar  avatar  avatar yasinn avatar  avatar Eric Zhang avatar 伊冲 avatar eddix avatar welsen avatar  avatar  avatar  avatar zeroinyang avatar x avatar Steven Lee avatar Douglas Lee avatar Qiang Luo avatar 唐睿 avatar

Watchers

伊冲 avatar  avatar James Cloos avatar Jinlong Quan avatar leo avatar  avatar  avatar lucky lin avatar

aufow's Issues

非常棒的项目,希望作者能够持续更新

我也是从dd-wrt使用到openwrt。autoddvpn是一个可以长期使用的项目。
换到op以后,自动vpn遇到了很多问题,
openwrt-smarthosts-autoddvpn有一定的启发但是smarthost和dnsmasq好像有一定的冲突,并且默认路由太少了,于是我在网上搜索gfwlist生成ip搜索到这个新项目。
非常的完美,虽然我依然使用的pptp,但作者提供的几个路由表和dnsmasq配置最完善,现在route已经设定每天6点自动checkout gfw的domain和route,希望可以经常更新。
虽然您提供了freeway.py 但是不可以在openwet中执行,所以还是svn更新配置更方便!
非常棒!nice!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.