通过使用 tcpmux 类型的代理,您可以实现多个 SSH 服务通过同一端口进行暴露。这种方法还适用于任何支持 HTTP Connect 代理连接方式的客户端,以实现端口的复用。
一、在公网IP的服务器机器上部署frps
假设公网服务器的IP为 1.2.3.4
修改frps.toml文件
# 服务器端口
bindPort = 5000
kcpBindPort = 5000
tcpmuxHTTPConnectPort = 5022 # tcpmux端口
二、在内网机器上部署frpc
1. 在内网机器A上配置
将a.zengwu.com.cn
解析到IP1.2.3.4
# 服务器域名端口
serverAddr = "1.2.3.4"
serverPort = 5000
# A内网服务器SSH配置
[[proxies]]
name = "ssha"
type = "tcpmux"
multiplexer = "httpconnect"
customDomains = ["a.zengwu.com.cn"]
localIP = "127.0.0.1"
localPort = 22
2. 在内网机器B上配置
将b.zengwu.com.cn
解析到IP1.2.3.4
# 服务器域名端口
serverAddr = "1.2.3.4"
serverPort = 5000
# A内网服务器SSH配置
[[proxies]]
name = "ssha"
type = "tcpmux"
multiplexer = "httpconnect"
customDomains = ["b.zengwu.com.cn"]
localIP = "127.0.0.1"
localPort = 22
三、在需要连接的客户端机上配置
1. 在命令行中使用ssh客户端连接
在要连接的客户端机器上,需要使用HTTP Connect 代理连接,这里可以使用socat来实现。
- Linux
# Ubuntu/Debian apt-get install socat # CentOS/RHEL yum install socat
- macOS
brew install socat
- Windows
可以通过Cygwin来安装.
- 使用ssh客户端连接
# 连接A机器
ssh -o "proxycommand=socat - PROXY:1.2.3.4:%h:%p,proxyport=5022" root@a.zengwu.com.cn
# 连接B机器
ssh -o "proxycommand=socat - PROXY:1.2.3.4:%h:%p,proxyport=5022" root@b.zengwu.com.cn
2. 使用XShell客户端中连接
- 设置链接信息
主机设置为a.zengwu.com.cn
,端口为22
- 添加代理
代理设置为HTTP,主机填写公网服务器的IP1.2.3.4
,端口为5022
,用户密码为空