用户工具

站点工具


shadowvpn

ShadowVpn

ShadowVPN 是一个基于 libsodium 的高速、安全的 VPN。特别为低端硬件,如 OpenWRT 路由器设计。 https://shadowvpn.org/ https://github.com/clowwindy/ShadowVPN

优势

无状态VPN,低负载低资源占用,适合安装在OpenWRT上,在没有限制UDP包数量的网络环境上速度飞快(例如校园网),在联通/移动线路上速度快于ShadowSocks电信就不要想了,用什么都是这么慢。

安装

编译

sudo apt-get install build-essential automake libtool
git clone https://github.com/clowwindy/ShadowVPN.git
git submodule update --init
./autogen.sh
./configure --enable-static --sysconfdir=/etc
make && sudo make install

编译为deb包

sudo apt-get install build-essential automake libtool gawk debhelper
git clone https://github.com/clowwindy/ShadowVPN.git
git submodule update --init
./autogen.sh
dpkg-buildpackage
sudo dpkg -i ../shadowvpn_xxx.deb

添加第三方源

Debian 7Ubuntu 12+可以添加下一行到/etc/apt/sources.list

deb http://shadowvpn.org/debian wheezy main

然后安装deb包即可:

sudo apt-get update
sudo apt-get install shadowvpn
sudo service shadowvpn restart

路由表

VPN是全局的,在访问国内网站时速度不佳,而且会暴露自己代理服务器IP,所以有必要配置路由表绕过国内网站。

这里采用chnroutes + ipset白名单的方式实现绕过国内网站。其中chnroutes可绕过所有国内的IP,ipset作为补充方案,指定你不想经过VPN访问的网站。

生成chnroutes

获取chnroute.txt

curl 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | grep ipv4 | grep CN | awk -F\| '{ printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > chnroute.txt

使用下面的gen_chnroutes.sh生成chnroutes.sh

#!/bin/sh

path=$(dirname $0)

list=$(grep -E "^([0-9]{1,3}\.){3}[0-9]{1,3}" $path/chnroute.txt |\
    sed -e "s/^/route \$action /" -e "s/$/ \$suf/")

cat <<-EOH > $path/chnroutes.sh
        #!/bin/sh

        if [ "\$1" = "down" -o "\$1" = "del" ]; then
            action=del
        else
            action=add
            suf="via \$(ip route show 0/0 | grep via | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}')"
        fi

        ip -batch - <<EOF
        $list

route \$action 172.16.0.0/12 \$suf
route \$action 192.168.0.0/16 \$suf
        EOF
EOH

配置ipset

使用下面脚本设置ipset

#!/bin/bash
 
if [ "$1" = "down" -o "$1" = "del"  ]; then
    ip rule del table cndirect
    ipset destroy whitelist
    iptables -t mangle -D fwmark -m set --match-set whitelist dst -j MARK --set-mark 0xffff
    iptables -t mangle -F PREROUTING
    iptables -t mangle -X fwmark
    exit
fi
 
suf="via $(ip route show 0/0 | grep via | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}')"
 
# restore ipset conf
#ipset restore /etc/ipset.conf
[ $(ipset list whitelist 2>/dev/null| wc -l) -eq 0 ] && { ipset -N whitelist iphash; }
 
iptables -t mangle -N fwmark
iptables -t mangle -A PREROUTING -j fwmark
# optional
#iptables -t mangle -A OUTPUT -j fwmark
 
iptables -t mangle -A fwmark -m set --match-set whitelist dst -j MARK --set-mark 0xffff
# echo "99 cndirect" >> /etc/iproute2/rt_tables
ip rule add fwmark 0xffff table cndirect
ip route add default dev enp8s0 table cndirect

配置dnsmasq

dnsmasqipset配置格式如下:

ipset=/.douban.com/whitelist
shadowvpn.txt · 最后更改: 2023/12/03 10:24 由 127.0.0.1