使用 ngrok 一句话进行内网穿透/端口映射

ngrok 是什么?

ngrok 是一个用 go 语言编写的反向代理,通过在公共的端点和本地运行的 Web 服务器之间建立一个安全的通道。 ngrok 可捕获和分析所有通道上的流量,便于后期分析和重放。

支持系统

  • Windows
  • Linux
  • Mac
  • FreeBSD

开始使用

1. 下载

官网下载

2. 解压并安装

$ unzip <下载保存路径>/ngrok.zip

3. 创建ngrok账号并配置authtoken

由于使用 ngrok 需要生成映射的动态域名,因此官网使用用户的形式来进行控制和跟踪,所以你需要注册一个账户并通过凭证来使用它。

# 保存你的凭证
$ ./ngrok authtoken <authtoken>

4. 开始穿透内网

# 映射 HTTP 80 端口进行测试
$ ./ngrok http 80

ngrok by @inconshreveable                                                                                                               (Ctrl+C to quit)

Session Status                online
Account                       Evan (Plan: Free)
Version                       2.3.25
Region                        United States (us)
Web Interface                 http://127.0.0.1:4040
Forwarding                    http://bee9c9ff.ngrok.io -> http://localhost:80
Forwarding                    https://bee9c9ff.ngrok.io -> http://localhost:80

Connections                   ttl     opn     rt1     rt5     p50     p90
                              0       0       0.00    0.00    0.00    0.00

已经开启成功,外网直接访问:http://bee9c9ff.ngrok.iohttps https://bee9c9ff.ngrok.io ,即可访问到你的站点。

或你想穿透某一端口,如:TCP,你可以这样来使用

# 映射 TCP 9000 端口进行测试
$ ./ngrok tcp 9000

ngrok by @inconshreveable                                                                                                               (Ctrl+C to quit)

Session Status                online
Account                       Evan (Plan: Free)
Version                       2.3.25
Region                        United States (us)
Web Interface                 http://127.0.0.1:4040
Forwarding                    tcp://0.tcp.ngrok.io:19993 -> localhost:9000

Connections                   ttl     opn     rt1     rt5     p50     p90
                              0       0       0.00    0.00    0.00    0.00

使用帮助

NAME:
   ngrok - tunnel local ports to public URLs and inspect traffic

DESCRIPTION:
    ngrok exposes local networked services behinds NATs and firewalls to the
    public internet over a secure tunnel. Share local websites, build/test
    webhook consumers and self-host personal services.
    Detailed help for each command is available with 'ngrok help <command>'.
    Open http://localhost:4040 for ngrok's web interface to inspect traffic.

EXAMPLES:
    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 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

VERSION:
   2.3.25

AUTHOR:
  inconshreveable - <[email protected]>

COMMANDS:
   authtoken	save authtoken to configuration file
   credits	prints author and licensing information
   http		start an HTTP tunnel
   start	start tunnels by name from the configuration file
   tcp		start a TCP tunnel
   tls		start a TLS tunnel
   update	update ngrok to the latest version
   version	print the version string
   help		Shows a list of commands or help for one command

后续

  • 搭建私有服务器

猜你喜欢

转载自blog.csdn.net/maoxinwen1/article/details/89436993