In this tutorial, I will show you how Inlets helped me to expose my local endpoints from my homelab that sits behind a Carrier-Grade NAT internet connection.

More on Inlets

First, what is Inlets?

Inlets is a project that Alex Ellis developed, that combines a reverse proxy and websockets to expose your local endpoints to the public via a exit-node. A exit-node in this case will be a $5 VPS which provides me with a Static IP.

Inlets also allow you to dynamically bind and discover your local services to DNS entries with automated TLS certificates to a public IP address over a websocket tunnel.

Have a look at the inlets project to learn more.

Inlets Architecture. source:

More on my Current Problem

I like to tinker around a lot as I have a very curious mind, therefore I'm running a couple of VPS's from different providers. But this becomes a costly excercise after some time, so I thought I will look into saving some costs.

I recently upgraded my home internet connection to fibre so I have good download/upload speeds, and since the Raspberry Pi comes now in 4GB models, I thought let's move my hosting to my homelab.

Then I realised my ISP uses a Carrier Grade NAT (CGN), basically everyone on their network shares the same Public IP, which makes it difficult to port forward traffic (like you would normally do), and wanting to use HTTPS on some of my web services made me think that's a no-go zone :( .


Solution: Inlets

I then discovered Inlets. The best of all, it solves my CGN issue and it does HTTPS automatically!! Super easy to setup and works like a charm!

This was literally my reaction:

What we will do today:

  • I will demonstrate building a Python Flask API that will return random data in JSON, which will run on my Raspberry Pi, then use Gunicorn to run the application as a Daemon.
  • Then we will provision a VPS running Ubuntu 18 which will act as my exit-node.
  • Create a DNS "A" Record with the IP of my VPS (
  • Setup Inlets on my exit-node.
  • Setup the Inlets Client on the Raspberry Pi.
  • Showing off the awesomeness of connecting to my API over the internet via HTTPS :D

Flask Application on my Raspberry Pi

Let's head over to my Raspberry Pi to start building our API using Python Flask, install the dependencies:

$ sudo pip install virtualenv
$ virtualenv .venv && source .venv/bin/activate
$ pip install flask Faker gunicorn
$ pip freeze > requirements.txt

Our application will use the Faker library to generate random data which we will return as JSON:

$ cat
from flask import Flask, jsonify
from faker import Faker

app = Flask(__name__)
fake = Faker()

def get_random_data():
    payload = {}
    payload['name'] = fake.first_name()
    payload['surname'] = fake.last_name()
    payload['country'] =
    payload['job'] = fake.job()
    payload['likes_coffee'] = fake.boolean(chance_of_getting_true=50)
    return payload

@app.route('/api/person', methods=['GET'])
def get_person():
    payload = get_random_data()
    return jsonify(payload)

if __name__ == '__main__':

Use gunicorn to start the application as a daemon and expose the endpoint over

$ gunicorn --workers 2 --bind app:app —daemon

Ensure that the port is listening:

$ sudo netstat -tulpn | grep 8000
tcp        0      0*               LISTEN      6698/python

Let's test out our API:

$ curl -s http://localhost:8000/api/person | python -m json.tool
    "country": "Chad",
    "job": "Producer, radio",
    "likes_coffee": true,
    "name": "Jennifer",
    "surname": "Combs"

Setup the DNS Record

Setup the A Record that points to the Public IP of your VPS, in my case =>


Setup the Inlets Exit Node

Once you are logged onto your VPS (in my case), generate your token and save it to your environment:

$ export INLETSTOKEN=$(head -c 16 /dev/urandom | shasum | cut -d" " -f1)

Make sure the token is in your environment:


Installing Inlets is simplicity at it's best, with one easy command execution, which auto detects your architecture:

$ curl -sLS | sudo sh
Downloading package as /tmp/inlets
Download complete.

Running as root - Attempting to move inlets to /usr/local/bin
New version of inlets installed to /usr/local/bin
Version: 2.2.0
Git Commit: 2f5e458d062e55dda9f08109f7b2c3c6919fcdf9

Get the systemd unit file and move it into it's respective path:

$ curl -sLO
$ mv inlets.service /etc/systemd/system/inlets.service

Let's have a look at our inlets.service unit file:

$ cat /etc/systemd/system/inlets.service
Description=Inlets Server Service

ExecStart=/usr/local/bin/inlets server --port=80 --token="${AUTHTOKEN}"


We need to save the token value to the environment file that is referenced from the unit file:

$ echo "AUTHTOKEN=$INLETSTOKEN" > /etc/default/inlets

Ensure the file is readable and the content is as expected:

$ cat /etc/default/inlets

Updating the inlets server port to 8080 so that we can allow Caddy to run on port 80 (and 443):

$ sudo sed -i s/80/8080/g /etc/systemd/system/inlets.service

Since we've created the unit file, reload the systemd daemon, start and enable the inlets service:

$ sudo systemctl daemon-reload
$ sudo systemctl start inlets
$ sudo systemctl enable inlets

Verify that the inlets server is started:

$ systemctl status inlets
- inlets.service - Inlets Server Service
   Loaded: loaded (/etc/systemd/system/inlets.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-08-13 15:55:37 UTC; 16s ago
 Main PID: 2140 (inlets)
    Tasks: 4 (limit: 1109)
   CGroup: /system.slice/inlets.service
           └─2140 /usr/local/bin/inlets server --port=8080 --token=99377fd98062f1559aef634dba7d508443f58979

Aug 13 15:55:37 inlets-exit-node systemd[1]: Started Inlets Server Service.
Aug 13 15:55:37 inlets-exit-node inlets[2140]: 2019/08/13 15:55:37 Server token: "99377fd98062f1559aef634dba7d508443f58979"
Aug 13 15:55:37 inlets-exit-node inlets[2140]: 2019/08/13 15:55:37 Listening on :8080

We will use Caddyserver to listen on port 80 and 443 with automatic HTTPS using Letsencrypt.

Get the latest Caddyserver binary from the releases page for your architecture, in my case its amd64 and download to the current working directory:

$ wget
$ tar -xf caddy_v1.0.1_linux_amd64.tar.gz

Create the Caddyfile in the current working directory and provide your DNS name, where I will use my current one

$ cat Caddyfile

proxy / {

proxy /tunnel {

Create a screen session:

$ screen -S CADDY

When starting the caddy server you will be asked for your email address, for requesting your certificate.

$ ./caddy
Activating privacy features...

Your sites will be served over HTTPS automatically using Let's Encrypt.
By continuing, you agree to the Let's Encrypt Subscriber Agreement at:
Please enter your email address to signify agreement and to be notified
in case of issues. You can leave it blank, but we don't recommend it.
  Email address: [email protected]

2019/08/13 16:05:49 [INFO] acme: Registering account for [email protected]
2019/08/13 16:05:49 [INFO] [] acme: Obtaining bundled SAN certificate
2019/08/13 16:05:50 [INFO] [] AuthURL:
2019/08/13 16:05:50 [INFO] [] acme: use tls-alpn-01 solver
2019/08/13 16:05:50 [INFO] [] acme: Trying to solve TLS-ALPN-01
2019/08/13 16:05:56 [INFO] [] The server validated our request
2019/08/13 16:05:56 [INFO] [] acme: Validations succeeded; requesting certificates
2019/08/13 16:05:58 [INFO] [] Server responded with a certificate.

Serving HTTPS on port 443

Serving HTTP on port 80

Now that the inlets server has been setup, note down the token, as we will need this for the client:


Inlets Client Setup

Head back to the Raspberry Pi as we want to establish the client to connect with our inlets server.

Install inlets on the raspberry pi (client side):

$ curl -sLS | sudo sh
Downloading package as /tmp/inlets-armhf
Download complete.

Running as root - Attempting to move inlets to /usr/local/bin
New version of inlets installed to /usr/local/bin
Version: 2.2.0
Git Commit: 2f5e458d062e55dda9f08109f7b2c3c6919fcdf9

Establistish the connection to the inlets server:

$ inlets client \
> --remote wss:// \
> \
> --token=99377fd98062f1559aef634dba7d508443f58979

2019/08/13 17:22:17 Upstream: =>
2019/08/13 17:22:17 Token: "99377fd98062f1559aef634dba7d508443f58979"
map[X-Inlets-Id:[377cb0d39ec64b2599676673603c0cec] X-Inlets-Upstream:[] Authorization:[Bearer 99377fd98062f1559aef634dba7d508443f58979]]
INFO[0000] Connecting to proxy url="wss://"

Enjoy the awesomeness of Inlets

Now the time to test out our setup. From a remote location, let's make a GET request to our API on our DNS name via HTTPS protocol:

$ curl -iv

*   Trying
* Connected to ( port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-ECDSA-AES256-GCM-SHA384
* ALPN, server accepted to use h2
* Server certificate:
*  subject:
*  start date: Aug 13 15:05:57 2019 GMT
*  expire date: Nov 11 15:05:57 2019 GMT
*  subjectAltName: host "" matched cert's ""
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7f811c804400)
> GET /api/person HTTP/2
> Host:
> User-Agent: curl/7.54.0
> Accept: */*
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 200
HTTP/2 200
< content-type: application/json
content-type: application/json
< date: Tue, 13 Aug 2019 16:28:01 GMT
date: Tue, 13 Aug 2019 16:28:01 GMT
< server: Caddy
server: Caddy
< server: gunicorn/19.9.0
server: gunicorn/19.9.0
< content-length: 105
content-length: 105

{"country":"Honduras","job":"Financial planner","likes_coffee":false,"name":"Mark","surname":"Delacruz"}
* Connection #0 to host left intact

Pretty sweet right?

Testing it via our browser:


Viewing the certificate:


Thank You

Inlets really helped me out connecting to my homelab via the CGN setup that my ISP has and my exit-node has a Static IP, so I don't need to deal with IP's changing which allows me to not worry about HTTPS issues along the line.

Well done to Alex Ellis for developing this!

Thanks for reading. If you would like to check out more of my content, check out my website at or follow me on Twitter @ruanbekker