1 摘要
关于玩转内网穿透系列:
玩转内网穿透(1):内网穿透是什么?有什么用
玩转内网穿透(2):CentOS 7使用Ngrok搭建内网穿透服务
本文将玩一点高级的,以实现高端的功能:
(1) 绑定多域名,多端口
(2) 实现远程桌面功能
(3) 开机启动Ngrok内网穿透服务
(4)一切启动都脚本化
2 绑定多域名、多端口、多协议
2.1 配置文件修改
修改客户端配置文件:
ngrok.yml
server_addr: "xxx.com:4443"
trust_host_root_certs: false
tunnels:
api:
subdomain: "api"
proto:
http: 127.0.0.1:8022
remote:
subdomain: "remote"
proto:
http: 192.168.8.56:18022
ssh:
remote_port: 50000
proto:
tcp: 192.168.8.101:22
desktop:
remote_port: 55123
proto:
tcp: 192.168.8.100:3389
配置文件说明:
server_name: 域名+隧道端口(tunnelAddr)
trust_host_root_certs : 当使用ssl/tls证书的时候,需要设置此选项;默认 ngrok 只信任 ngrok.com 域名证书,所以自签名设置为 false
tunnels : 隧道,设置多域名时如此配置
api : 隧道名称
subdomain : 二级域名名称
proto: 隧道协议,常用协议包括: http,tcp,udp
http : 协议名称,后边接内网映射的 ip+端口,这里的 ip 可以为本机(127.0.0.1),也可以为局域网内的其他主机 ip
启动客户端:
d:
cd D:\develop\software\windows_amd64
ngrok.exe -config ngrok.yml start api remote
2.2 启动脚本
windows 启动脚本,在Ngrok客户端软件同一文件夹下创建 start_multi.bat 文件
start_multi.bat :
ngrok.exe -config ngrok.yml start api remote ssh desktop
脚本写好后,下次启动客户端直接双击脚本即可运行
配置文件中包含的隧道,在脚本中都需要体现出来,如果脚本中没有,则启动后不会运行对应的隧道

3 远程桌面连接
Windows 系统自带的远程桌面连接端口为 3389,在步骤2中已经包含了这一端口
使用步骤:
(1) 打开Windows的远程连接功能
win10: 开始 – 设置 – 系统 – 远程桌面 – 「启用远程桌面」,点击打开 – 点击「高级设置」–启用「需要计算机使用网络级别身份验证进行连接」
(2) 使用远程桌面进行连接
win10: 开始 – 输入"远程桌面连接" 进行搜索 – 选择搜索结果 「远程桌面连接」应用程序 – 输入隧道域名+端口 – 点击「连接」 – 输入计算机「用户名」和「密码」 进行远程连接

官方参考:
如何使用远程桌面
使用“远程桌面连接”连接到另一台计算机
3 Ngrok 服务开启启动
编写 Ngrok 服务端 启动脚本 start.sh
cd /usr/local/ngrok/
touch start.sh
sudo chmod +x start.sh
启动脚本内容:
# !/bin/bash
#
# ngrok 启动脚本
# ngrok 目录
ngrokPath=/usr/local/ngrok/
# 代理域名
domain=xxx.com
nohup ${ngrokPath}bin/ngrokd -tlsKey="${ngrokPath}assets/server/tls/snakeoil.key" -tlsCrt="${ngrokPath}assets/server/tls/snakeoil.crt" -domain=${domain} -httpAddr=:5442 -httpsAddr=:5443 -tunnelAddr=":4443" >/dev/null 2>&1 &
其中 xxx.com 为自己的域名
开机启动脚本:
echo "/usr/local/ngrok/start.sh" >> /etc/rc.d/rc.local
sudo chmod +x /etc/rc.d/rc.local
4 参考资料推荐
ngrok绑定多个顶级域名、多个二级域名及转发tcp同时启动的方法
个人公众号:404Code,记录半个互联网人的技术与思考,感兴趣的可以关注.

1472

被折叠的 条评论
为什么被折叠?



