返回列表 發帖

Openwrt V2ray 透明代理 tls + ws (實踐編)

本帖最後由 tomleehk 於 2019-12-21 08:39 編輯

Openwrt V2ray 透明代理 tls + ws (實踐編)

參考網上文章, 呢d網友嘅文章比較完整

V2RAY透明代理
https://ibcl.us/HC5962-V2Ray_20190518/
https://xdays.me/V2RAY%E9%80%8F%E6%98%8E%E4%BB%A3%E7%90%86/



左砌右砌加加減減, 初步睇結果喺成功做到tcp+dns轉發, 速度唔算好高, 足夠一般使用

本帖最後由 tomleehk 於 2019-12-21 11:28 編輯

將v2ray作為OpenWrt 透明代理, 需要安裝一些package
opkg update <<ENTER>>
opkg install bash kmod-ipt-tproxy iptables-mod-tproxy bind-dig <<ENTER>>

TOP

本帖最後由 tomleehk 於 2019-12-27 12:20 編輯

v2ray.json
  1. {
  2.   "inbounds": [
  3.     {
  4.       "port": 1080,
  5.       "listen": "0.0.0.0",
  6.       "protocol": "socks",
  7.       "sniffing": {
  8.         "enabled": true,
  9.         "destOverride": ["http", "tls"]
  10.       },
  11.       "settings": {
  12.         "auth": "noauth",
  13.         "udp": true
  14.       }
  15.     },
  16.     {
  17.       "port": 8080,
  18.       "listen": "0.0.0.0",
  19.       "protocol": "http",
  20.       "sniffing": {
  21.         "enabled": true,
  22.         "destOverride": ["http", "tls"]
  23.       },
  24.       "settings": {
  25.         "timeout": 300
  26.       }
  27.     },
  28.     {
  29.       "port": 12345,
  30.       "protocol": "dokodemo-door",
  31.       "sniffing": {
  32.         "enabled": true,
  33.         "destOverride": ["http", "tls"]
  34.       },
  35.       "settings": {
  36.         "network": "tcp,udp",
  37.         "timeout": 0,
  38.         "followRedirect": true
  39.       }
  40.     }
  41.   ],
  42.   "outbounds": [
  43.     {
  44.       "protocol": "vmess",
  45.       "settings": {
  46.         "vnext": [
  47.           {
  48.             "address": "server ip",
  49.             "port": 443,
  50.             "users": [
  51.               {
  52.                 "id": "779e81cb-79b6-3377-b2b5-ce402c21b8f5",
  53.                 "security": "aes-128-gcm",
  54.                 "alterId": 64
  55.               }
  56.             ]
  57.           }
  58.         ]
  59.       },
  60.       "streamSettings": {
  61.         "network": "ws",
  62.         "security": "tls",
  63.         "tlsSettings": {"allowInsecure": true,"serverName": "server url"},
  64.         "wsSettings": {
  65.           "path": "/vpath"
  66.         }
  67.       }
  68.     }
  69.   ]
  70. }
複製代碼
v2ray 啟動 script
  1. #!/bin/sh /etc/rc.common
  2. # "new" style init script
  3. # Look at /lib/functions/service.sh on a running system for explanations of what other SERVICE_
  4. # options you can use, and when you might want them.

  5. START=80
  6. STOP=20
  7. APP=v2ray
  8. SERVICE_WRITE_PID=1
  9. SERVICE_DAEMONIZE=1
  10. PREFIX=/usr/bin

  11. start() {
  12.     service_start $PREFIX/v2ray -config $PREFIX/v2ray.json
  13.     $PREFIX/client_proxy.sh start
  14. }

  15. stop() {
  16.     $PREFIX/client_proxy.sh stop
  17.     service_stop $PREFIX/v2ray
  18. }
複製代碼
成功啟動後可以用
ps | grep "v2ray"
curl -Is -x 127.0.0.1:8080 https://www.google.com
curl  -x  socks5://127.0.0.1:1080  www.google.com
睇吓有無正確嘅response

留意port 1080及port 8080呢2段嘅config只喺方便用curl測試connection,
本身運作上並非必要

TOP

本帖最後由 tomleehk 於 2019-12-21 08:37 編輯

Iptable scripts
  1. #!/bin/bash
  2. # -*- coding: utf-8 -*-

  3. start() {

  4. # Chain TCP
  5.   iptables -t nat -N V2RAY
  6. # Reserved IP TCP
  7.   iptables -t nat -A V2RAY -d 0.0.0.0/8 -j RETURN
  8.   iptables -t nat -A V2RAY -d 10.0.0.0/8 -j RETURN
  9.   iptables -t nat -A V2RAY -d 127.0.0.0/8 -j RETURN
  10.   iptables -t nat -A V2RAY -d 169.254.0.0/16 -j RETURN
  11.   iptables -t nat -A V2RAY -d 172.16.0.0/12 -j RETURN
  12.   iptables -t nat -A V2RAY -d 192.168.0.0/16 -j RETURN
  13.   iptables -t nat -A V2RAY -d 224.0.0.0/4 -j RETURN
  14.   iptables -t nat -A V2RAY -d 240.0.0.0/4 -j RETURN
  15. # VPS IP
  16.   iptables -t nat -A V2RAY -d <v2ray server ip> -j RETURN
  17. # Apply Forwarding Rules TCP
  18.   iptables -t nat -A V2RAY -p tcp -j REDIRECT --to-ports 12345
  19.   iptables -t nat -A PREROUTING -p tcp -j V2RAY
  20.   iptables -t nat -A OUTPUT -p tcp -j V2RAY


  21. # UDP Redirect
  22.   iptables -t mangle -N V2RAY
  23.   iptables -t mangle -A V2RAY -p udp -j RETURN -m mark --mark 0xff
  24.   iptables -t mangle -A V2RAY -p udp --dport 53 -j TPROXY --on-port 12345 --tproxy-mark 0x01/0x01
  25.   iptables -t mangle -N V2RAY_MARK
  26.   iptables -t mangle -A V2RAY_MARK -p udp -j RETURN -m mark --mark 0xff
  27.   iptables -t mangle -A V2RAY_MARK -p udp --dport 53 -j MARK --set-mark 1

  28. # add route for udp traffic
  29.   ip route add local default dev lo table 100
  30.   ip rule add fwmark 1 lookup 100

  31. # Apply the rules
  32. # apply udp tproxy for traffic forworded by this proxy
  33.   iptables -t mangle -A PREROUTING -j V2RAY
  34. # apply udp tproxy for proxy itself
  35.   iptables -t mangle -A OUTPUT -j V2RAY_MARK
  36. }

  37. stop() {
  38.     iptables -t nat -D PREROUTING  -p tcp -j V2RAY
  39.     iptables -t nat -D OUTPUT -p tcp -j V2RAY
  40.     iptables -t nat -F V2RAY
  41.     iptables -t nat -X V2RAY
  42.     iptables -t mangle -D PREROUTING -j V2RAY
  43.     iptables -t mangle -F V2RAY
  44.     iptables -t mangle -X V2RAY
  45.     iptables -t mangle -D OUTPUT -j V2RAY
  46.     iptables -t mangle -F V2RAY_MARK
  47.     iptables -t mangle -X V2RAY_MARK
  48.     ip rule del fwmark 1 lookup 100
  49.     ip route del local default dev lo table 100
  50. }

  51. case $1 in
  52. start)
  53.     start
  54.     ;;
  55. stop)
  56.     stop
  57.     ;;
  58. *)
  59.     echo "$0 start|stop"
  60.     ;;
  61. esac
複製代碼
規則中 v2ray listening port (12345)要按實際情況修改。

TOP

本帖最後由 tomleehk 於 2019-12-21 13:02 編輯

dns , routing tab 可按實際情況config
暫時一切tcp轉發,dns轉發功能都work

TOP

本帖最後由 tomleehk 於 2019-12-22 11:50 編輯

穩定性足夠..ofca 跑速約15mb..
用iptables 效能已經喺最好..
初步試只可直連v2ray server, 經 cdn 好似cloudflare喺唔通, 留番俾其人有需要嘅人研究吓

TOP

返回列表