内网穿透Ngrok

了解Ngrok原理 白话文 通俗易懂

Ngrok 代替了花生壳 花生壳免费的隔三差五的就不能访问了 Ngrok是一款免费开源的软件 稳定性强
但是Ngrok到了1.x项目的状态不在开发 支持维护
Ngrok 2.x 是1.x的继承者 也是当前所有开发工作的重点 但是他的源码不可用 是要收费的

Ngrok1.x是开源 但是不维护了
Ngrok 2.x 是闭源的 收费的
插入一张图一片了解什么事内网穿透
在这里插入图片描述

实验环境

系统 Ip 端口
Centos 7.5(服务器) 192.168.200.10 8080
Centos 7.5(客户端) 192.168.200.20 80

先安装服务端 服务端是 1.x (1.0-1.8)

在安装客户端 客户端是 2.x

1.0 安装git ()

# shell~    yum -y install git
注意git版本应大于1.7.9.5

1.1配置go环境

#下载go源码包
#shell~ wget https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz

1.2 解压到/usr/local/

#shell~ tar xf go1.7.linux-amd64.tar.gz -C /usr/local

1.3 配置环境变量

#shell~    tail -f 2 /etc/profile
export GOROOT=/usr/local/go
export PATH=$GOROOT/bin:$PATH
保存退出然后生效环境变量
#shell~  /etc/profile

1.4: 查看go环境是否配置成功

#shell~  version		
go version go1.7 linux/amd64

1.5下载Ngrok源码包进行编译 服务端安装

#shell~  /usr/local/
#shell~  git clone https://github.com/inconshreveable/ngrok.git
#shell~  cd ngrok/

Ngrok需要一个域名这里采用test.ngrok.com作为本次实验的域名

1.6 生成证书

#shell~  openssl genrsa -out rootCA.key 2048

#shell~ openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=a.a.com(需要映射域名)" -days 5000 -out rootCA.pem

#shell~  openssl genrsa -out device.key 2048

#shell~  openssl req -new -key device.key -subj "/CN=需要映射域名a.a.com" -out device.csr

#shell~   openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000

1.7 本目录下面应该是生成六个文件 用他们来替换掉默认的证书文件 替换掉就行

#shell~  cp rootCA.pem assets/client/tls/ngrokroot.crt
#shell~  cp device.crt assets/server/tls/snakeoil.crt 
#shell~  cp device.key assets/server/tls/snakeoil.key 

1.8 开始编译Ngrok

#shell~  pwd
/usr/local/ngrok/

#shell~  make release-server  

在这里插入图片描述
出现这种情况代表成功了 !!!

2.4 我们可以在ngrok的/bin目录中找到ngrokd 我们把Ngrok启动起来

#shell~  ./bin/ngrokd -domain=”ngrok.com(你的域名)” -httpAddr=”:8080”

出现下面类似内容 测说明我们的服务端Ngrokd正常运行了
[23:18:27 CST 2016/08/23] [INFO] (ngrok/log.(*PrefixLogger).Info:83) [registry] [tun] No affinity cache specified
[23:18:27 CST 2016/08/23] [INFO] (ngrok/log.Info:112) Listening for public http connections on [::]:8080
[23:18:27 CST 2016/08/23] [INFO] (ngrok/log.Info:112) Listening for public https connections on [::]:443
[23:18:27 CST 2016/08/23] [INFO] (ngrok/log.Info:112) Listening for control and proxy connections on [::]:4443
[23:18:27 CST 2016/08/23] [INFO] (ngrok/log.(*PrefixLogger).Info:83) [metrics] Reporting every 30 seconds

到这里服务端已经安装好了

2.0客户端安装

其实客户端安装和服务端安装基本是没有差别的

2.1 安装git

#shell~  yum -y install git

注意git版本应大于1.7.9.5

2.2: 配置go环境

#下载go源码包

#shell~  wget https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz

2.3解压到/usr/local/

#shell~  tar xf go1.7.linux-amd64.tar.gz -C /usr/local

2.4 :配置环境变量

#shell~  tail -f 2 /etc/profile
export GOROOT=/usr/local/go
export PATH=$GOROOT/bin:$PATH
保存退出然后生效环境变量
source /etc/profile

2.5: 查看go环境是否配置成功

#shell~  go version		
go version go1.7 linux/amd64

2.6下载Ngrok源码包进行编译

#shell~  cd /usr/local/
#shell~  git clone https://github.com/inconshreveable/ngrok.git
#shell~  cd ngrok/

2.7 这个地方不需要生成证书 而是需要去服务端把三个配置文件拷过来

rootCA.pem
device.crt
device.key

#shell~  cd /usr/local/ngrok/assets
#shell~  scp roo@192.168.200.10/usr/local/ngrok/rootCA.pem  client/tls/ngrokroot.crt
#shell~  scp roo@192.168.200.10/usr/local/ngrok/device.crt server/tls/snakeoil.crt 
#shell~  scp roo@192.168.200.10/usr/local/ngrok/device.key server/tls/snakeoil.key 

2.8 开始编译

#shell~  make release-client

出现下面这样代表成功
bin/go-bindata -nomemcopy -pkg=assets -tags=release
-debug=false
-o=src/ngrok/client/assets/assets_release.go
assets/client/…
bin/go-bindata -nomemcopy -pkg=assets -tags=release
-debug=false
-o=src/ngrok/server/assets/assets_release.go
assets/server/…
go get -tags ‘release’ -d -v ngrok/…
go install -tags ‘release’ ngrok/main/ngrok

2.9 编写客户端配置文件

#shell~  pwd
/usr/local/ngrok/
#shell~  cat ngrok.cfg
server_addr: “test.ngrok.com:4443”
Trust_host_root_certs: false

启动ngrok

#shell~  ./bin/ngrok -config=ngrok.cfg -subdomain=test 80

客户端ngrok正常显示

#客户端ngrok正常显示 (Ctrl+C to quit)

Tunnel Status online
Version 1.7/1.7
Forwarding http://ngrok.test.com:8080 -> 127.0.0.1:80
Forwarding https://ngrok.dingdayu.com:8080 -> 127.0.0.1:80
Web Interface 127.0.0.1:4040

客户端后台运行命令

setsid ngrok -config=ngrok.cfg -subdomain=test 80
-subdomain是域名的开头

服务器后台运行命令

nohup ngrokd -domain=“ngrok.com” -httpAddr=":8080" &

最后

lh@linux
本次实验 外网服务器是8080 内网服务器是 80
如果报错请留言
[参考] (https://blog.csdn.net/weixin_38628533/article/details/83476294)

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值