If you’re behind a corporate firewall or simply at home behind a router, the IP address coming into the environment will hit the main switch and issue DHCP IP Addresses for the machines (PCs, Laptops, Tablets, Phones, etc) within the network. So, if you try to request your address with the port for your application, it will get lost at the switch and never hit your machine. To get the IP Address coming into the environment, simply google ‘Whats my ip’ or go to whatsmyip.org.

The Dynamic Host Configuration Protocol (DHCP) is a network management protocol used on TCP/IP networks whereby a DHCP server dynamically assigns an IP address and other network configuration parameters to each device on a network so they can communicate with other IP networks. -wikipedia

ngrok is one tool that can create a tunnel and expose an HTTP or HTTPS endpoint for your application running locally to be exposed to others. It automatically handles all the NAT traversal to navigate to down the router and switch paths to you. ngrok has several pricing plans and depending what you need it for, you might be able to get away with the simple free plan.

ngrok has simple getting started commands. Here they are in a nutshell.

  1. Download the executable and copy it to a path on your machine, your user folder works best so you don’t have to specify the path when running ngrok.

Pro Tip

If you’re on a Mac, then using homebrew’s cask for installing ngrok will automatically install ngrok and set the path alias for you so you can fire off ngrok without needing to install it in the right directory or creating an alias.

brew cask install ngrok
  1. Create an account on https://ngrok.com/ and then associate the key you receive upon registering.
ngrok authtoken <YOUR_AUTHTOKEN>
  1. Run ngrok and specify the protocol and port
ngrok http 80

Other examples of commands that you can use with ngrok.

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

This will return a custom URL for you to pass around to others to directly access your services.

ngrok by @inconshreveable                                               (Ctrl+C to quit)

Session Status                online
Account                       DAVID E MANSKE (Plan: Free)
Version                       2.2.8
Region                        United States (us)
Web Interface                 http://127.0.0.1:4040
Forwarding                    http://c93e384c.ngrok.io -> localhost:8100
Forwarding                    https://c93e384c.ngrok.io -> localhost:8100

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

Finally, ngrok has a built in inspector and re-run web portal that allows you to see all the requests/responses that come in to your machine. Open a web browser and navigate to the ngrok local portal.

Photo by Ryan Wallace on Unsplash