mihomo icon indicating copy to clipboard operation
mihomo copied to clipboard

[Bug] wireguard无法连接,不知道是不是我的配置有问题

Open ghost opened this issue 1 year ago • 26 comments

Verify steps

  • [X] 确保你使用的是本仓库最新的的 mihomo 或 mihomo Alpha 版本 Ensure you are using the latest version of Mihomo or Mihomo Alpha from this repository.
  • [X] 如果你可以自己 debug 并解决的话,提交 PR 吧 Is this something you can debug and fix? Send a pull request! Bug fixes and documentation fixes are welcome.
  • [X] 我已经在 Issue Tracker 中找过我要提出的问题 I have searched on the issue tracker for a related issue.
  • [X] 我已经使用 Alpha 分支版本测试过,问题依旧存在 I have tested using the dev branch, and the issue still exists.
  • [X] 我已经仔细看过 Documentation 并无法自行解决问题 I have read the documentation and was unable to solve the issue.
  • [X] 这是 Mihomo 核心的问题,并非我所使用的 Mihomo 衍生版本(如 OpenMihomo、KoolMihomo 等)的特定问题 This is an issue of the Mihomo core per se, not to the derivatives of Mihomo, like OpenMihomo or KoolMihomo.

Mihomo version

最新

What OS are you seeing the problem on?

Windows

Mihomo config

- { name: 'xxx', type: wireguard, server: xxxx, port: xxx, ip: xxx, private-key: xxx, public-key: xxx, preshared-key: xxx, dns: [xxx], udp: true}

Mihomo log

No response

Description

使用wireguard客户端可以连接,但是使用clash不行

ghost avatar Dec 05 '23 01:12 ghost

我跟你一模一样的问题。。。我一直以为是我自已的问题,我用stash也可以连接上,原生的wireguard也是可以连得上,用clash.meta连不了,sing-box也是连不上,我看了sing-box的配置和clash.meta一样的,估计他们用的同样的代码。我的macos m1,手机用stash没问题,sing-box也不行

skill7899 avatar Dec 05 '23 10:12 skill7899

我也只是单纯的挂clash.meta连接家里的wg,然后分流直接IP访问的网。不是套娃

skill7899 avatar Dec 05 '23 10:12 skill7899

注意字段要写对啊

  - name: "wg"
    type: wireguard
    private-key: eCtXsJZ27+4PbhDkHnB923tkUn2Gj59wZw5wFA75MnU=
    server: 162.159.192.1
    port: 2480
    ip: 172.16.0.2
    ipv6: fd01:5ca1:ab1e:80fa:ab85:6eea:213f:f4a5
    public-key: Cr8hWlKvtDt7nrvf+f0brNQQzabAqrjfBvas9pmowjo=
    allowed-ips: ['0.0.0.0/0']
    # pre-shared-key: 31aIhAPwktDGpH4JDhA8GNvjFXEf/a6+UaQRyOAiyfM=
    # reserved: [209,98,59]  # 字符串格式也是合法的,如"U4An"
    udp: true
    # mtu: 1408
    # dialer-proxy: "ss1"  # 一个出站代理的标识。当值不为空时,将使用指定的 proxy/proxy-group 发出连接
    # remote-dns-resolve: true # 强制dns远程解析,默认值为false
    # dns: [ 1.1.1.1, 8.8.8.8 ] # 仅在remote-dns-resolve为true时生效

snakem982 avatar Dec 05 '23 11:12 snakem982

注意字段要写对啊

  - name: "wg"
    type: wireguard
    private-key: eCtXsJZ27+4PbhDkHnB923tkUn2Gj59wZw5wFA75MnU=
    server: 162.159.192.1
    port: 2480
    ip: 172.16.0.2
    ipv6: fd01:5ca1:ab1e:80fa:ab85:6eea:213f:f4a5
    public-key: Cr8hWlKvtDt7nrvf+f0brNQQzabAqrjfBvas9pmowjo=
    allowed-ips: ['0.0.0.0/0']
    # pre-shared-key: 31aIhAPwktDGpH4JDhA8GNvjFXEf/a6+UaQRyOAiyfM=
    # reserved: [209,98,59]  # 字符串格式也是合法的,如"U4An"
    udp: true
    # mtu: 1408
    # dialer-proxy: "ss1"  # 一个出站代理的标识。当值不为空时,将使用指定的 proxy/proxy-group 发出连接
    # remote-dns-resolve: true # 强制dns远程解析,默认值为false
    # dns: [ 1.1.1.1, 8.8.8.8 ] # 仅在remote-dns-resolve为true时生效

我再对了一次,可以确定参数没有错。直接拷你的,修改配置。难道对wg的服务有要求?

  - name: "wg"
    type: wireguard
    private-key: 0ISqjtiz64LqF8ZMfXQwnWCG0HPR2ZULusWEFspwo14=
    server: xxxxx
    port: 49748
    ip: 10.6.6.3
    
    ipv6: fd42:42:42::3
    public-key: a4yAedNlJv7QtIufeNTIZiFnx2ZUNLrHPq5yyDumM1U=
    allowed-ips: ['0.0.0.0/0']
    pre-shared-key: PRYLKQwhvmgOiG6Bu95CdgnfrpDOeT8ck8jWR2PfSS4=
    # reserved: [209,98,59]  # 字符串格式也是合法的,如"U4An"
    udp: true

这个原生wg的配置 image

下面是clash.meta的报错 image

skill7899 avatar Dec 06 '23 01:12 skill7899

我贴一个我的配置给你参考下,它是可以工作的

 - {"name":"🇺🇸US_104","server":"162.159.192.15","type":"wireguard","country":"🇺🇸US","port":1018,"udp":true,"ip":"172.16.0.2","ipv6":"2606:4700:110:82ef:29f3:592e:ed00:442c","public-key":"bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=","private-key":"qGxQqQKdNfvV15ozIuTRjd0IFfN/yfbBvWe9ZEjvcUU=","mtu":1280,"dns":["8.8.8.8","1.1.1.1"],"allowed-ips":["0.0.0.0/0","::/0"],"remote-dns-resolve":true}
 - {"name":"🇺🇸US_105","server":"162.159.192.162","type":"wireguard","country":"🇺🇸US","port":945,"udp":true,"ip":"172.16.0.2","ipv6":"2606:4700:110:82ef:29f3:592e:ed00:442c","public-key":"bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=","private-key":"qGxQqQKdNfvV15ozIuTRjd0IFfN/yfbBvWe9ZEjvcUU=","mtu":1280,"dns":["8.8.8.8","1.1.1.1"],"allowed-ips":["0.0.0.0/0","::/0"],"remote-dns-resolve":true}

snakem982 avatar Dec 06 '23 03:12 snakem982

我贴一个我的配置给你参考下,它是可以工作的

 - {"name":"🇺🇸US_104","server":"162.159.192.15","type":"wireguard","country":"🇺🇸US","port":1018,"udp":true,"ip":"172.16.0.2","ipv6":"2606:4700:110:82ef:29f3:592e:ed00:442c","public-key":"bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=","private-key":"qGxQqQKdNfvV15ozIuTRjd0IFfN/yfbBvWe9ZEjvcUU=","mtu":1280,"dns":["8.8.8.8","1.1.1.1"],"allowed-ips":["0.0.0.0/0","::/0"],"remote-dns-resolve":true}
 - {"name":"🇺🇸US_105","server":"162.159.192.162","type":"wireguard","country":"🇺🇸US","port":945,"udp":true,"ip":"172.16.0.2","ipv6":"2606:4700:110:82ef:29f3:592e:ed00:442c","public-key":"bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=","private-key":"qGxQqQKdNfvV15ozIuTRjd0IFfN/yfbBvWe9ZEjvcUU=","mtu":1280,"dns":["8.8.8.8","1.1.1.1"],"allowed-ips":["0.0.0.0/0","::/0"],"remote-dns-resolve":true}

机场的我测了可以的,家里的就不行,我看好像不是我个例,有不少人有这种问题。同样的配置在stash也是可以的。所以我就觉得不是跟服务器的wg版本有关系。

skill7899 avatar Dec 06 '23 03:12 skill7899

我也只是单纯的挂clash.meta连接家里的wg,然后分流直接IP访问的网。不是套娃

我之前也遇到过,似乎需要重启clash客户端,或者把server配置成域名,很奇怪,你可以重启下clash试试

ghost avatar Dec 06 '23 04:12 ghost

我也只是单纯的挂clash.meta连接家里的wg,然后分流直接IP访问的网。不是套娃

我之前也遇到过,似乎需要重启clash客户端,或者把server配置成域名,很奇怪,你可以重启下clash试试

试过了,无论是域名还是IP都不行。Handshake 失败

skill7899 avatar Dec 06 '23 06:12 skill7899

我也只是单纯的挂clash.meta连接家里的wg,然后分流直接IP访问的网。不是套娃

我之前也遇到过,似乎需要重启clash客户端,或者把server配置成域名,很奇怪,你可以重启下clash试试

试过了,无论是域名还是IP都不行。Handshake 失败

重启clash试试,要还不行我就不知道了。服务模式,或者tun模式开启,试试

ghost avatar Dec 06 '23 08:12 ghost

我也只是单纯的挂clash.meta连接家里的wg,然后分流直接IP访问的网。不是套娃

我之前也遇到过,似乎需要重启clash客户端,或者把server配置成域名,很奇怪,你可以重启下clash试试

试过了,无论是域名还是IP都不行。Handshake 失败

重启clash试试,要还不行我就不知道了。服务模式,或者tun模式开启,试试

我电脑都重启了~各种模式都试了ORZ

skill7899 avatar Dec 06 '23 09:12 skill7899

如果你的dns模式为fakeip,则必须开启remote-dns-resolve,否则域名服务会无法联通

xishang0128 avatar Dec 06 '23 10:12 xishang0128

如果你的dns模式为fakeip,则必须开启remote-dns-resolve,否则域名服务会无法联通

我直接都用ip了,链接不上,握手不成功。

skill7899 avatar Dec 06 '23 14:12 skill7899

如果你的dns模式为fakeip,则必须开启 remote-dns-resolve,否则域名服务会无法联通

我直接都用ip了,链接不上,握手不成功。

还有一种可能,你ip被墙了

ghost avatar Dec 06 '23 18:12 ghost

如果你的dns模式为fakeip,则必须开启 remote-dns-resolve,否则域名服务会无法联通

我直接都用ip了,链接不上,握手不成功。

还有一种可能,你ip被墙了

我是家里的IPV6,用WG原生可以直接连上的。。不是机场

skill7899 avatar Dec 07 '23 01:12 skill7899

如果你的dns模式为fakeip,则必须开启 remote-dns-resolve,否则域名服务会无法联通

我直接都用ip了,链接不上,握手不成功。

还有一种可能,你ip被墙了

我是家里的IPV6,用WG原生可以直接连上的。。不是机场

那可能确实有点小问题,我自己用也是有时候连接不稳定,可能需要优化下 我试了下,感觉配置文件写的顺序不对也会影响,这有点没道理了,不知道是不是gui封装的问题,或者其他的‘’和“”好像也会影响,甚至远程dns解析开启会连接不上网。也可以去gui那里反馈下

ghost avatar Dec 07 '23 10:12 ghost

如果你的dns模式为fakeip,则必须开启remote-dns-resolve,否则域名服务会无法联通

我现在是连接不上,握手失败。还没有到访问,我访问都是IP的家里的IP。 @Skyxim

skill7899 avatar Dec 09 '23 04:12 skill7899

用12月22号的alpha内核,电脑上可以访问wireguard节点 相同的配置,在11月3号的alpha版本clash meta for android上就连不上,报错也是握手失败

sf467 avatar Dec 22 '23 15:12 sf467

有没有可能是V6的问题,因为我家里没有V4

skill7899 avatar Dec 27 '23 01:12 skill7899

用12月22号的alpha内核,电脑上可以访问wireguard节点 相同的配置,在11月3号的alpha版本clash meta for android上就连不上,报错也是握手失败

同同同

typenoob avatar Jan 23 '24 13:01 typenoob

这个里是dns查询的问题, wireguard要先保证查询的dns没有被污染, 所以首要默认的nameserver应该是cf或者google的,这里有个参考配置

dns:
  enable: true
  listen: 0.0.0.0:53
  ipv6: true
  default-nameserver:
    - 1.1.1.1
    - 8.8.8.8
  nameserver:
    - https://doh.pub/dns-query
    - https://dns.alidns.com/dns-query
  fallback:
    - https://1.1.1.2/dns-query
    - https://1.0.0.2/dns-query
    - https://9.9.9.9/dns-query
  fallback-filter:
    geoip: true
    geoip-code: CN
    ipcidr:
      - 240.0.0.0/4

参考: https://www.sainnhe.dev/post/best-practice-for-dns-in-clash/

Arstman avatar Jan 27 '24 14:01 Arstman

这个里是dns查询的问题, wireguard要先保证查询的dns没有被污染, 所以首要默认的nameserver应该是cf或者google的,这里有个参考配置

dns:
  enable: true
  listen: 0.0.0.0:53
  ipv6: true
  default-nameserver:
    - 1.1.1.1
    - 8.8.8.8
  nameserver:
    - https://doh.pub/dns-query
    - https://dns.alidns.com/dns-query
  fallback:
    - https://1.1.1.2/dns-query
    - https://1.0.0.2/dns-query
    - https://9.9.9.9/dns-query
  fallback-filter:
    geoip: true
    geoip-code: CN
    ipcidr:
      - 240.0.0.0/4

参考: https://www.sainnhe.dev/post/best-practice-for-dns-in-clash/

我的DNS没有开fallback,也是跟你一样的,你的wg是V4的IP,还是V6的IP?

skill7899 avatar Jan 28 '24 02:01 skill7899

这个里是dns查询的问题, wireguard要先保证查询的dns没有被污染, 所以首要默认的nameserver应该是cf或者google的,这里有个参考配置

dns:
  enable: true
  listen: 0.0.0.0:53
  ipv6: true
  default-nameserver:
    - 1.1.1.1
    - 8.8.8.8
  nameserver:
    - https://doh.pub/dns-query
    - https://dns.alidns.com/dns-query
  fallback:
    - https://1.1.1.2/dns-query
    - https://1.0.0.2/dns-query
    - https://9.9.9.9/dns-query
  fallback-filter:
    geoip: true
    geoip-code: CN
    ipcidr:
      - 240.0.0.0/4

参考: https://www.sainnhe.dev/post/best-practice-for-dns-in-clash/

我的DNS没有开fallback,也是跟你一样的,你的wg是V4的IP,还是V6的IP?

v4

Arstman avatar Jan 28 '24 10:01 Arstman

这个里是dns查询的问题, wireguard要先保证查询的dns没有被污染, 所以首要默认的nameserver应该是cf或者google的,这里有个参考配置

dns:
  enable: true
  listen: 0.0.0.0:53
  ipv6: true
  default-nameserver:
    - 1.1.1.1
    - 8.8.8.8
  nameserver:
    - https://doh.pub/dns-query
    - https://dns.alidns.com/dns-query
  fallback:
    - https://1.1.1.2/dns-query
    - https://1.0.0.2/dns-query
    - https://9.9.9.9/dns-query
  fallback-filter:
    geoip: true
    geoip-code: CN
    ipcidr:
      - 240.0.0.0/4

参考: https://www.sainnhe.dev/post/best-practice-for-dns-in-clash/

我的DNS没有开fallback,也是跟你一样的,你的wg是V4的IP,还是V6的IP?

v4

你用V6试一下能不能连上,DDNS改成只获取V6,不过你们这种一般都是连机场,所以给的都是V4,我这种是回家,是V6。

skill7899 avatar Jan 29 '24 06:01 skill7899

可能是内核不支持preshared-key参数

laobanbiefangcu avatar Apr 07 '24 05:04 laobanbiefangcu

就是手机安卓端的问题,相同配置Mac上正常

Wireguard节点放到Surge的手机和MAC也正常

wallinwind avatar May 28 '24 02:05 wallinwind

我也这样, 用wireguard客户端就没问题, 用mihomo就死活连不上

moreoronce avatar Sep 07 '24 16:09 moreoronce