diff --git a/client/proxy/proxy.go b/client/proxy/proxy.go index 98a8a672..1cf477df 100644 --- a/client/proxy/proxy.go +++ b/client/proxy/proxy.go @@ -305,8 +305,12 @@ func (pxy *XTCPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) { ProxyName: pxy.cfg.ProxyName, Sid: natHoleSidMsg.Sid, } + serverAddr := pxy.clientCfg.NatHoleServerAddr + if serverAddr == "" { + serverAddr = pxy.clientCfg.ServerAddr + } raddr, _ := net.ResolveUDPAddr("udp", - net.JoinHostPort(pxy.clientCfg.ServerAddr, strconv.Itoa(pxy.serverUDPPort))) + net.JoinHostPort(serverAddr, strconv.Itoa(pxy.serverUDPPort))) clientConn, err := net.DialUDP("udp", nil, raddr) if err != nil { xl.Error("dial server udp addr error: %v", err) diff --git a/client/visitor.go b/client/visitor.go index 1d7386f7..ee15f283 100644 --- a/client/visitor.go +++ b/client/visitor.go @@ -210,8 +210,12 @@ func (sv *XTCPVisitor) handleConn(userConn net.Conn) { return } + serverAddr := sv.ctl.clientCfg.NatHoleServerAddr + if serverAddr == "" { + serverAddr = sv.ctl.clientCfg.ServerAddr + } raddr, err := net.ResolveUDPAddr("udp", - net.JoinHostPort(sv.ctl.clientCfg.ServerAddr, strconv.Itoa(sv.ctl.serverUDPPort))) + net.JoinHostPort(serverAddr, strconv.Itoa(sv.ctl.serverUDPPort))) if err != nil { xl.Error("resolve server UDP addr error") return diff --git a/conf/frpc_full.ini b/conf/frpc_full.ini index 29f6bcab..49e5b471 100644 --- a/conf/frpc_full.ini +++ b/conf/frpc_full.ini @@ -6,6 +6,10 @@ server_addr = 0.0.0.0 server_port = 7000 +# Specify another address of the server to connect for nat hole. By default, it's same with +# server_addr. +# nat_hole_server_addr = 0.0.0.0 + # The maximum amount of time a dial to server will wait for a connect to complete. Default value is 10 seconds. # dial_server_timeout = 10 diff --git a/pkg/config/client.go b/pkg/config/client.go index 906ee985..b4cb4d15 100644 --- a/pkg/config/client.go +++ b/pkg/config/client.go @@ -35,6 +35,9 @@ type ClientCommonConf struct { // ServerAddr specifies the address of the server to connect to. By // default, this value is "0.0.0.0". ServerAddr string `ini:"server_addr" json:"server_addr"` + // Specify another address of the server to connect for nat hole. By default, it's same with + // ServerAddr. + NatHoleServerAddr string `ini:"nat_hole_server_addr" json:"nat_hole_server_addr"` // ServerPort specifies the port to connect to the server on. By default, // this value is 7000. ServerPort int `ini:"server_port" json:"server_port"`