通过 SSH 反向隧道进行内网穿透

通过 SSH 反向隧道进行内网穿透

2018/08/15 运维 内网穿透

通过 SSH 反向隧道进行内网穿透

需求说明

现有内网主机一台(IP:192.168.0.11)和外网主机一台(IP:333.333.333.333),目的是通过客户端在外网环境下访问到内网主机。

环境搭建

安装 autossh

此操作需要在内网主机和外网主机上都进行

yum install wget gcc make -y
wget http://www.harding.motd.ca/autossh/autossh-1.4f.tgz
gunzip -c autossh-1.4f.tgz | tar xvf -
cd autossh-1.4f
./configure
make
make install

内网主机

设置与外网主机的免密登录

ssh-keygen -t rsa
ssh-copy-id root@333.333.333.333

建立与外网服务器间的连接

autossh -M 7281 -fCNR 333.333.333.333:7280:localhost:22 root@333.333.333.333

外网主机

编辑配置文件

编辑配置文件 /etc/ssh/sshd_config, 设置 GatewayPorts yes

设置 localhost 免密

ssh-keygen -t rsa
ssh-copy-id root@localhost

建立反向代理并转发到内网服务器

autossh -M 7281 -fCNL *:1212:localhost:7280 localhost

测试服务

通过第三方 ssh 工具进行连接,连接的 IP 为 333.333.333.333, 端口号为 1212, 用户密码为内网主机的用户名和密码

参考链接

Search

    Table of Contents