Skip to content

Latest commit

 

History

History
316 lines (296 loc) · 8.93 KB

v2ray_rel.org

File metadata and controls

316 lines (296 loc) · 8.93 KB

v2ray

transparent proxy

configuration file in raspberry

//listen on the 12345 port for incoming raw packet, for example using ssh tunnel to forward router’s packets to raspberry //outbounds to the real remote proxy server { “routing”: {…}, “inbounds”: [ { … }, { “port”: 12345, // The open port “protocol”: “dokodemo-door”, “settings”: { “network”: “tcp,udp”, “followRedirect”: true // Need to be set as true to accept traffic from iptables }, “sniffing”: { “enabled”: true, “destOverride”: [“http”, “tls”] } } ], “outbounds”: [ { … “streamSettings”: { … “sockopt”: { “mark”: 255 // Here is SO_MARK,used for iptables to recognise. Each outbound needs to configure; you can use other value other than 255 but it needs to be consistant as in iptables rules; if there are multiple outbounds, it is recommended that you set all SO_MARK value the same for all outbounds. } } } … ] }

a whole list


{ “inbounds”: [ { “tag”:”transparent”, “port”: 12345, “protocol”: “dokodemo-door”, “settings”: { “network”: “tcp,udp”, “followRedirect”: true }, “sniffing”: { “enabled”: true, “destOverride”: [ “http”, “tls” ] }, “streamSettings”: { “sockopt”: { “tproxy”: “tproxy” // 透明代理使用 TPROXY 方式 } } }, { “port”: 1080, “protocol”: “socks”, // 入口协议为 SOCKS 5 “sniffing”: { “enabled”: true, “destOverride”: [“http”, “tls”] }, “settings”: { “auth”: “noauth” } } ], “outbounds”: [ { “tag”: “proxy”, “protocol”: “vmess”, // 代理服务器 “settings”: { “vnext”: [ … ] }, “streamSettings”: { “sockopt”: { “mark”: 255 } }, “mux”: { “enabled”: true } }, { “tag”: “direct”, “protocol”: “freedom”, “settings”: { “domainStrategy”: “UseIP” }, “streamSettings”: { “sockopt”: { “mark”: 255 } } }, { “tag”: “block”, “protocol”: “blackhole”, “settings”: { “response”: { “type”: “http” } } }, { “tag”: “dns-out”, “protocol”: “dns”, “streamSettings”: { “sockopt”: { “mark”: 255 } } } ], “dns”: { “servers”: [ “8.8.8.8”, // 非中中国大陆域名使用 Google 的 DNS “1.1.1.1”, // 非中中国大陆域名使用 Cloudflare 的 DNS(备用) “114.114.114.114”, // 114 的 DNS (备用) { “address”: “223.5.5.5”, //中国大陆域名使用阿里的 DNS “port”: 53, “domains”: [ “geosite:cn”, “ntp.org”, // NTP 服务器 “$myserver.address” // 此处改为你 VPS 的域名 ] } ] }, “routing”: { “domainStrategy”: “IPOnDemand”, “rules”: [ { // 劫持 53 端口 UDP 流量,使用 V2Ray 的 DNS “type”: “field”, “inboundTag”: [ “transparent” ], “port”: 53, “network”: “udp”, “outboundTag”: “dns-out” }, { // 直连 123 端口 UDP 流量(NTP 协议) “type”: “field”, “inboundTag”: [ “transparent” ], “port”: 123, “network”: “udp”, “outboundTag”: “direct” }, { “type”: “field”, “ip”: [ // 设置 DNS 配置中的国内 DNS 服务器地址直连,以达到 DNS 分流目的 “223.5.5.5”, “114.114.114.114” ], “outboundTag”: “direct” }, { “type”: “field”, “ip”: [ // 设置 DNS 配置中的国内 DNS 服务器地址走代理,以达到 DNS 分流目的 “8.8.8.8”, “1.1.1.1” ], “outboundTag”: “proxy” // 改为你自己代理的出站 tag }, { // 广告拦截 “type”: “field”, “domain”: [ “geosite:category-ads-all” ], “outboundTag”: “block” }, { // BT 流量直连 “type”: “field”, “protocol”:[“bittorrent”], “outboundTag”: “direct” }, { // 直连中国大陆主流网站 ip 和 保留 ip “type”: “field”, “ip”: [ “geoip:private”, “geoip:cn” ], “outboundTag”: “direct” }, { // 直连中国大陆主流网站域名 “type”: “field”, “domain”: [ “geosite:cn” ], “outboundTag”: “direct” } ] } }


iptables setting

ip rule add fwmark 1 table 100 ip route add local 0.0.0.0/0 dev lo table 100

iptables -t mangle -N V2RAY iptables -t mangle -A V2RAY -d 127.0.0.1/32 -j RETURN iptables -t mangle -A V2RAY -d 224.0.0.0/4 -j RETURN iptables -t mangle -A V2RAY -d 255.255.255.255/32 -j RETURN iptables -t mangle -A V2RAY -d 192.168.0.0/16 -p tcp -j RETURN # 直连局域网,避免 V2Ray 无法启动时无法连网关的 SSH,如果你配置的是其他网段(如 10.x.x.x 等),则修改成自己的 iptables -t mangle -A V2RAY -d 192.168.0.0/16 -p udp ! –dport 53 -j RETURN # 直连局域网,53 端口除外(因为要使用 V2Ray 的 iptables -t mangle -A V2RAY -p udp -j TPROXY –on-port 12345 –tproxy-mark 1 # 给 UDP 打标记 1,转发至 12345 端口 iptables -t mangle -A V2RAY -p tcp -j TPROXY –on-port 12345 –tproxy-mark 1 # 给 TCP 打标记 1,转发至 12345 端口 iptables -t mangle -A PREROUTING -j V2RAY # 应用规则

iptables -t mangle -N V2RAY_MASK iptables -t mangle -A V2RAY_MASK -d 224.0.0.0/4 -j RETURN iptables -t mangle -A V2RAY_MASK -d 255.255.255.255/32 -j RETURN iptables -t mangle -A V2RAY_MASK -d 192.168.0.0/16 -p tcp -j RETURN # 直连局域网 iptables -t mangle -A V2RAY_MASK -d 192.168.0.0/16 -p udp ! –dport 53 -j RETURN # 直连局域网,53 端口除外(因为要使用 V2Ray 的 DNS) iptables -t mangle -A V2RAY_MASK -j RETURN -m mark –mark 0xff # 直连 SO_MARK 为 0xff 的流量(0xff 是 16 进制数,数值上等同与上面V2Ray 配置的 255),此规则目的是避免代理本机(网关)流量出现回环问题 iptables -t mangle -A V2RAY_MASK -p udp -j MARK –set-mark 1 # 给 UDP 打标记,重路由 iptables -t mangle -A V2RAY_MASK -p tcp -j MARK –set-mark 1 # 给 TCP 打标记,重路由 iptables -t mangle -A OUTPUT -j V2RAY_MASK # 应用规则

iptables -t mangle -A V2RAY_MASK -p udp -j MARK –set-mark 1 iptables -t mangle -A V2RAY_MASK -p tcp -j MARK –set-mark 1 iptables -t mangle -A OUTPUT -j V2RAY_MASK ===================

v2ray inbound

inbound/inboundDetour configuration

inbound的详细配置如下

“inbound”: { “port”: 1080, “listen”: “127.0.0.1”, “protocol”: “协议名称”, “settings”: {}, “streamSettings”: {}, “tag”: “标识”, “domainOverride”: [“http”, “tls”] }

inboundDetour的详细配置如下

“inboundDetour”: [ { “port”: 1080, “listen”: “127.0.0.1”, “protocol”: “协议名称”, “settings”: {}, “streamSettings”: {}, “tag”: “标识”, “domainOverride”: [“http”, “tls”] } ]

“protocol” 传输协议

上述配置文件中,最重要的设置参数就是”protocol”连接协议,目前支持下面的7种协议:Blackhole、Dokodemo-door、HTTP、Freedom、HTTP、Shadowsocks、Socks、VMess。其中Dokodemo-door、HTTP单独为传入协议,Shadowsocks、Socks、VMess分别有传入传出协议。Blackhole、Freedom单独为传出协议。

所以可作为传入协议配置的有Dokodemo-door、HTTP、Shadowsocks、Socks、VMess这5种协议类型

inbound的详细配置如下

“inbound”: { “port”: 1080, “listen”: “127.0.0.1”, “protocol”: “协议名称”, “settings”: {}, “streamSettings”: {}, “tag”: “标识”, “domainOverride”: [“http”, “tls”] }

inboundDetour的详细配置如下

“inboundDetour”: [ { “port”: 1080, “listen”: “127.0.0.1”, “protocol”: “协议名称”, “settings”: {}, “streamSettings”: {}, “tag”: “标识”, “domainOverride”: [“http”, “tls”] } ]

“protocol” 传输协议

上述配置文件中,最重要的设置参数就是”protocol”连接协议,目前支持下面的7种协议:Blackhole、Dokodemo-door、HTTP、Freedom、HTTP、Shadowsocks、Socks、VMess。其中Dokodemo-door、HTTP单独为传入协议,Shadowsocks、Socks、VMess分别有传入传出协议。Blackhole、Freedom单独为传出协议。 所以可作为传入协议配置的有Dokodemo-door、HTTP、Shadowsocks、Socks、VMess这5种协议类型

inbound protocl(proxy protocl ) support list

Socks: socks5, socks4… HTTP: http proxy Dokodemo-door: the raw packet without any proxy header Shadowsocks VMess