v2fly / v2ray-core

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

V2Ray doesn't respect /etc/gai.conf #79

Closed kidonng closed 4 years ago

kidonng commented 4 years ago

Please read the instruction and answer the following questions before submitting your issue. Thank you. Please answer all the questions with enough information. All issues not following this template will be closed immediately. If you are not sure if your question is truely a bug in V2Ray, please discuss it here first.

1) What version of V2Ray are you using (If you deploy different version on server and client, please explicitly point out)?

Server: unstable-e425876afe56564e82a528661438aa95857632a7 (This issue doesn't appear on latest stable version 4.26.0, only on unstable version)

Client: 4.26.0

2) What's your scenario of using V2Ray? E.g., Watching YouTube videos in Chrome via Socks/VMess proxy.

/etc/gai.conf is the config file for getaddrinfo(3). I want V2Ray prefer IPv4 connections over IPv6 by setting precedence ::ffff:0:0/96 100 in /etc/gai.conf.

3) What did you see? (Please describe in detail, such as timeout, fake TLS certificate etc)

When visiting websites, V2Ray prefers IPv6 connections instead of IPv4 (the websites display server's IPv6 address).

4) What's your expectation?

V2Ray prefers IPv4 connections instead of IPv6 (the websites display server's IPv4 address).

5) Please attach your configuration file (Mask IP addresses before submit this issue).

Server configuration:

{
  "inbounds": [
    {
      "port": 443,
      "protocol": "vmess",
      "settings": {
        "clients": [
          {
            "id": "",
            "alterId": 4
          }
        ]
      },
      "streamSettings": {
        "security": "tls",
        "tlsSettings": {
          "certificates": [
            {
              "certificateFile": "",
              "keyFile": ""
            }
          ]
        }
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom"
    }
  ]
}

Client configuration: Not relevant to this issue, but I'm willing to provide if it is needed.

6) Please attach error logs, especially the bottom lines if the file is large. Error log file is usually at /var/log/v2ray/error.log on Linux.

Server error log:

    // Please attach your server error log here.

Client error log:

    // Please attach your client error log here.

7) Please attach access log. Access log is usually at '/var/log/v2ray/access.log' on Linux.

This is the access log when loglevel is set to debug and then visit http://google.com/search?q=1:

V2Ray 4.26.0 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.14.6 linux/amd64)
A unified platform for anti-censorship.
2020/08/04 11:34:20 [Debug] v2ray.com/core/app/log: Logger started
2020/08/04 11:34:20 [Debug] v2ray.com/core/app/proxyman/inbound: creating stream worker on 0.0.0.0:443
2020/08/04 11:34:20 [Info] v2ray.com/core/transport/internet/tcp: listening TCP on 0.0.0.0:443
2020/08/04 11:34:20 [Info] v2ray.com/core/common/platform/ctlcmd: <v2ctl message>
v2ctl> Read config:  config.json
2020/08/04 11:34:20 [Warning] v2ray.com/core: V2Ray 4.26.0 started
2020/08/04 11:34:22 [Info] [696230717] v2ray.com/core/proxy/vmess/inbound: received request for tcp:google.com:80
2020/08/04 11:34:22 [Info] [696230717] v2ray.com/core/app/dispatcher: default route for tcp:google.com:80
2020/08/04 11:34:22 [Info] [696230717] v2ray.com/core/proxy/freedom: opening connection to tcp:google.com:80
2020/08/04 11:34:22 [Info] [696230717] v2ray.com/core/transport/internet/tcp: dialing TCP to tcp:google.com:80
2020/08/04 11:34:22 x:12577 accepted tcp:google.com:80
2020/08/04 11:34:22 [Info] [696230717] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/freedom: connection ends > context canceled
2020/08/04 11:34:23 [Info] [1389776534] v2ray.com/core/proxy/vmess/inbound: received request for tcp:www.google.com:80
2020/08/04 11:34:23 [Info] [1389776534] v2ray.com/core/app/dispatcher: default route for tcp:www.google.com:80
2020/08/04 11:34:23 [Info] [1389776534] v2ray.com/core/proxy/freedom: opening connection to tcp:www.google.com:80
2020/08/04 11:34:23 [Info] [1389776534] v2ray.com/core/transport/internet/tcp: dialing TCP to tcp:www.google.com:80
2020/08/04 11:34:23 x:12583 accepted tcp:www.google.com:80
2020/08/04 11:34:23 [Info] [1389776534] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/freedom: connection ends > context canceled
2020/08/04 11:34:24 [Info] [615817618] v2ray.com/core/proxy/vmess/inbound: received request for tcp:www.google.com:443
2020/08/04 11:34:24 [Info] [615817618] v2ray.com/core/app/dispatcher: default route for tcp:www.google.com:443
2020/08/04 11:34:24 [Info] [615817618] v2ray.com/core/proxy/freedom: opening connection to tcp:www.google.com:443
2020/08/04 11:34:24 [Info] [615817618] v2ray.com/core/transport/internet/tcp: dialing TCP to tcp:www.google.com:443
2020/08/04 11:34:24 x:12585 accepted tcp:www.google.com:443
2020/08/04 11:34:25 [Info] [3665469194] v2ray.com/core/proxy/vmess/inbound: received request for tcp:www.gstatic.com:443
2020/08/04 11:34:25 [Info] [3665469194] v2ray.com/core/app/dispatcher: default route for tcp:www.gstatic.com:443
2020/08/04 11:34:25 [Info] [3665469194] v2ray.com/core/proxy/freedom: opening connection to tcp:www.gstatic.com:443
2020/08/04 11:34:25 [Info] [3665469194] v2ray.com/core/transport/internet/tcp: dialing TCP to tcp:www.gstatic.com:443
2020/08/04 11:34:25 x:12583 accepted tcp:www.gstatic.com:443
2020/08/04 11:34:26 [Info] [2993755919] v2ray.com/core/proxy/vmess/inbound: received request for tcp:edge.microsoft.com:443
2020/08/04 11:34:26 [Info] [2993755919] v2ray.com/core/app/dispatcher: default route for tcp:edge.microsoft.com:443
2020/08/04 11:34:26 [Info] [2993755919] v2ray.com/core/proxy/freedom: opening connection to tcp:edge.microsoft.com:443
2020/08/04 11:34:26 [Info] [2993755919] v2ray.com/core/transport/internet/tcp: dialing TCP to tcp:edge.microsoft.com:443
2020/08/04 11:34:26 x:12630 accepted tcp:edge.microsoft.com:443
2020/08/04 11:34:27 [Info] [797891954] v2ray.com/core/proxy/vmess/inbound: received request for tcp:fonts.gstatic.com:443
2020/08/04 11:34:27 [Info] [797891954] v2ray.com/core/app/dispatcher: default route for tcp:fonts.gstatic.com:443
2020/08/04 11:34:27 [Info] [797891954] v2ray.com/core/proxy/freedom: opening connection to tcp:fonts.gstatic.com:443
2020/08/04 11:34:27 [Info] [797891954] v2ray.com/core/transport/internet/tcp: dialing TCP to tcp:fonts.gstatic.com:443
2020/08/04 11:34:27 x:12631 accepted tcp:fonts.gstatic.com:443

8) Other configurations (such as Nginx) and logs.

9) If V2Ray doesn't run, please attach output from --test.

The command is usually /usr/bin/v2ray/v2ray --test --config /etc/v2ray/config.json, but may vary according to your scenario.

10) If V2Ray service doesn't run, please attach journal log.

Usual command is journalctl -u v2ray.

11) Additional info

I can still use domainStrategy to force V2Ray use IPv4 address, for example:

{
  "routing": {
    "rules": [
      {
        "type": "field",
        "domain": [
          "geosite:google"
        ],
        "outboundTag": "ipv4"
      }
    ]
  },
  "outbounds": [
    {
      "tag": "ipv4",
      "protocol": "freedom",
      "settings": {
        "domainStrategy": "UseIPv4"
      }
    }
  ]
}
lucifer9 commented 4 years ago

https://golang.org/pkg/net/#hdr-Name_Resolution

You need "force cgo resolver".