场景
ISP出口无分配公网IP地址,查看出口路由WAN接口获取到的地址为:100.xx.xx.xx,为保留地址。外网有主动访问到服务内部需求。现有资源如下:
公有云主机(阿里云)
公网中有LINUX服务器
方案
autoSSH
实现步骤
1、创建SSH证书密钥对
<略>
2、内网服务器配置
2.1 安装软件包
# yum/apt install autossh
2.2 ssh 远程定义
Host server User root Hostname xxx.xxx.xxx.xxx RemoteForward 8848 0.0.0.0:22 RemoteForward 443 0.0.0.0:443 IdentityFile ~/.ssh/stunnel Port 22 PreferredAuthentications publickey ForwardAgent yes
Tips:这里将本机的22、443端口扔到隧道,通过公网主机的8848、443端口访问进来。
2.3 创建systemd服务文件
# cat > /etc/systemd/system/autossh.service << EOF Description=Keep a tunnel to 'Stunnel-Server' open After=network.target [Service] Environment="AUTOSSH_GATETIME=0" ExecStart=/usr/bin/autossh -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" root@server -p 22 [Install] WantedBy=multi-user.target EOF
2.4 服务启动
systemctl daemon-reload systemctl restart autossh
推荐本站淘宝优惠价购买喜欢的宝贝:
本文链接:https://sg.hqyman.cn/post/9553.html 非本站原创文章欢迎转载,原创文章需保留本站地址!
休息一下~~