[GH-ISSUE #838] frps不设置bind_addr时默认绑定到IPv6 #658

Closed
opened 2026-05-05 12:25:34 -06:00 by gitea-mirror · 23 comments
Owner

Originally created by @qakcn on GitHub (Jun 22, 2018).
Original GitHub issue: https://github.com/fatedier/frp/issues/838

Issue is only used for submiting bug report and documents typo. If there are same issues or answers can be found in documents, we will close it directly.
(为了节约时间,提高处理问题的效率,不按照格式填写的 issue 将会直接关闭。)

Use the commands below to provide key information from your environment:
You do NOT have to include this information if this is a FEATURE REQUEST

What version of frp are you using (./frpc -v or ./frps -v)?

0.20.0

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/qakcn/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/qakcn/go"
GORACE=""
GOROOT="/usr/lib/go-1.10"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.10/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build049950030=/tmp/go-build -gno-record-gcc-switches"

Configures you used:

frps.ini

[common]
bind_addr = 0.0.0.0
bind_port = 7000
kcp_bind_port = 7000

log_file = /var/log/frps.log
log_level =info
log_max_days = 5

Steps to reproduce the issue:

  1. 按上述配置,有没有bind_addr = 0.0.0.0结果一样
  2. 启动frps服务frps -c frps.ini

Describe the results you received:

netstat -nl46检查只有IPv6地址被监听:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:23333           0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN
tcp6       0      0 :::23333                :::*                    LISTEN
tcp6       0      0 :::7000                 :::*                    LISTEN
udp    24576      0 127.0.0.53:53           0.0.0.0:*
udp        0      0 0.0.0.0:68              0.0.0.0:*
udp6       0      0 :::7000                 :::*

Describe the results you expected:

希望监听IPv4地址。

Additional information you deem important (e.g. issue happens only occasionally):

这可能是Go语言通病,之前使用ngrok和kcptun时也有不配置绑定IPv4地址0.0.0.0时默认监听IPv6地址。

我希望能同时监听所有地址。

Can you point out what caused this issue (optional)

Sorry。

Originally created by @qakcn on GitHub (Jun 22, 2018). Original GitHub issue: https://github.com/fatedier/frp/issues/838 Issue is only used for submiting bug report and documents typo. If there are same issues or answers can be found in documents, we will close it directly. (为了节约时间,提高处理问题的效率,不按照格式填写的 issue 将会直接关闭。) Use the commands below to provide key information from your environment: You do NOT have to include this information if this is a FEATURE REQUEST **What version of frp are you using (./frpc -v or ./frps -v)?** 0.20.0 **What operating system and processor architecture are you using (`go env`)?** ``` GOARCH="amd64" GOBIN="" GOCACHE="/home/qakcn/.cache/go-build" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/qakcn/go" GORACE="" GOROOT="/usr/lib/go-1.10" GOTMPDIR="" GOTOOLDIR="/usr/lib/go-1.10/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="g++" CGO_ENABLED="1" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build049950030=/tmp/go-build -gno-record-gcc-switches" ``` **Configures you used:** `frps.ini` ``` [common] bind_addr = 0.0.0.0 bind_port = 7000 kcp_bind_port = 7000 log_file = /var/log/frps.log log_level =info log_max_days = 5 ``` **Steps to reproduce the issue:** 1. 按上述配置,有没有`bind_addr = 0.0.0.0`结果一样 2. 启动frps服务`frps -c frps.ini` **Describe the results you received:** `netstat -nl46`检查只有IPv6地址被监听: ``` Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:23333 0.0.0.0:* LISTEN tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN tcp6 0 0 :::23333 :::* LISTEN tcp6 0 0 :::7000 :::* LISTEN udp 24576 0 127.0.0.53:53 0.0.0.0:* udp 0 0 0.0.0.0:68 0.0.0.0:* udp6 0 0 :::7000 :::* ``` **Describe the results you expected:** 希望监听IPv4地址。 **Additional information you deem important (e.g. issue happens only occasionally):** 这可能是Go语言通病,之前使用ngrok和kcptun时也有不配置绑定IPv4地址`0.0.0.0`时默认**只**监听IPv6地址。 我希望能同时监听所有地址。 **Can you point out what caused this issue (optional)** Sorry。
Author
Owner

@fatedier commented on GitHub (Jun 22, 2018):

所以你的问题是什么?服务不可用?我没看出来问题。

<!-- gh-comment-id:399379394 --> @fatedier commented on GitHub (Jun 22, 2018): 所以你的问题是什么?服务不可用?我没看出来问题。
Author
Owner

@qakcn commented on GitHub (Jun 22, 2018):

只绑定到了:::7000,看前面的协议,是tcp6udp6,没有绑定到0.0.0.0:7000

也就是说设置bind_addr = 0.0.0.0没有生效

<!-- gh-comment-id:399381617 --> @qakcn commented on GitHub (Jun 22, 2018): 只绑定到了:::7000,看前面的协议,是`tcp6`和`udp6`,没有绑定到`0.0.0.0:7000`。 也就是说设置`bind_addr = 0.0.0.0`没有生效
Author
Owner

@fatedier commented on GitHub (Jun 22, 2018):

所以问题是什么?

<!-- gh-comment-id:399382017 --> @fatedier commented on GitHub (Jun 22, 2018): 所以问题是什么?
Author
Owner

@qakcn commented on GitHub (Jun 22, 2018):

我要绑定到0.0.0.0,也就是所有IPv4地址上

<!-- gh-comment-id:399382248 --> @qakcn commented on GitHub (Jun 22, 2018): 我要绑定到`0.0.0.0`,也就是所有IPv4地址上
Author
Owner

@fatedier commented on GitHub (Jun 22, 2018):

ok,那就说明服务没问题,其他需求请自行通过 google 解决。

<!-- gh-comment-id:399382607 --> @fatedier commented on GitHub (Jun 22, 2018): ok,那就说明服务没问题,其他需求请自行通过 google 解决。
Author
Owner

@qakcn commented on GitHub (Jun 22, 2018):

有问题啊,你的设置项没有生效啊,没有按照预期的方式运作

<!-- gh-comment-id:399382852 --> @qakcn commented on GitHub (Jun 22, 2018): 有问题啊,你的设置项没有生效啊,没有按照预期的方式运作
Author
Owner

@fatedier commented on GitHub (Jun 22, 2018):

目前看符合预期,如果你的服务不能通过 ipv4 地址访问,再提 issue。

<!-- gh-comment-id:399383232 --> @fatedier commented on GitHub (Jun 22, 2018): 目前看符合预期,如果你的服务不能通过 ipv4 地址访问,再提 issue。
Author
Owner

@qakcn commented on GitHub (Jun 22, 2018):

没有监听当然是不能访问了……

<!-- gh-comment-id:399383494 --> @qakcn commented on GitHub (Jun 22, 2018): 没有监听当然是不能访问了……
Author
Owner

@fatedier commented on GitHub (Jun 22, 2018):

目前从你的描述来看完全符合预期,请提供更详细的信息,或者自行搜索相关的技术知识。

<!-- gh-comment-id:399383997 --> @fatedier commented on GitHub (Jun 22, 2018): 目前从你的描述来看完全符合预期,请提供更详细的信息,或者自行搜索相关的技术知识。
Author
Owner

@qakcn commented on GitHub (Jun 22, 2018):

我要绑定到3个IP地址,要运行3个服务?

其他服务比如nginx里0.0.0.0就是绑定到所有IPv4地址,这可以说是约定俗成的了,还有我上面的netstat结果里那个0.0.0.0:23333端口是ssh服务的,也没有问题

<!-- gh-comment-id:399384184 --> @qakcn commented on GitHub (Jun 22, 2018): 我要绑定到3个IP地址,要运行3个服务? 其他服务比如nginx里0.0.0.0就是绑定到所有IPv4地址,这可以说是约定俗成的了,还有我上面的netstat结果里那个`0.0.0.0:23333`端口是ssh服务的,也没有问题
Author
Owner

@fatedier commented on GitHub (Jun 22, 2018):

google

<!-- gh-comment-id:399384549 --> @fatedier commented on GitHub (Jun 22, 2018): [google](https://google.com)
Author
Owner

@qakcn commented on GitHub (Jun 22, 2018):

要么就不要把0.0.0.0作为一个有效值,既然要作为有效值,就要按照预期的方式(绑定到IPv4地址)来运作

<!-- gh-comment-id:399384831 --> @qakcn commented on GitHub (Jun 22, 2018): 要么就不要把`0.0.0.0`作为一个有效值,既然要作为有效值,就要按照预期的方式(绑定到IPv4地址)来运作
Author
Owner

@qakcn commented on GitHub (Jun 22, 2018):

https://en.wikipedia.org/wiki/0.0.0.0

As a host address

......

In the context of servers, 0.0.0.0 can mean "all IPv4 addresses on the local machine". If a host has two IP addresses, 192.168.1.1 and 10.1.2.1, and a server running on the host is configured to listen on 0.0.0.0, it will be reachable at both of those IP addresses.

<!-- gh-comment-id:399385359 --> @qakcn commented on GitHub (Jun 22, 2018): https://en.wikipedia.org/wiki/0.0.0.0 As a host address ...... In the context of servers, 0.0.0.0 can mean "all IPv4 addresses on the local machine". If a host has two IP addresses, 192.168.1.1 and 10.1.2.1, and a server running on the host is configured to listen on 0.0.0.0, it will be reachable at both of those IP addresses.
Author
Owner

@fatedier commented on GitHub (Jun 22, 2018):

所以你遇到的问题是服务不能访问,而不是绑定了 ipv6 地址,绑定 ipv6 地址导致服务不能访问只是你的猜测,这不是一个问题。

我一直问你问题是什么,我们应该去解决问题,而不是去解决一个猜测的问题,从而忽略其他因素,你的猜测是因素之一,所以需要验证,提供测试依据。
你可以做的事情很多,通过搜索引擎搜集相关技术资料,自行在不同的环境下做测试,充分理解这个问题。不要只止步于表面的现象就不去深究原因。

<!-- gh-comment-id:399388578 --> @fatedier commented on GitHub (Jun 22, 2018): 所以你遇到的问题是服务不能访问,而不是绑定了 ipv6 地址,绑定 ipv6 地址导致服务不能访问只是你的猜测,这不是一个问题。 我一直问你问题是什么,我们应该去解决问题,而不是去解决一个猜测的问题,从而忽略其他因素,你的猜测是因素之一,所以需要验证,提供测试依据。 你可以做的事情很多,通过搜索引擎搜集相关技术资料,自行在不同的环境下做测试,充分理解这个问题。不要只止步于表面的现象就不去深究原因。
Author
Owner

@qakcn commented on GitHub (Jun 22, 2018):

Go语言的net.Listen在地址缺省的情况下(比如net.Listen("tcp",":7000"))会不监听IPv4端口而只监听IPv6地址,只有指定了tcp4的协议(如net.Listen("tcp4",":7000"))或者IPv4地址(net.Listen("tcp","1.2.3.4:7000"))才会监听。(目前看来0.0.0.0也会不监听IPv4)

这个实际上是Go语言的一个bug吧,去google上也能搜到很多同样的问题。在Go语言解决之前,难道不是只能靠开发者来解决吗。

<!-- gh-comment-id:399395416 --> @qakcn commented on GitHub (Jun 22, 2018): Go语言的`net.Listen`在地址缺省的情况下(比如`net.Listen("tcp",":7000")`)会**不监听**IPv4端口而**只监听**IPv6地址,只有指定了`tcp4`的协议(如`net.Listen("tcp4",":7000")`)或者IPv4地址(`net.Listen("tcp","1.2.3.4:7000")`)才会监听。(目前看来`0.0.0.0`也会不监听IPv4) 这个实际上是Go语言的一个bug吧,去google上也能搜到很多同样的问题。在Go语言解决之前,难道不是只能靠开发者来解决吗。
Author
Owner

@fatedier commented on GitHub (Jun 22, 2018):

请贴出你搜索到的原文或代码注释或相关资料?

<!-- gh-comment-id:399395693 --> @fatedier commented on GitHub (Jun 22, 2018): 请贴出你搜索到的原文或代码注释或相关资料?
Author
Owner

@qakcn commented on GitHub (Jun 22, 2018):

对不起,我的错,0.0.0.0[::]net.Listen里是一样的,虽然netstat里没有0.0.0.0,但是::是通过IPv4-mapped IPv6 addresses同时监听了0.0.0.0的。

抱歉耽误了你的时间。

<!-- gh-comment-id:399404709 --> @qakcn commented on GitHub (Jun 22, 2018): 对不起,我的错,`0.0.0.0`和`[::]`在`net.Listen`里是一样的,虽然netstat里没有`0.0.0.0`,但是`::`是通过IPv4-mapped IPv6 addresses同时监听了0.0.0.0的。 抱歉耽误了你的时间。
Author
Owner

@fatedier commented on GitHub (Jun 22, 2018):

ok,所以你自己是可以解决这个问题的。然后回到最初的问题,为什么你的服务不能访问,相信你也能定位到原因的,如果确实是一个 bug,再提交新的 issue。

<!-- gh-comment-id:399405339 --> @fatedier commented on GitHub (Jun 22, 2018): ok,所以你自己是可以解决这个问题的。然后回到最初的问题,为什么你的服务不能访问,相信你也能定位到原因的,如果确实是一个 bug,再提交新的 issue。
Author
Owner

@hyyz17200 commented on GitHub (Oct 10, 2020):

所以我想知道到底怎么监听v4地址,难道我必须填服务器ip吗

<!-- gh-comment-id:706570546 --> @hyyz17200 commented on GitHub (Oct 10, 2020): 所以我想知道到底怎么监听v4地址,难道我必须填服务器ip吗
Author
Owner

@BisonLeo commented on GitHub (Nov 22, 2021):

https://www.cnblogs.com/kaishirenshi/p/13496475.html
/* If we have the unspecified IPv4 address (0.0.0.0) and

  • the unspecified IPv6 address (::) is next, we need to
  • swap the order of these in the list. We always try to
  • bind to IPv6 first, then IPv4, since an IPv6 socket
  • might be able to receive IPv4 packets if V6ONLY is not
  • enabled, but never the other way around.
  • ... 省略 ...
    */

tcp6 的端口能否通过 ipv4 访问还是要看 AP_ENABLE_V4_MAPPED 程序编译的时候是否开启了
而frp 默认肯定是开启的, 所以不是这个问题导致的.

<!-- gh-comment-id:975696407 --> @BisonLeo commented on GitHub (Nov 22, 2021): https://www.cnblogs.com/kaishirenshi/p/13496475.html /* If we have the unspecified IPv4 address (0.0.0.0) and * the unspecified IPv6 address (::) is next, we need to * swap the order of these in the list. We always try to * bind to IPv6 first, then IPv4, since an IPv6 socket * might be able to receive IPv4 packets if V6ONLY is not * enabled, but never the other way around. * ... 省略 ... */ tcp6 的端口能否通过 ipv4 访问还是要看 AP_ENABLE_V4_MAPPED 程序编译的时候是否开启了 而frp 默认肯定是开启的, 所以不是这个问题导致的.
Author
Owner

@hzdavid commented on GitHub (Apr 9, 2024):

最终的解决方案是什么呢?

<!-- gh-comment-id:2044061146 --> @hzdavid commented on GitHub (Apr 9, 2024): 最终的解决方案是什么呢?
Author
Owner

@shuguang101 commented on GitHub (May 7, 2024):

请贴出你搜索到的原文或代码注释或相关资料?
golang 0.0.0.0会同时监听ipv4 ipv6, 这和nginx等软件的行为不同, nginx 0.0.0.0只会监听ipv4. golang 为了兼容性, 后面不会对这个行为进行修改了。
https://github.com/golang/go/issues/48723
https://github.com/golang/go/issues/17615

<!-- gh-comment-id:2098245895 --> @shuguang101 commented on GitHub (May 7, 2024): > 请贴出你搜索到的原文或代码注释或相关资料? golang 0.0.0.0会同时监听ipv4 ipv6, 这和nginx等软件的行为不同, nginx 0.0.0.0只会监听ipv4. golang 为了兼容性, 后面不会对这个行为进行修改了。 https://github.com/golang/go/issues/48723 https://github.com/golang/go/issues/17615
Author
Owner

@4d4d4d4 commented on GitHub (Jun 11, 2024):

目前我也遇到了这个问题,我的frpc无法连接frps,查看只开放了tcp6由此无法通过telnet命令确认(telnet其他开放tcp端口是正常的)。再次怀疑是只开放tcp6导致的连接超时问题(版本号0.58.1) # @fatedier

<!-- gh-comment-id:2160149601 --> @4d4d4d4 commented on GitHub (Jun 11, 2024): 目前我也遇到了这个问题,我的frpc无法连接frps,查看只开放了tcp6由此无法通过telnet命令确认(telnet其他开放tcp端口是正常的)。再次怀疑是只开放tcp6导致的连接超时问题(版本号0.58.1) # @fatedier
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#658
No description provided.