1. 概述
ngrok
開源的內(nèi)網(wǎng)穿透工具有很多,例如ngrok草丧、frp狸臣、lanproxy、goproxy昌执、nps等烛亦。
-
fatedier/frp
frp is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the Internet. As of now, it supports TCP and UDP, as well as HTTP and HTTPS protocols, where requests can be forwarded to internal services by domain name.
Frp also has aP2P connect mode
. -
inconshreveable/ngrok
ngrok is a reverse proxy that creates a secure tunnel from a public endpoint to a locally running web service. ngrok captures and analyzes all traffic over the tunnel for later inspection and replay. -
snail007/goproxy
The GoProxy is a high-performance http proxy, https proxy, socks5 proxy, ss proxy, websocket proxies, tcp proxies, udp proxies, game shield, game proxies
其中,F(xiàn)rp的使用方法可以參考我之前的文章《Frp - 內(nèi)網(wǎng)穿透工具使用介紹》懂拾,更深入的用法煤禽,可以閱讀官方文檔。
Ngrok的商業(yè)化工作做得不錯(cuò)岖赋∶使可以在不部署公網(wǎng)服務(wù)
的情況下,免費(fèi)
使用NAT穿透功能贾节。
有兩家基于Ngrok的商業(yè)應(yīng)用汁汗,本文重點(diǎn)介紹第一家:
-
ngrok
Ngrok團(tuán)隊(duì)提供的,基于ngrok 2.x栗涂,ngrok 1.x開源版本已經(jīng)不維護(hù)知牌,2.x好像不開源 -
NATAPP
內(nèi)網(wǎng)穿透 基于ngrok 1.7版本的國內(nèi)高速內(nèi)網(wǎng)映射工具
參考:內(nèi)網(wǎng)穿透工具比較(ngrok,frp,lanproxy,goproxy,nps)
2. Setup與Http服務(wù)代理介紹
2.1. Setup
注冊并登錄ngrok官網(wǎng),可以看到ngrok dashboard頁面斤程。
通過Dashboard角寸,可以下載不同Desktop的運(yùn)行程序,可以查看自己Authtoken忿墅,可以查看已創(chuàng)建的Tunnel
image.png
image.png
2.2. 啟動(dòng)需要Nat外被遠(yuǎn)程訪問
的Http服務(wù)
- Python2啟動(dòng)方式扁藕,F(xiàn)or Test
$ python -m SimpleHTTPServer 8001
Serving HTTP on 0.0.0.0 port 8001 ...
10.210.10.183 - - [09/Apr/2021 09:36:15] "GET / HTTP/1.1" 200 -
- Python3啟動(dòng)方式,F(xiàn)or Test
$ python -m http.server 8001
Serving HTTP on 0.0.0.0 port 8001 ...
10.210.10.183 - - [09/Apr/2021 09:36:15] "GET / HTTP/1.1" 200 -
2.3. 啟動(dòng)Ngrok服務(wù)疚脐,本機(jī)需要能夠訪問到Ngrok官方服務(wù)亿柑,否則,可以借用http_proxy或者其他proxy
$ ./ngrok http 8001
ngrok by @inconshreveable (Ctrl+C to quit) Session Status online
Account shuzhang (Plan: Free)
Version 2.3.39
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://3a2dbc150775.ngrok.io -> http://localhost:8001
Forwarding https://3a2dbc150775.ngrok.io -> http://localhost:8001
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
2.4. 本地打開Console頁面(http://127.0.0.1:4040/status)棍弄,可以查看Tunnel狀態(tài)
image.png
2.5. 關(guān)鍵一步望薄,調(diào)用http請求http://3a2dbc150775.ngrok.io,結(jié)果OK
image.png
3. 其他用法
3.1. ngrok help呼畸,查看推薦用法
$ ./ngrok help
...
ngrok http 80 # secure public URL for port 80 web server
ngrok http -subdomain=baz 8080 # port 8080 available at baz.ngrok.io
ngrok http foo.dev:80 # tunnel to host:port instead of localhost
ngrok http https://localhost # expose a local https server
ngrok tcp 22 # tunnel arbitrary TCP traffic to port 22
ngrok tls -hostname=foo.com 443 # TLS traffic for foo.com to port 443
ngrok start foo bar baz # start tunnels from the configuration file
...
3.2. 編寫ngrok.yml痕支,同時(shí)啟動(dòng)一組Tunnel
3.2.1. 編寫ngrok.yml
$ cat ~/.ngrok2/ngrok.yml
authtoken: 1quWLs7sdwwz4xxxxxxxxxxxxxHX_osfdsdfd56scfwrwerQH1Jt
http_proxy: "http://10.xxx.yyy.zzz:8000"
web_addr: 0.0.0.0:4040
tunnels:
test-http:
addr: 127.0.0.1:8001
proto: http
inspect: true
bind_tls: both
test-ssh:
addr: 127.0.0.1:22
proto: tcp
3.2.2. 啟動(dòng)所有所有Tunnel,也可以啟動(dòng)部分
$ ./ngrok start --all
ngrok by @inconshreveable (Ctrl+C to quit)
Session Status online
Account shuzhang (Plan: Free)
Version 2.3.38
Region United States (us)
Web Interface http://0.0.0.0:4040
Forwarding http://84dc8148b639.ngrok.io -> http://127.0.0.1:8001
Forwarding https://84dc8148b639.ngrok.io -> http://127.0.0.1:8001
Connections ttl opn rt1 rt5 p50 p90
7 0 0.00 0.01 0.00 0.00
HTTP Requests
-------------
GET / 200 OK
GET / 200 OK
GET / 200 OK