[GH-ISSUE #3889] frps 无法监听ipv4地址 #3083

Closed
opened 2026-05-05 13:59:46 -06:00 by gitea-mirror · 6 comments
Owner

Originally created by @iccfish on GitHub (Dec 23, 2023).
Original GitHub issue: https://github.com/fatedier/frp/issues/3889

Bug Description

默认情况下服务端绑定IP地址为0.0.0.0,但是在这种情况下frps仅监听了IPV6地址,IPV4地址并不监听,导致使用IPV4地址无法连接(这里不考虑使用6to4方式进行访问)。
image

已确认 net.ipv6.bindv6only0
image

frpc Version

0.53.2

frps Version

0.53.2

System Architecture

linux/amd64

Configurations

[common]
# A literal address or host name for IPv6 must be enclosed
# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
bind_addr = 0.0.0.0
bind_port = 7000

# udp port to help make udp hole to penetrate nat
#bind_udp_port = 7000

Logs

No response

Steps to reproduce

None.

Affected area

  • Docs
  • Installation
  • Performance and Scalability
  • Security
  • User Experience
  • Test and Release
  • Developer Infrastructure
  • Client Plugin
  • Server Plugin
  • Extensions
  • Others
Originally created by @iccfish on GitHub (Dec 23, 2023). Original GitHub issue: https://github.com/fatedier/frp/issues/3889 ### Bug Description 默认情况下服务端绑定IP地址为0.0.0.0,但是在这种情况下frps仅监听了IPV6地址,IPV4地址并不监听,导致使用IPV4地址无法连接(这里不考虑使用6to4方式进行访问)。 ![image](https://github.com/fatedier/frp/assets/1091653/53f7688e-a90c-4c04-b39d-9a12dc032f09) 已确认 `net.ipv6.bindv6only` 为 `0` ![image](https://github.com/fatedier/frp/assets/1091653/304d89bd-c57a-4307-b68d-d0f1a295525c) ### frpc Version 0.53.2 ### frps Version 0.53.2 ### System Architecture linux/amd64 ### Configurations ``` [common] # A literal address or host name for IPv6 must be enclosed # in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80" bind_addr = 0.0.0.0 bind_port = 7000 # udp port to help make udp hole to penetrate nat #bind_udp_port = 7000 ``` ### Logs _No response_ ### Steps to reproduce None. ### Affected area - [ ] Docs - [X] Installation - [ ] Performance and Scalability - [ ] Security - [ ] User Experience - [ ] Test and Release - [ ] Developer Infrastructure - [ ] Client Plugin - [ ] Server Plugin - [ ] Extensions - [ ] Others
Author
Owner

@jdkcn commented on GitHub (Apr 29, 2024):

请问这个问题是怎么解决的,谢谢。我现在也是这个情况。谢谢!

<!-- gh-comment-id:2081784452 --> @jdkcn commented on GitHub (Apr 29, 2024): 请问这个问题是怎么解决的,谢谢。我现在也是这个情况。谢谢!
Author
Owner

@Silbernitrat commented on GitHub (Jun 22, 2024):

我也遇到这个问题了

<!-- gh-comment-id:2184055278 --> @Silbernitrat commented on GitHub (Jun 22, 2024): 我也遇到这个问题了
Author
Owner

@nanzehua commented on GitHub (Jul 18, 2024):

这个你是怎么解决的?

<!-- gh-comment-id:2235176995 --> @nanzehua commented on GitHub (Jul 18, 2024): 这个你是怎么解决的?
Author
Owner

@yurenchen000 commented on GitHub (Sep 11, 2024):

0. golang net.Listen('tcp', addr)

cause golang default bind all
https://github.com/golang/go/issues/48723
https://pkg.go.dev/net#Listen

net.Listen("tcp", bindAddr)   //bind 4 and 6
net.Listen("tcp4", bindAddr)  //bind 4
net.Listen("tcp6", bindAddr)  //bind 6

1. test patch 'tcp4'

server bind
fe4ca1b/server/service.go (L224)

demo patch (only fix BindAddr, webServer and ProxyBindAddr, for test purpose)
//if the addr is ipv4, only bind tcp4

diff --git a/pkg/util/http/server.go b/pkg/util/http/server.go
index 99bed36..a299164 100644
--- a/pkg/util/http/server.go
+++ b/pkg/util/http/server.go
@@ -16,6 +16,7 @@ package http
 
 import (
 	"crypto/tls"
+	"fmt"
 	"net"
 	"net/http"
 	"net/http/pprof"
@@ -53,7 +54,12 @@ func NewServer(cfg v1.WebServerConfig) (*Server, error) {
 		addr = ":http"
 	}
 
-	ln, err := net.Listen("tcp", addr)
+	proto := "tcp"
+	if net.ParseIP(cfg.Addr).To4()!=nil{
+		proto = "tcp4"
+		fmt.Println("==bind tcp4", addr)
+	}
+	ln, err := net.Listen(proto, addr)
 	if err != nil {
 		return nil, err
 	}
diff --git a/server/proxy/tcp.go b/server/proxy/tcp.go
index a6eae3a..0fb5bc0 100644
--- a/server/proxy/tcp.go
+++ b/server/proxy/tcp.go
@@ -73,7 +73,13 @@ func (pxy *TCPProxy) Run() (remoteAddr string, err error) {
 				pxy.rc.TCPPortManager.Release(pxy.realBindPort)
 			}
 		}()
-		listener, errRet := net.Listen("tcp", net.JoinHostPort(pxy.serverCfg.ProxyBindAddr, strconv.Itoa(pxy.realBindPort)))
+		addr := net.JoinHostPort(pxy.serverCfg.ProxyBindAddr, strconv.Itoa(pxy.realBindPort))
+		proto := "tcp"
+		if net.ParseIP(pxy.serverCfg.ProxyBindAddr).To4()!=nil {
+			proto = "tcp4"
+			fmt.Println("==bind tcp4", addr)
+		}
+		listener, errRet := net.Listen(proto, addr)
 		if errRet != nil {
 			err = errRet
 			return
diff --git a/server/service.go b/server/service.go
index 27c4110..91eb5e9 100644
--- a/server/service.go
+++ b/server/service.go
@@ -221,7 +221,12 @@ func NewService(cfg *v1.ServerConfig) (*Service, error) {
 
 	// Listen for accepting connections from client.
 	address := net.JoinHostPort(cfg.BindAddr, strconv.Itoa(cfg.BindPort))
-	ln, err := net.Listen("tcp", address)
+	proto := "tcp"
+	if net.ParseIP(cfg.BindAddr).To4() != nil {
+		proto = "tcp4"
+		fmt.Println("==bind tcp4", address)
+	}
+	ln, err := net.Listen(proto, address)
 	if err != nil {
 		return nil, fmt.Errorf("create server listener error, %v", err)
 	}

//it didn't fix all net.Listen()


maybe add some option (ex. addr_tcpv4_only)
or host schema (ex. tcp4:8.8.8.8)
for v4 or v6 will better

<!-- gh-comment-id:2344577438 --> @yurenchen000 commented on GitHub (Sep 11, 2024): ## 0. golang net.Listen('tcp', addr) cause golang default bind all https://github.com/golang/go/issues/48723 https://pkg.go.dev/net#Listen ```golang net.Listen("tcp", bindAddr) //bind 4 and 6 net.Listen("tcp4", bindAddr) //bind 4 net.Listen("tcp6", bindAddr) //bind 6 ``` <br> ## 1. test patch 'tcp4' server bind https://github.com/fatedier/frp/blob/fe4ca1b/server/service.go#L224 demo patch (only fix BindAddr, webServer and ProxyBindAddr, for test purpose) //if the addr is ipv4, only bind tcp4 ```diff diff --git a/pkg/util/http/server.go b/pkg/util/http/server.go index 99bed36..a299164 100644 --- a/pkg/util/http/server.go +++ b/pkg/util/http/server.go @@ -16,6 +16,7 @@ package http import ( "crypto/tls" + "fmt" "net" "net/http" "net/http/pprof" @@ -53,7 +54,12 @@ func NewServer(cfg v1.WebServerConfig) (*Server, error) { addr = ":http" } - ln, err := net.Listen("tcp", addr) + proto := "tcp" + if net.ParseIP(cfg.Addr).To4()!=nil{ + proto = "tcp4" + fmt.Println("==bind tcp4", addr) + } + ln, err := net.Listen(proto, addr) if err != nil { return nil, err } diff --git a/server/proxy/tcp.go b/server/proxy/tcp.go index a6eae3a..0fb5bc0 100644 --- a/server/proxy/tcp.go +++ b/server/proxy/tcp.go @@ -73,7 +73,13 @@ func (pxy *TCPProxy) Run() (remoteAddr string, err error) { pxy.rc.TCPPortManager.Release(pxy.realBindPort) } }() - listener, errRet := net.Listen("tcp", net.JoinHostPort(pxy.serverCfg.ProxyBindAddr, strconv.Itoa(pxy.realBindPort))) + addr := net.JoinHostPort(pxy.serverCfg.ProxyBindAddr, strconv.Itoa(pxy.realBindPort)) + proto := "tcp" + if net.ParseIP(pxy.serverCfg.ProxyBindAddr).To4()!=nil { + proto = "tcp4" + fmt.Println("==bind tcp4", addr) + } + listener, errRet := net.Listen(proto, addr) if errRet != nil { err = errRet return diff --git a/server/service.go b/server/service.go index 27c4110..91eb5e9 100644 --- a/server/service.go +++ b/server/service.go @@ -221,7 +221,12 @@ func NewService(cfg *v1.ServerConfig) (*Service, error) { // Listen for accepting connections from client. address := net.JoinHostPort(cfg.BindAddr, strconv.Itoa(cfg.BindPort)) - ln, err := net.Listen("tcp", address) + proto := "tcp" + if net.ParseIP(cfg.BindAddr).To4() != nil { + proto = "tcp4" + fmt.Println("==bind tcp4", address) + } + ln, err := net.Listen(proto, address) if err != nil { return nil, fmt.Errorf("create server listener error, %v", err) } ``` //it didn't fix all net.Listen() ----- maybe add some option (ex. addr_tcpv4_only) or host schema (ex. tcp4:8.8.8.8) for v4 or v6 will better
Author
Owner

@crystal0913 commented on GitHub (Jan 6, 2025):

try this:

firewall-cmd --permanent --zone=public --add-port=<your_bind_port >/tcp
systemctl reload firewalld
<!-- gh-comment-id:2573072820 --> @crystal0913 commented on GitHub (Jan 6, 2025): try this: ``` firewall-cmd --permanent --zone=public --add-port=<your_bind_port >/tcp systemctl reload firewalld ```
Author
Owner

@YufengSoft commented on GitHub (May 16, 2025):

2025年了,frp_0.62.1_linux_amd64 版本依旧出现这个问题

<!-- gh-comment-id:2885841679 --> @YufengSoft commented on GitHub (May 16, 2025): 2025年了,frp_0.62.1_linux_amd64 版本依旧出现这个问题
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#3083
No description provided.