Connect two clients behind NAT

来源:互联网 发布:苏宁程序员工资待遇 编辑:程序博客网 时间:2024/05/22 14:40
原贴:http://cb.vu/unixtoolbox.xhtml

Connect two clients behind NAT

Suppose two clients are behind a NAT gateway and client cliadmin has to connect to client cliuser (the destination), both can login to the gate with ssh and are running Linux with sshd. You don't need root access anywhere as long as the ports on gate are above 1024. We use 2022 on gate. Also since the gate is used locally, the option GatewayPorts is not necessary.
On client cliuser (from destination to gate):
# ssh -R 2022:localhost:22 user@gate            # forwards client 22 to gate:2022
On client cliadmin (from host to gate):
# ssh -L 3022:localhost:2022 admin@gate         # forwards client 3022 to gate:2022
Now the admin can connect directly to the client cliuser with:
# ssh -p 3022 admin@localhost                   # local:3022 -> gate:2022 -> client:22
原创粉丝点击