v2ray 指定对网站使用 IPv4 或 IPv6 出口 (包括Warp)

昨天想和朋友一起开 zoom 屏幕共享追剧,然后登陆 zoom 的时候发现提示 "error code 1044",这个是 Zoom 对于免费用户在大陆地区登陆时的限制,再三确认分流规则没问题后,我想到会不会是由于出口 IP 有问题。

分析

我作为网络出口的服务器上有两张绑定了外部 IP 地址的网卡, eth0eth1 分别对应 ipv4 和 ipv6,ipv4 出口是美国的家宽,ipv6 ASN 注册在中国大陆,但是因为宣告在美国所以 Google 在内的大部分 GeoIP 都会认为这个 IP 是美国的,zoom 的 GeoIP 服务商不知道为什么这个月突然把这个 IP 重新标注回了中国。

随后我 down 掉了 eth1 ( ifdown eth1 ),然后打开 zoom,就可以正常登陆了。

解决

我没找到 v2ray 这类软件的服务端如何对一个网站或 GeoSite 做指定 IP 地址的分流,但是在文档中找到了对网站指定 IPv4 和 IPv6 的方法,完整配置文件如下。

如果你使用的官方脚本,或你使用的第三方脚本配置文件地址和官方脚本相同,那么配置文件位于

/usr/local/etc/v2ray/config.json

可以使用 cat /usr/local/etc/v2ray/config.json 查看文件内容,使用 vi /usr/local/etc/v2ray/config.json 更改文件内容,更改后 ESC : wq 回车保存退出

{
  "inbounds": [{
    "port": 11111, //此处为安装时生成的端口,可修改随意,但是保证和下面提到的端口号相同
    "listen":"127.0.0.1",
    "protocol": "vmess",
    "settings": {
      "clients": [
        {
          "id": "*****", //此处为安装时生成的id
          "level": 1,
          "alterId": **      //此处为安装时生成的alterId
        }
      ]
    },
    "streamSettings": {
      "network": "ws",
      "wsSettings": {
        "path": "/************"   //此处为路径
      }
    }
  }],
  "outbounds": [
    {
      "tag":"IP4_out",     //IPv4出口的标签
      "protocol": "freedom",
      "settings": {
          "domainStrategy": "UseIPv4"     //出口策略
      }
    },
    {
      "tag":"IP6_out",     //IPv6出口的标签
      "protocol": "freedom",
      "settings": {
        "domainStrategy": "UseIPv6"     //出口策略
      }
    }
  ],
  "routing": {
    "rules": [
      {
        "type": "field",
        "outboundTag": "IP4_out",
        "domain": ["geosite:netflix","geosite:zoom","geosite:paypal"]
      },
      {
        "type": "field",
        "ip": ["geoip:private"],
        "outboundTag": "blocked"
      },
      {
        "type": "field",
        "outboundTag": "IP4_out",
        "network": "udp,tcp"
      }
    ]
  }
}

随后重启 v2ray

systemctl restart v2ray

需要注意的是,如果 routing (路由) 策略里面包含多个网站,必须使用 "geosite:1","geosite:2" 的写法,不可 "geosite:1,2";如果你的服务端没有 GeoSite 配置的话这个策略无法被识别也会导致无法启动,遇到这种情况需要输入以下内容更新 GeoIP 和 GeoSite,然后重启 v2ray

bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-dat-release.sh)

systemctl restart v2ray

进阶玩法

有一些进阶玩法,例如使用 WARP 解锁 Netflix 非自制剧,如果你只配置了单栈网络的话也可以使用这个方法配置让 geosite:netflix 走你配置网络的出口,下面是脚本,来自 P3TERX

该脚本使用的 git.io 可能无法在纯 ipv6 服务器上打开,可以在电脑上打开该地址下载后使用 SFTP 上传到服务器

添加 WARP Wire­Guard 双栈全局网络

bash <(curl -fsSL git.io/warp.sh) d

添加或更改 IPv4/​IPv6 网络中的一个出口走 WARP Wire­Guard 网络

bash <(curl -fsSL git.io/warp.sh) 4
bash <(curl -fsSL git.io/warp.sh) 6

然后在 v2ray 配置文件中更改以下字段后重启即可

"rules": [
      {
        "type": "field",
        "outboundTag": "IP*_out",  //替换为你自己选择的网络,并且移除本行双斜线注释后方全部内容,含双斜线
        "domain": ["geosite:netflix"]
      },

附上我自己现在的配置文件(仅包含路由部分)

    "outbounds": [
      {
        "tag":"IP4_out", //IPv4优先
        "protocol": "freedom",
        "settings": {
            "domainStrategy": "UseIPv4"
        }
      },
      {
        "tag":"IP6_out", //IPv6优先
        "protocol": "freedom",
        "settings": {
          "domainStrategy": "UseIPv6"
        }
      },
      {
        "tag": "direct",  //自动选择
        "protocol": "freedom",
        "settings": {}
      },
      {
        "tag": "block", //封锁
        "protocol": "blackhole",
        "settings": {}
      },
      {
        "tag": "warp", //Cloudflare WARP 全局
        "protocol": "socks",
            "settings": {
                "servers": [{
                  "address": "127.0.0.1",
                  "port": 40000,
                  "users": []
                }]}
      },
      {
        "tag": "yto_out", //多伦多服务器出口
        "protocol": "trojan",
            "settings": {
              "servers": [
                {
                  "address": "***",
                  "port": 443,
                  "password": "***",
                  "flow": "xtls-rprx-direct-udp443",
                  "level": 0
                }
              ]
        }
    ],
    "routing": {
      "rules": [
        // IPv4
        {
          "type": "field",
          "outboundTag": "IP4_out",
          "domain": ["geosite:zoom"]
        },

        // IPv6
        {
            "type": "field",
            "outboundTag": "IP6_out",
            "domain": ["geosite:google","geosite:youtube","geosite:netflix"]
        },

        // Cloudflare Warp
        {
            "type": "field", // Social
            "outboundTag": "Warp",
            "domain": ["geosite:twitter","geosite:instagram","geosite:facebook"]
        },
        {
          "type": "field", // Mastodon
          "outboundTag": "warp",
          "domain": ["domain:mastodon.social","domain:mstdn.social","domain:o3o.ca","domain:noc.social","domain:mstdn.ca"]
        },
        {
          "type": "field", // 中国大陆
          "outboundTag": "warp",
          "domain": ["geoip:cn"]
        },
        {
            "type": "field", // Archive
            "outboundTag": "warp",
            "domain": ["domain:archive.ph","domain:archive.today","domain:archive.org"]
        },
        
        // Auto
        {
          "type": "field", // IP Test
          "outboundTag": "direct",
          "domain": ["ip.sb","ipinfo.io"]
        },
        
        // ALL
        {
          "type": "field",
          "outboundTag": "direct",
          "network": "udp,tcp"
        },
        
        // Block
        {
            "type": "field", // 私网地址
            "ip": ["geoip:private"],
            "outboundTag": "block"
        }
      ]
    }
  }
暂无评论

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇