Introduction
由于众所周知的原因,在大陆无法正常使用某些资本主义网站给科学研究工作带来了诸多不便。知名代理协议Shadowsocks由于开发较早、使用人数多而沦为rbq,成为了精准打击对象,封锁力度较大。
Project V 是一个工具集合,它可以帮助你打造专属的基础通信网络。Project V 的核心工具称为V2Ray,其主要负责网络协议和功能的实现,与其它 Project V 通信。V2Ray 可以单独运行,也可以和其它工具配合,以提供简便的操作流程。Project V 是一个工具集合,它可以帮助你打造专属的基础通信网络。Project V 的核心工具称为V2Ray,其主要负责网络协议和功能的实现,与其它 Project V 通信。V2Ray 可以单独运行,也可以和其它工具配合,以提供简便的操作流程。
Project V 官方网站
V2Ray 使用 Go 语言编写,可跨平台运行,包括基于 Linux 的嵌入式操作系统,如 OpenWRT 。我们的目标是将 V2Ray 运行在使用 OpenWRT 操作系统的路由器上,以便网关后的设备无需额外配置即可使用代理。以下步骤在安装了 OpenWrt 18.06.2 的 NETGEAR WNDR4300 路由器测试可行。
V2Ray 白话文教程提供了一种简单的透明代理方案,该方案使用 V2Ray 内置的 GeoIP 和域名白名单,利用 V2Ray 自带的路由功能,使白名单内站点直通,其余走代理,可满足绝大部分应用场景,若无特殊需求参考该文配置即可。
由于该白名单并不完整,只收录了常用境内站点,误杀概率较大。为了最大限度减少对网速的影响,配置基于GFWList的黑名单透明代理似乎更为科学。经过摸索,实现类似SS+GFWList的效果。下文将介绍 V2Ray 服务端和客户端(路由器)的搭建步骤,着重介绍黑名单配置方法。
Server
服务端并不需要进行特殊设置,这里不再赘述,直接贴出我的配置文件供参考:
{
"log": {
"access": "/var/log/v2ray/access.log",
"error": "/var/log/v2ray/error.log",
"loglevel": "warning"
},
"inbound": {
"port": 12345,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "your-uuid",
"level": 1,
"alterId": 100
}
]
},
"streamSettings": {
"network": "kcp",
"security": "tls",
"tlsSettings": {
"serverName": "your-server",
"certificates": [
{
"certificateFile": "path-to-your-ssl-certificate",
"keyFile": "path-to-your-ssl-key"
}
]
}
},
"detour": {
"to": "tag_to_detour"
}
},
"outbound": {
"protocol": "freedom",
"settings": {}
},
"inboundDetour": [
{
"protocol": "vmess",
"port": "15000-18000",
"tag": "tag_to_detour",
"settings": {},
"allocate": {
"strategy": "random",
"concurrency": 5,
"refresh": 5
},
"streamSettings": {
"network": "kcp",
"security": "tls",
"tlsSettings": {
"serverName": "your-server",
"certificates": [
{
"certificateFile": "path-to-your-ssl-certificate",
"keyFile": "path-to-your-ssl-key"
}
]
}
}
}
],
"outboundDetour": [
{
"protocol": "blackhole",
"settings": {},
"tag": "blocked"
}
],
"routing": {
"strategy": "rules",
"settings": {
"rules": [
{
"type": "field",
"ip": [
"0.0.0.0/8",
"10.0.0.0/8",
"100.64.0.0/10",
"127.0.0.0/8",
"169.254.0.0/16",
"172.16.0.0/12",
"192.0.0.0/24",
"192.0.2.0/24",
"192.168.0.0/16",
"198.18.0.0/15",
"198.51.100.0/24",
"203.0.113.0/24",
"::1/128",
"fc00::/7",
"fe80::/10"
],
"outboundTag": "blocked"
}
]
}
}
}
Client
Anti-spoofing DNS server
使用 V2Ray 的 Dokodemo door(任意门)协议,将 8.8.8.8 转发至本地 5353 端口:
{
...
"inboundDetour": [
...
{
"protocol": "dokodemo-door",
"port": 5353,
"settings": {
"address": "8.8.8.8",
"port": 53,
"network": "udp",
"timeout": 30,
"followRedirect": false
}
}
],
...
}
Transparent proxy
使用 V2Ray 的 Dokodemo door(任意门)协议,在本地 1234 端口开启透明代理,之后可使用 iptables 将需要代理的流量转发至此端口:
{
...
"inboundDetour": [
...
{
"protocol": "dokodemo-door",
"port": 1234,
"settings": {
"network": "tcp,udp",
"timeout": 30,
"followRedirect": true
}
}
],
...
}
其余部分参考其他文档配置即可,这里贴出我的完整配置供参考:
{
"log": {
"loglevel": "warning"
},
"inboundDetour": [
{
"protocol": "dokodemo-door",
"port": 1234,
"settings": {
"network": "tcp,udp",
"timeout": 30,
"followRedirect": true
}
},
{
"protocol": "dokodemo-door",
"port": 5353,
"settings": {
"address": "8.8.8.8",
"port": 53,
"network": "udp",
"timeout": 30,
"followRedirect": false
}
}
],
"outbound": {
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "your-server",
"port": 12345,
"udianlujitao.comsers": [
{
"id": "your-uuid",
"level": 1,
"alterId": 100
}
]
}
]
},
"streamSettings": {
"network": "kcp",
"security": "tls",
"tlsSettings": {
"serverName": "your-server"
}
},
"mux": {
"enabled": true,
"concurrency": 8
}
},
"outboundDetour": [
{
"protocol": "freedom",
"settings": {},
"tag": "direct"
}
],
"dns": {
"servers": [
"8.8.8.8",
"localhost"
]
}
}
OpenWRT init
V2Ray 官方没有提供 OpenWRT 的 init 配置文件,我编写了一份基于 procd 的简单配置,放在/etc/init.d/v2ray
即可使用 enable, start 等命令在后台运行,仅供参考:
#!/bin/sh /etc/rc.common
START=90
STOP=15
USE_PROCD=1
#PROCD_DEBUG=1
CONF=/etc/v2ray/config.json
PROG=/usr/bin/v2ray/v2ray
start_service() {
procd_open_instance
procd_set_param command $PROG -config $CONF
procd_set_param stdout 1
procd_set_param stderr 1
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-9}
procd_close_instance
}
Traffic forwarding
- 使用gfwlist2dnsmasq工具生成 gfwlist 的 dnsmasq 配置,放在
/etc/dnsmasq.d/gfwlist.conf
:
./gfwlist2dnsmasq.sh -s gfwlist -o /etc/dnsmasq.d/gfwlist.conf
- 在
/etc/dnsmasq.conf
添加配置目录:
echo "conf-dir=/etc/dnsmasq.d" >> /etc/dnsmasq.conf
- 在 LuCI 的自定义防火墙规则中添加如下内容:
iptables-save -c | grep -v "gfwlist" | iptables-restore -c
ipset -X gfwlist
ipset create gfwlist hash:ip
iptables -t nat -A PREROUTING -p tcp -m set --match-set gfwlist dst -j REDIRECT --to-port 1234
iptables -t nat -A OUTPUT -p tcp -m set --match-set gfwlist dst -j REDIRECT --to-port 1234
ipset -X gfwlist_ext
ipset create gfwlist_ext hash:net
for ip in $(cat /etc/v2ray/extn_ips.txt);
do ipset add gfwlist_ext $ip;
done
iptables -t nat -A PREROUTING -p tcp -m set --match-set gfwlist_ext dst -j REDIRECT --to-port 1234
iptables -t nat -A OUTPUT -p tcp -m set --match-set gfwlist_ext dst -j REDIRECT --to-port 1234
将gfwlist
和gfwlist_ext
中 IP 的 TCP 流量转发至 1234 端口,这里偷懒没设 UDP 透明代理。gfwlist
的内容由 dnsmasq 自动添加gfwlist_ext
用于存储额外需要代理的 IP 地址,如 Telegram 服务器。hash:net类型存储 CIDR 地址更为高效,所以单独建一张表。
配置完成,重启路由器后应该能顺利访问河蟹网站。
Reference
- https://www.v2ray.com
- https://toutyrater.github.io/app/transparent_proxy.html
- https://blog.nicesite.win/2017/08/16/soft-router/
- https://wiki.archlinux.org/index.php/Ipset
- http://ipset.netfilter.org/ipset.man.html
- https://github.com/shadowsocks/luci-app-shadowsocks/wiki/GfwList-Support
- https://github.com/shadowsocks/luci-app-shadowsocks/blob/master/files/root/usr/bin/ss-rules
0 条评论