v2fly / v2ray-core

A platform for building proxies to bypass network restrictions.
https://v2fly.org
MIT License
29.76k stars 4.68k forks source link

rule无法实现分流 #2436

Closed zoni-cc closed 1 year ago

zoni-cc commented 1 year ago

你正在使用哪个版本的 V2Ray?

V5.3.0

你的使用场景是什么?

rule控制分流

你看到的异常现象是什么?

分流无法实现,默认走第一个outbounds

你期待看到的正常表现是怎样的?

按照域名 ip设定 实现不同标记 走不同的outbounds

请附上你的配置

服务端配置:

// 在这里附上服务器端配置文件
    "router": {
        "domainStrategy": "AsIs",
        "rule": [
            {
                "inboundTag": "in-01",
                "tag": "direct",
                "domainMatcher": "mph",
                "protocol": ["http", "tls"],    
                "network":  ["tcp,udp"] 
            },
            {
                                 "inboundTag": "in-02",
                "tag": "out-02",
                "domainMatcher": "mph",
                "protocol": ["http", "tls"],    
                "geoDomain": [
                    { 
                        "code": ["tiktok"]
                    }
                ],
                "domain": [
                    { 
                        "type": "Plain",
                        "value":"ibytedtos.com",
                        "value":"ibyteimg.com",
                        "value":"ipstatp.com",
                        "value":"tik-tokapi.com",
                        "value":"tiktok.com",
                        "value":"ibytedtos.com"
                    }
                ]
            },
            {
                "inboundTag": "in-03",
                "Tag": "out-03",
                "domainMatcher": "mph",
                "protocol": ["http", "tls"],
                "geoDomain": [
                    { 
                        "code": "google", 
                        "code": "youtube"
                    }
                ]
            },
            {
                "tag": "blocked",
                "domainMatcher": "mph",
                "protocol": ["http", "tls"],
                "geoip":[
                    {
                        "cidr":[
                            {
                                "ipAddr":"192.168.0.0",
                                "prefix":"16"
                            },
                            {
                                "ipAddr":"172.16.0.0",
                                "prefix":"12"
                            },
                            {
                                "ipAddr":"10.0.0.0",
                                "prefix":"8"                                
                            }
                        ],
                        "code":["private"]
                    }
                ],
                "geoDomain": [
                    { 
                        "code": "category-ads"
                    }
                ],
                "domain": [
                    { 
                        "type": "Plain",
                        "value": "epochtimes"
                    }
                ]
            },
            {
                "tag": "blocked",
                "domainMatcher": "mph",
                "protocol": ["bittorrent"],
                "network":  ["tcp,udp"]
            }
        ]
    }

客户端配置:

// 在这里附上客户端配置

请附上出错时软件输出的错误日志

无错误日志

服务器端错误日志:

// 在这里附上服务器端日志

客户端错误日志:

// 在这里附上客户端日志

请附上访问日志

// 在这里附上服务器端日志

其它相关的配置文件(如 Nginx)和相关日志

如果 V2Ray 无法启动,请附上 --test 命令的输出

如果 V2Ray 服务运行异常,请附上 journal 日志

zoni-cc commented 1 year ago

routing修改为router 也一样

mydogshitgold commented 1 year ago

Your configuration has multiple structural and syntactical errors, which is understandable given that the new v5 configuration schema is still in the draft stage and lacks comprehensive documentation. It might be best to stick with the old format for now until the new one is more stable.

If you want to learn how to write v5 configuration properly, it's worth taking a look at the source code, particularly the corresponding protobuf files (usually has file extension .proto) . Additionally, there's a project that provides a JSON schema for the new configuration format which can be used for autocomplete and validation.

That being said, I made a few modifications to your original configuration, and here it is

  "router": {
    "domainStrategy": "AsIs",
    "rule": [
      {
        "tag": "direct",
        "inboundTag": [
          "in-01"
        ],
        "protocol": [
          "http",
          "tls"
        ],
        "networks": [
          "TCP",
          "UDP"
        ]
      },
      {
        "tag": "out-02",
        "inboundTag": [
          "in-02"
        ],
        "domainMatcher": "mph",
        "geoDomain": [
          {
            "code": "tiktok"
          },
          {
            "domain": [
              {
                "type": "RootDomain",
                "value": "ibytedtos.com"
              },
              {
                "type": "RootDomain",
                "value": "ibyteimg.com"
              },
              {
                "type": "RootDomain",
                "value": "ipstatp.com"
              },
              {
                "type": "RootDomain",
                "value": "tik-tokapi.com"
              },
              {
                "type": "RootDomain",
                "value": "tiktok.com"
              }
            ]
          }
        ]
      },
      {
        "inboundTag": [
          "in-03"
        ],
        "tag": "out-03",
        "domainMatcher": "mph",
        "geoDomain": [
          {
            "code": "google"
          },
          {
            "code": "youtube"
          }
        ]
      },
      {
        "tag": "blocked",
        "domainMatcher": "mph",
        "geoip": [
          {
            "code": "private"
          },
          {
            "cidr": [
              {
                "ipAddr": "192.168.0.0",
                "prefix": 16
              },
              {
                "ipAddr": "172.16.0.0",
                "prefix": 12
              },
              {
                "ipAddr": "10.0.0.0",
                "prefix": 8
              }
            ]
          }
        ]
      },
      {
        "tag": "blocked",
        "domainMatcher": "mph",
        "geoDomain": [
          {
            "code": "category-ads"
          },
          {
            "domain": [
              {
                "type": "RootDomain",
                "value": "epochtimes.com"
              }
            ]
          }
        ]
      },
      {
        "tag": "blocked",
        "protocol": [
          "bittorrent"
        ]
      }
    ]
  }

Does it work for you?


NOTE: I changed the domain.type in your config to RootDomain instead of Plain. I think Plain in this context might not be what you meant.

zoni-cc commented 1 year ago

调整后,依旧无法正常实现分流。(V5的写法比V4啰嗦很多) 调整后配置如下:


{
    "log": {
        "access": "/var/log/v2ray/access.log",
        "error": "/var/log/v2ray/error.log",
        "loglevel": "warning"
    },
    "inbounds": [
        {
            "tag": "in-10086",
            "port": 10086,
            "listen": "0.0.0.0",
            "protocol": "shadowsocks",
            "settings": {
                "method": "aes-256-gcm",
                "password": "password",
                "network": ["tcp","udp"],
                "packetEncoding": ["Packet"]
                },
            "sniffing": {
                "enabled": true,
                "destOverride": ["http", "tls","quic"],
                "metadataOnly":true
                }
        },
        {
            "tag": "in-10087",
            "port": 10087,
            "listen": "0.0.0.0",
            "protocol": "shadowsocks",
            "settings": {
                "method": "aes-256-gcm",
                "password": "password",
                "network": ["tcp","udp"],
                "packetEncoding": ["Packet"]
                },
            "sniffing": {
                "enabled": true,
                "destOverride": ["http", "tls","quic"],
                "metadataOnly":true
                }
        }
    ],
    "outbounds": [
        {
            "protocol": "shadowsocks",
            "settings": {
                "servers": [
                    {
                        "address": "url1",
                        "method": "aes-256-gcm",
                        "password": "password",
                        "port": 50000
                    }
                ]
            },
            "tag": "out-01"
        },
        {
            "protocol": "shadowsocks",
            "settings": {
                "servers": [
                    {
                        "address": "url2",
                        "method": "aes-256-gcm",
                        "password": "password",
                        "port": 50000
                    }
                ]
            },
            "tag": "out-02"
        },
        {
            "protocol": "freedom",
            "settings": {
            "domainStrategy": "AsIs"
            },
            "tag": "direct"
        },
        {
            "protocol": "blackhole",
            "settings": {},
            "tag": "blocked"
        }
    ],
    "router": {
        "domainStrategy": "AsIs",
        "rule": [
            {
                "Tag": "direct",
                "inboundTag": "in-10087",
                "domainMatcher": "mph",
                "protocol": ["http", "tls"],
                "network": ["tcp","udp"]
            },
            {
                "inboundTag": "in-10086",
                "Tag": "out-02",
                "domainMatcher": "mph",
                "protocol": ["http", "tls"],
                "network": ["tcp","udp"],
                "geoDomain": [
                    { 
                        "code": "google"
                    },
                    { 
                        "code": "youtube"
                    }
                ]
            },
            {
                "tag": "blocked",
                "protocol": ["http", "tls"],
                "geoDomain":[
                    { 
                        "code": "category-ads"
                    },
                    {
                        "dimain":[
                            {
                                "type":"Plain",
                                "value":"epochtimes"
                            }
                        ]
                    }
                ]   
            },
            {
                "tag": "blocked",
                "protocol": ["bittorrent"]
            }
        ]
    }
}
mydogshitgold commented 1 year ago

Unluckily, the adjusted v5 configurations you provided still contain numerous structural errors (it seems you are mixed the v4 and v5 format together). It did not pass the test command v2ray test -format=jsonv5 -config config.json.

For instance,

These are only a few of the errors present.

Considering the current situation, it may be prudent to stick with the stable and well-documented v4 format for the time being. The v5 schema appears to be somewhat unstable and lacking in available resources and documentation. While the v5 format may have some newer features and improvements, the v4 format is still a reliable and effective configuration option. Therefore, it may be wise to postpone any attempts to use it until it is more thoroughly developed.

However, if you're still having issues or have to use v5 configuration format , feel free to ask and I'll be happy to help :)

zoni-cc commented 1 year ago

已经用回v4.... 希望V5尽快完善 哈哈