醉梦半醒的博客

Centos7 实现ngrok内网穿透

字数统计: 431阅读时长: 2 min
2018/10/10 Share

1.安装go语言环境和git :yum install golang git -y

go env检测环境是否正确

2.git下载ngrok源码

cd /usr/local/

git clone https://github.com/inconshreveable/ngrok.git

3.配置环境变量

export GOPATH=/usr/local/ngrok/

export NGROK_DOMAIN=”iloveflag.com”

4.生成证书:

cd /usr/local/ngrok

openssl genrsa -out rootCA.key 2048

openssl req -x509 -new -nodes -key rootCA.key -subj “/CN=$NGROK_DOMAIN” -days 5000 -out rootCA.pem

openssl genrsa -out server.key 2048

openssl req -new -key server.key -subj “/CN=$NGROK_DOMAIN” -out server.csr

openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 5000

5.覆盖证书

cp rootCA.pem assets/client/tls/ngrokroot.crt

cp server.crt assets/server/tls/snakeoil.crt

cp server.key assets/server/tls/snakeoil.key

6.生成服务端与客户端

cd /usr/local/ngrok/

GOOS=linux GOARCH=amd64 make release-server

GOOS=windows GOARCH=amd64 make release-client

7.生成的文件在/usr/local/ngrok/bin

8.后台启动服务端:

编写start.sh文件如下:

nohup ./ngrokd -domain=”iloveflag.com” -httpAddr=”:80″ -httpsAddr=”:8081″ -tunnelAddr=”:4443″&

 

运行:bash start.sh

9.将windows_amd64下面的ngrok.exe拷贝到桌面,并且配置ngrok.cnf文件和start脚本

 

 

ngrok.cnf:

——————————————————

server_addr: “iloveflag.com:4443”

trust_host_root_cert: false

tunnels:

http:

subdomain: “www”

proto:

http: “80”

https:

subdomain: “www”

proto:

https: “443”

mstsc:

remote_port: 3389

proto:

tcp: “127.0.0.1:3389”

———————————————

Tip:需要符合yaml语言规范,检查地址: http://www.yamllint.com/

 

 

 

start.bash:

————————————————

ngrok -config=ngrok.cfg start http https mstsc

————————————————-

 

 

10.在客户端上运行start.bat

 

11.远程连接:

 

参考:https://segmentfault.com/a/1190000014094827

 

CATALOG