返回列表 發帖

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

看起来,透明代理複雜多。Performance 如何?

TOP

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

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

TOP

本帖最後由 yiucsw 於 2020-1-15 08:48 編輯

昨天重装Newif3 v2ray client. 看到Luci-app-v2ray 有更新,試了一下,只要加你的vmess outbound parameter. V2ray 便能用。再跟你的TPROXY v2ray.config,click troxy tab。好像便 不用set sock5, whatismyipaddress 顯示Server IP 地址。不知道是不是TRPROXY。
感謝你的幫忙。


*luci-app-v2ray 是在中國Client用的。不用set iptables, 不用set startup script.

TOP

本帖最後由 yiucsw 於 2020-1-15 09:04 編輯

luci-app-v2ray generated script.
  1. {
  2.         "log": {
  3.                 "access": "\/var\/log\/v2ray-access.log",
  4.                 "loglevel": "warning",
  5.                 "error": "\/var\/log\/v2ray-error.log"
  6.         },
  7.         "routing": {
  8.                 "domainStrategy": "IPOnDemand",
  9.                 "rules": [
  10.                         {
  11.                                 "type": "field",
  12.                                 "ip": [
  13.                                         "geoip:private",
  14.                                         "geoip:cn"
  15.                                 ],
  16.                                 "outboundTag": "direct"
  17.                         },
  18.                         {
  19.                                 "type": "field",
  20.                                 "domain": [
  21.                                         "geosite:cn"
  22.                                 ],
  23.                                 "outboundTag": "direct"
  24.                         },
  25.                         {
  26.                                 "type": "field",
  27.                                 "protocol": [
  28.                                         "bittorrent"
  29.                                 ],
  30.                                 "outboundTag": "direct"
  31.                         },
  32.                         {
  33.                                 "type": "field",
  34.                                 "port": "53",
  35.                                 "network": "udp",
  36.                                 "inboundTag": [
  37.                                         "transparent"
  38.                                 ],
  39.                                 "outboundTag": "dns_out"
  40.                         },
  41.                         {
  42.                                 "type": "field",
  43.                                 "ip": [
  44.                                         "1.1.1.1",
  45.                                         "8.8.8.8",
  46.                                         "208.67.222.222"
  47.                                 ],
  48.                                 "outboundTag": "proxy"
  49.                         }
  50.                 ]
  51.         },
  52.         "inbounds": [
  53.                 {
  54.                         "listen": "0.0.0.0",
  55.                         "port": 1080,
  56.                         "protocol": "socks",
  57.                         "settings": {
  58.                                 "auth": "noauth",
  59.                                 "udp": false
  60.                         },
  61.                         "streamSettings": {
  62.                                 "sockopt": {
  63.                                        
  64.                                 }
  65.                         },
  66.                         "sniffing": {
  67.                                 "enabled": true,
  68.                                 "destOverride": [
  69.                                         "http",
  70.                                         "tls"
  71.                                 ]
  72.                         }
  73.                 },
  74.                 {
  75.                         "port": 1081,
  76.                         "protocol": "dokodemo-door",
  77.                         "settings": {
  78.                                 "followRedirect": true,
  79.                                 "network": "tcp"
  80.                         },
  81.                         "streamSettings": {
  82.                                 "sockopt": {
  83.                                         "tproxy": "redirect"
  84.                                 }
  85.                         },
  86.                         "tag": "transparent",
  87.                         "sniffing": {
  88.                                 "enabled": true,
  89.                                 "destOverride": [
  90.                                         "http",
  91.                                         "tls"
  92.                                 ]
  93.                         }
  94.                 }
  95.         ],
  96.         "outbounds": [
  97.                 {
  98.                         "sendThrough": "0.0.0.0",
  99.                         "protocol": "vmess",
  100.                         "settings": {
  101.                                 "vnext": [
  102.                                         {
  103.                                                 "address": "yourservr.dynu.net",
  104.                                                 "port": 443,
  105.                                                 "users": [
  106.                                                         {
  107.                                                                 "id": "8b737d60-a000-4a0f-8de3-218fa0c0a3d8",
  108.                                                                 "alterId": 64,
  109.                                                                 "security": "chacha20-poly1305"
  110.                                                         }
  111.                                                 ]
  112.                                         }
  113.                                 ]
  114.                         },
  115.                         "streamSettings": {
  116.                                 "network": "ws",
  117.                                 "security": "tls",
  118.                                 "tlsSettings": {
  119.                                         "serverName": "yourserver.dynu.net",
  120.                                         "allowInsecure": true,
  121.                                         "allowInsecureCiphers": false,
  122.                                         "disableSystemRoot": false,
  123.                                         "certificates": [
  124.                                                
  125.                                         ]
  126.                                 },
  127.                                 "wsSettings": {
  128.                                         "path": "\/vpath"
  129.                                 },
  130.                                 "sockopt": {
  131.                                         "mark": 255
  132.                                 }
  133.                         },
  134.                         "tag": "proxy",
  135.                         "mux": {
  136.                                 "enabled": true,
  137.                                 "concurrency": 8
  138.                         }
  139.                 },
  140.                 {
  141.                         "protocol": "freedom",
  142.                         "settings": {
  143.                                
  144.                         },
  145.                         "streamSettings": {
  146.                                 "sockopt": {
  147.                                         "mark": 255
  148.                                 }
  149.                         },
  150.                         "tag": "direct"
  151.                 },
  152.                 {
  153.                         "protocol": "dns",
  154.                         "settings": {
  155.                                
  156.                         },
  157.                         "streamSettings": {
  158.                                 "sockopt": {
  159.                                         "mark": 255
  160.                                 }
  161.                         },
  162.                         "tag": "dns_out"
  163.                 }
  164.         ]
  165. }
複製代碼


Hope it works。

TOP

mips router跑v2ray似乎很吃力,要用上softfloat去執行,效能底下.
建議用trojan,因為不依賴CPU floating 計算功能,所以效率高很多
321

TOP

返回列表