SSH 反向代理實現(xiàn)訪問內(nèi)網(wǎng)服務

1、適用場景

主機B不能直接訪問主機C

主機C能直接訪問主機B


問題:

公司內(nèi)網(wǎng)機器 10.3.20.102,有個 80 端口的 nginx 服務,想在外網(wǎng)可以直接訪問,比如在 192.168.1.254 機器上直接訪問 10.3.20.102:80 , 怎么實現(xiàn)?

2、配置 ssh 方向代理實現(xiàn)

// 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

參考:實戰(zhàn) SSH 端口轉(zhuǎn)發(fā)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容