显示标签为“代理”的博文。显示所有博文
显示标签为“代理”的博文。显示所有博文

星期日, 九月 07, 2025

188 IPv6 only 服务器上 Mihomo 入站 + 安装 WARP

环境与需求: 

IPv6 only 小鸡, 想上双栈 warp, 同时开放一个 socks5 端口, 用于 Mihomo 连入. warp 不要像 tun 那样来占用我的整个小鸡网络. 

流程: 

目标网站 - warp - socks5 - Mihomo - 机场 - 我的设备 

 

1, 运行脚本

wget -N https://gitlab.com/fscarmen/warp/-/raw/main/menu.sh && bash menu.sh

2, 选

3. 为 IPv6 only 添加 WARP 双栈网络接口
1. wireguard 内核 (默认)
2. 非全局
1. 使用免费账户 (默认)
3. 使用 VPS 初始设置 (默认)

3, 选 13 安装 wireproxy 和进行设置, 最后可能会出错, 会显示如下信息, 看起来像是安装完成, 但是 wget 解析域名的时候解析到了 IPv4 的地址, 所以返回了 Network is unreachable: 

 进度 1/3: 安装系统依赖……

--2025-09-07 09:11:58--  https://github.com/pufferffish/wireproxy/releases/download/v1.0.9/wireproxy_linux_amd64.tar.gz
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... failed: Network is unreachable.
--2025-09-07 09:11:58--  https://gitlab.com/fscarmen/warp/-/raw/main/wireproxy/wireproxy_linux_amd64.tar.gz
Resolving gitlab.com (gitlab.com)... 172.65.251.78
Connecting to gitlab.com (gitlab.com)|172.65.251.78|:443... failed: Network is unreachable.
0% [Working]
gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now
0% [Waiting for headers]
 进度 2/3: 已处理好 WARP 配置文件

Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [128 kB]
Hit:3 http://archive.ubuntu.com/ubuntu jammy-security InRelease
Fetched 128 kB in 8s (16.3 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
157 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
openresolv is already the newest version (3.12.0-2).
iptables is already the newest version (1.8.7-1ubuntu5.2).
net-tools is already the newest version (1.60+git20181103.0eebece-1ubuntu5.4).
dnsutils is already the newest version (1:9.18.30-0ubuntu0.22.04.2).
0 upgraded, 0 newly installed, 0 to remove and 157 not upgraded.

 进度 3/3: 寻找 MTU 最优值已完成

 创建快捷 warp 指令成功
 WireProxy 还未安装

4, 直接去下载 wireproxy 的 amd64 包, 放入 /usr/bin/ 下, 给 0755 权限, 注意不是放在 /usr/local/bin/ 里面

https://github.com/whyvl/wireproxy/releases

5, 修改 /etc/wireguard/ 下的各项配置文件, 保证 dns 不为 IPv4. 不然 wireproxy 服务会报错:

journalctl -xeu wireproxy.service


-- Support: http://www.ubuntu.com/support
--
-- A start job for unit wireproxy.service has finished successfully.
--
-- The job identifier is 3900.
Sep 07 09:46:52 HK-LXC wireproxy[13136]: 2025/09/07 09:46:52 lookup engage.cloudflareclient.com on 8.8.8.8:53: dial udp 8.8.8.8:53: connect: network is unreachable
Sep 07 09:46:52 HK-LXC systemd[1]: wireproxy.service: Main process exited, code=exited, status=1/FAILURE
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- An ExecStart= process belonging to unit wireproxy.service has exited.

修改 warp.conf 底下的 DNS 和 Endpoint 为 IPv6, 改 Endpoint 是因为域名不知道去哪个弱智 IPv4 DNS 请求导致不能解析, 所以就直接写成固定的 IPv6 地址:

DNS = 2606:4700:4700::1001,2606:4700:4700::1111
Endpoint = [2606:4700:d0::a29f:c001]:2408

修改 proxy.conf 底下的 DNS 和 Endpoint 为 IPv6, 如上.

5, 再次执行 warp 命令, 选 2.连接 Wireproxy (warp y) 或者直接执行 warp y

如果还启不来, 看看是否有 wireproxy 的服务:

systemctl list-unit-files | grep wire

如果没有服务, 手动添加一个, 注意从 /lib/systemd/system/wireproxy.service 添加, 不知道为什么, 我记得脚本里就是添加到这了. 注意 MemoryLimit=256M 这个参数, 是我手动加的, 实际使用中发现有 wireproxy 内存泄漏的情况, 1GB 的内存半天就占满失联了, 如果你也有 wireproxy 内存泄漏, 建议将内存限制手动加到 service 文件中. 另外, RemainAfterExit=yes 这个参数也不要, 否则, wireproxy 意外退出了之后 systemd 无感知, 还以为它在运行: 

[Unit]
Description=WireProxy for WARP
After=network.target
Documentation=https://github.com/fscarmen/warp-sh
Documentation=https://github.com/pufferffish/wireproxy
[Service]
ExecStart=/usr/bin/wireproxy -c /etc/wireguard/proxy.conf
Restart=always
MemoryLimit=256M [Install] WantedBy=multi-user.target
systemctl daemon-reload

service 命令如果启动还有报错, 尝试手动运行

/usr/bin/wireproxy -c /etc/wireguard/proxy.conf

可能会看到

2025/09/07 09:59:06 lookup engage.cloudflareclient.com on 8.8.8.8:53: dial udp 8.8.8.8:53: connect: network is unreachable

这样的报错, warp 或者一键脚本擅自修改了 resolv.conf 也就是系统 DNS, 改回 IPv6 的即可, 如

nameserver 2606:4700:4700::1001
nameserver 2606:4700:4700::1111

另外可能有端口占用的问题, 从 netstat -lntpu 会看到哪个进程占用, 干掉端口占用的进程或者用脚本换新的 socks 端口. 


Mihomo 入站只需提一嘴, 会搓配置的人一看就懂

#config.yaml
log-level: silent
ipv6: true
tcp-concurrent: true
listeners:
  - name: myvmess
    type: vmess
    port: 80
    listen: 0.0.0.0
    users:
     - username: 1
       uuid: c441dae3-1176-4640-9c51-666e2f80d92c
       alterId: 0
       udp: true
       cipher: auto
proxies:
  - name: warp
    type: socks5
    server: 127.0.0.1
    port: 1080
    udp: true
dns:
  enable: true
  listen: 127.0.0.1:53
  ipv6: true
  nameserver:
    - https://[2606:4700:4700::1001]:443/dns-query#DIRECT
    - https://[2606:4700:4700::1111]:443/dns-query#DIRECT
  default-nameserver:
    - https://[2606:4700:4700::1001]:443/dns-query#DIRECT
rules:
  - MATCH,warp

注意 proxies 里面 udp 要开, 查看 udp 是否能通, 去 https://networktest.twilio.com/ 网站检测一下就行, 如果 udp: true 忘记写了的话, twilio 里面第一条  NTS: TURN UDP Connectivity 会显示 failed. 

nameserver 我用了 Cloudflare 的两个 doh 来查询, warp 只管和 ip 之间的流量, warp 用的是 udp 53 的传统 dns, 我完全不信任这种协议. 

星期二, 八月 06, 2024

178 mihomo (clash meta) 内核在访问 gstatic.com 和 googleapis.com 非大陆域名 / IP 走 DIRECT 直连 的问题

一直使用 openclash + mihomo (原 clash meta) 内核运行在路由器上, 最近似乎规则有些问题, 谷歌的 cdn 总是直连. 过一会又发现它在走代理, 而且基本都是这几个域名: 

ssl.gstatic.com
www.gstatic.com
*.googleapis.com

最早怀疑是 IPv6 的问题, 因为我最近把它打开了, 后面发现不是. 

然后是怀疑 geoip 出了问题, 我用的是 https://raw.githubusercontent.com/Loyalsoldier/geoip/release/geoip-only-cn-private.dat 这个只有 cn 和 private 的 dat, 关键代码如下: 

geodata-mode: true
geox-url:
   geoip: "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/geoip-only-cn-private.dat"
   geosite: ~
   mmdb: ~
   asn: ~

因为它是 dat, 内容不可见, 我就换成了纯文本的 ipcidr + rule-set 的形式, 这种规则的好处是, ip 段可见, 方便排查. 代码如下: 

rule-providers:
  CN4:
    type: http
    path: cn4.txt
    url: "https://raw.githubusercontent.com/gaoyifan/china-operator-ip/ip-lists/china.txt"
    interval: 604800
    proxy: Tunnels
    behavior: ipcidr
    format: text

  CN6:
    type: http
    path: cn6.txt
    url: "https://raw.githubusercontent.com/gaoyifan/china-operator-ip/ip-lists/china6.txt"
    interval: 604800
    proxy: Tunnels
    behavior: ipcidr
    format: text
rules:
  - IP-CIDR,255.255.255.255/32,REJECT
  - IP-CIDR6,ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128,REJECT
  - GEOIP,PRIVATE,DIRECT
  - RULE-SET,CN4,DIRECT
  - RULE-SET,CN6,DIRECT
  - MATCH,Tunnels

像上面这样的配置, 跑了几天, 依旧不行, 有时候使用谷歌正常, 也有时候浏览器在转, 一转我就知道这二币又去直连了:

然而我的 ipv4 段里面, 根本没有 172.217.31.10: 

172.81.192.0/18 = 172.81.192.0 - 172.81.255.255

那特码的就怪了, 没有规则你凭什么匹配成 DIRECT 直连? 排查过 openclash 的运行配置, 和我写的 rules 一样, 就那么几条, 没有加别的.

后来被折腾得烦了, 直接上 rule-set 看看吧, 于是就多加了一段,  代码如下: 

rule-providers:
  GOOGLE:
    type: http
    path: google.yaml
    url: "https://******/google.yaml"  #配置在下面, 自己简单写的, 本地加载的话上面改成 type:file 具体看配置手册
    interval: 604800
    proxy: Tunnels
    behavior: classical
    format: yaml
rules:
  - IP-CIDR,255.255.255.255/32,REJECT
  - IP-CIDR6,ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128,REJECT
  - GEOIP,PRIVATE,DIRECT
  - RULE-SET,GOOGLE,Tunnels
  - RULE-SET,CN4,DIRECT
  - RULE-SET,CN6,DIRECT
  - MATCH,Tunnels

写在了 cn4 和 cn6 (或者是 geoip,cn) 的上面, 观察了几天, 问题解决了, 那几个撒币域名解析的香港地址也不直连了... 注意, 不要加 no-resolve, 因为这些 IP 大部分是由域名解析过来的, 哪怕是拦截用的 255 和 fffff 也是一样. 

以下是谷歌配置 google.yaml: 

payload:
  - DOMAIN-SUFFIX,ytimg.com
  - DOMAIN-SUFFIX,amp.dev
  - DOMAIN-SUFFIX,android.com
  - DOMAIN-SUFFIX,api.ai
  - DOMAIN-SUFFIX,app-measurement.com
  - DOMAIN-SUFFIX,app-measurement.net
  - DOMAIN-SUFFIX,appspot.com
  - DOMAIN-SUFFIX,material.io
  - DOMAIN-SUFFIX,recaptcha.net
  - DOMAIN-SUFFIX,gstatic.com
  - DOMAIN-SUFFIX,google.com
  - DOMAIN-SUFFIX,googleapis.com
  - DOMAIN-SUFFIX,g.co
  - DOMAIN-SUFFIX,flutter.dev
  - DOMAIN-SUFFIX,flutterapp.com
  - DOMAIN-SUFFIX,firebaseapp.com
  - DOMAIN-SUFFIX,firebaseio.com
  - DOMAIN-SUFFIX,blogspot.com
  - DOMAIN-SUFFIX,youtube.com
  - DOMAIN-SUFFIX,youtu.be
  - DOMAIN-SUFFIX,g.co
  - DOMAIN-SUFFIX,withgoogle.com
  - DOMAIN-SUFFIX,googleusercontent.com
  - DOMAIN-SUFFIX,ggpht.com
  - DOMAIN-SUFFIX,googlevideo.com
  - DOMAIN-KEYWORD,gvt
  - DOMAIN-KEYWORD,ampproject
  - DOMAIN-REGEX,^gvt\d\.com
  - DOMAIN-REGEX,^.*\.goog

以上是我根据自己的使用习惯和需求写的, 参考了 https://github.com/blackmatrix7/ios_rule_script/blob/master/rule/Clash/Google/Google_No_Resolve.yaml 但没有完全使用, blackmatrix 作者的这个版本算是懒人配置, 里面还有 cn 域名. 我为了防止自己的服务器送中, 把所有谷歌大陆域名都屏蔽掉了, 还有一些广告域名也是. 规则这个东西, 千人千面, 根据自己的需求来我觉得最好不过了. 

对了, 上面的规则里有正则 DOMAIN-REGEX, ≤1.18.1 的版本是用不了的. 发布博文时, 使用的版本是 1.18.7