SSH 反向代理实现访问内网服务

1、适用场景

主机B不能直接访问主机C

主机C能直接访问主机B


问题:

公司内网机器 10.3.20.102,有个 80 端口的 nginx 服务,想在外网可以直接访问,比如在 192.168.1.254 机器上直接访问 10.3.20.102:80 , 怎么实现?

2、配置 ssh 方向代理实现

// 10.3.20.102 上的配置

# curl 10.3.20.102:80

10.3.20.102

# ssh -fCNR 9998:localhost:80 root@120.77.154.31

root@120.77.154.31's password: 输入 120.77.154.31 机器的密码

# ps -ef|grep ssh

root 64758 1 0 Jul17 ? 00:00:06 sshd: root@pts/0

root 72706 1 0 13:49 ? 00:00:00 /usr/sbin/sshd -D

root 72858 72706 0 14:10 ? 00:00:00 sshd: root@pts/1

root 72921 1 0 14:27 ? 00:00:00 ssh -fCNR 9998:localhost:80 root@120.77.154.31

root 72923 64760 0 14:27 pts/0 00:00:00 grep --color=auto ssh

// 120.77.154.31 上的配置(买的云服务器)

# ssh -fCNL "*:80:localhost:9998" localhost

root@localhost's password: 输入 120.77.154.31 机器的密码

# ps -ef|grep ssh

root 1697 1 0 13:50 ? 00:00:00 /usr/sbin/sshd

root 1801 1697 0 14:07 ? 00:00:00 sshd: root@pts/0

root 1849 1697 0 14:10 ? 00:00:00 sshd: root

root 1854 1697 0 14:10 ? 00:00:00 sshd: root

root 1870 1697 0 14:27 ? 00:00:00 sshd: root

root 1875 1697 0 14:28 ? 00:00:00 sshd: root

root 1885 1 0 14:28 ? 00:00:00 ssh -fCNL *:80:localhost:9998 localhost

root 1898 1803 0 14:49 pts/0 00:00:00 grep ssh

3、192.168.1.254 上测试能否访问 10.3.20.102:80 服务

# curl 120.77.154.31:80

10.3.20.102

参考:实战 SSH 端口转发

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容