Multiple SSH Services Sharing the Same Port
Steps
-
Deploy frps on a machine with public IP
Modify the frps.toml file to include the following content (using the most simplified configuration here):
bindPort = 7000 tcpmuxHTTPConnectPort = 5002
-
Deploy frpc on intranet machine A
Create an frpc configuration file, for example frpc.toml, and add the following content to the configuration file:
serverAddr = "x.x.x.x" serverPort = 7000 [[proxies]] name = "ssh1" type = "tcpmux" multiplexer = "httpconnect" customDomains = ["machine-a.example.com"] localIP = "127.0.0.1" localPort = 22
-
Deploy another frpc on intranet machine B
Create an frpc configuration file, for example frpc.toml, and add the following content to the configuration file:
serverAddr = "x.x.x.x" serverPort = 7000 [[proxies]] name = "ssh2" type = "tcpmux" multiplexer = "httpconnect" customDomains = ["machine-b.example.com"] localIP = "127.0.0.1" localPort = 22
-
Access intranet machine A via SSH ProxyCommand
Use SSH ProxyCommand to access intranet machine A, assuming the username is test. Use the following command:
ssh -o 'proxycommand socat - PROXY:x.x.x.x:%h:%p,proxyport=5002' test@machine-a.example.com
To access intranet machine B, simply change the domain name, assuming the username is still test:
ssh -o 'proxycommand socat - PROXY:x.x.x.x:%h:%p,proxyport=5002' test@machine-b.example.com
By following the above steps, you can implement multiple SSH services sharing the same port for access on machines with public IP addresses.