English
Français

Blog of Denis VOITURON

for a better .NET world

Dev-Tunnel to replace NGrok

Posted on 2024-06-02

Introduction

When developing an application for Microsoft Teams, for example, we regularly need a a tool for creating secure tunnels to local servers. Our local development is then accessible from the Internet. Basically, the website being developed on the local machine can be accessed from anywhere via a temporary public URL.

The best-known software for this is NGrok, which does the job perfectly.

But for some months now, Microsoft has been offering an equivalent free solution: Dev Tunnel.

Installation

Before creating a dev tunnel, you must first download and install the Command Line Interface (CLI) tool devtunnel for your operating system. (see all installation commands here).

winget install Microsoft.devtunnel

Login

To start a dev tunnel, you must first log in with a Microsoft or GitHub account. Dev tunnels do not allow you to host tunnels anonymously.

devtunnel user login

Tunnel

Once connected, you can start hosting a tunnel dev using the host command. You must first start your local web server, for example listening on port http 4444, or on the secure port https 5000. You can do this using the dotnet serve tool or any other hosting command.

# Start a HTTP local server
dotnet serve -p 4444 --directory ./

# Start an HTTPS local server
dotnet serve -p 5000 --tls --directory ./

The Dev Tunnel command is then…

devtunnel host -p 4444 --allow-anonymous
devtunnel host -p 5000 --allow-anonymous --protocol https

Each time you run the devtunnel host command, a new temporary domain is created.

Persistent Tunnel

If you want the domain to persist for several days (maximum 30 days):

  1. You need to create a TunnelID
  2. Add one or more listening ports.
  3. You can start the tunnel using its ID.
devtunnel create my-tunnel --allow-anonymous --expiration 30d
devtunnel port create my-tunnel -p 5000

When the Tunnel starts up for the first time, a domain will be generated. It will remain unchanged for the next 30 days.

devtunnel host my-tunnel

Example:

▶️❯ devtunnel create my-tunnel --allow-anonymous --expiration 30d

        Welcome to dev tunnels!
        CLI version: 1.0.1301+f410beb2af

        By using the software, you agree to
          - the dev tunnels License Terms: https://aka.ms/devtunnels/tos
          - the Microsoft Privacy Statement: https://privacy.microsoft.com/privacystatement

        Report issues on GitHub: https://aka.ms/devtunnels/issues
        Use 'devtunnel --help' to see available commands or visit: https://aka.ms/devtunnels/docs

        Tunnel ID             : my-tunnel.euw
        Description           :
        Labels                :
        Access control        : {+Anonymous [connect]}
        Host connections      : 0
        Client connections    : 0
        Current upload rate   : 0 MB/s (limit: 20 MB/s)
        Current download rate : 0 MB/s (limit: 20 MB/s)
        Tunnel Expiration     : 30 days

        Set default tunnel to my-tunnel.

▶️❯ devtunnel port create my-tunnel -p 5000 --protocol https

        Tunnel ID             : my-tunnel.euw
        Port Number           : 5000
        Protocol              : auto
        Access control        : {Inherited: +Anonymous [connect]}
        Client connections    : 0

▶️❯ devtunnel host my-tunnel

        Hosting port: 5000
        Connect via browser: https://hj8h5tk6.euw.devtunnels.ms:5000, https://hj8h5tk6-5000.euw.devtunnels.ms
        Inspect network activity: https://hj8h5tk6-5000-inspect.euw.devtunnels.ms

        Ready to accept connections for tunnel: my-tunnel

Languages

EnglishEnglish
FrenchFrançais

Follow me

Recent posts