使用ngrok实现内网穿透

来源:互联网 发布:淘宝描述代码 编辑:程序博客网 时间:2024/05/18 02:35

安装依赖项

sudo apt-get install supervisorsudo apt-get install mercurial git gcc 

安装go

tar -C /usr/local -xzf go1.8.1.linux-amd64.tar.gzecho "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc使环境变量生效source .bashrc 

同步代码

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

生成密匙

openssl genrsa -out rootCA.key 2048openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=lianghuanhan.club" -days 5000 -out rootCA.pemopenssl genrsa -out device.key 2048openssl req -new -key device.key -subj "/CN=lianghuanhan.club" -out device.csropenssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000

复制密匙

cp rootCA.pem assets/client/tls/ngrokroot.crtcp device.crt assets/server/tls/snakeoil.crtcp device.key assets/server/tls/snakeoil.key

编译源码

make release-servermake release-client编译win7 64位客户端GOOS=windows GOARCH=amd64 make release-client

启动服务器端

./ngrokd -domain="lianghuanhan.club" -httpAddr=":8088" -httpsAddr=":8089"

启动客户端

编辑配置文件vim ngrok.cfg 写入以下数据server_addr: lianghuanhan:4443trust_host_root_certs: false

linux 64位客户端

监听http 80端口./ngrok -subdomain pub -proto=http -config=ngrok.cfg 80监听tcp 22端口./ngrok -subdomain pub -proto=tcp -config=ngrok.cfg 22

windows 64位客户端

监听远程桌面端口ngrok.exe -subdomain pub -proto=tcp -config=ngrok.cfg 3389

在浏览器中输入:localhost:4040 (在客户端上)

可以查看所有的请求情况!

view

注意事项

1.为lianghuanhan.club添加dns解析

添加两条A记录:lianghuanhan.club和*.lianghuanhan.club,指向lianghuanhan.club所在的服务器ip。

2.客户端ngrok.cfg中server_addr后的值必须严格与-domain以及证书中的"/CN=lianghuanhan.club"相同,必须先生成证书,拷贝到相应目录,再编译代码。

0 0