Using Packetriot to Access OctoPrint Remotely
Tags: octoprint, packetriot, tunneling, remote
Published: 2021-05-12 15:25:50

## Introduction

Welcome! This is a pretty straight-forward tutorial on setting up Packetriot. Although intended for OctoPrint, this is pretty software-agnostic, and thus, can be followed for pretty much any local service. I will be doing this on an Orange Pi PC+ running Armbian (Debian) Buster. This should work for any Debian-like OS such as PopOS and Ubuntu.

For this tutorial, you'll need:
* A Domain
* Basic Linux knowledge
* A Packetriot Account ([Get one here](https://packetriot.com))

If you're not running a Debian-like OS, additional download instructions are available [here](https://packetriot.com/downloads).

If at any point you get stuck, check out Packetriot's incredibly extensive documentation [here](https://docs.packetriot.com/).

Now, let's get into it!

## Install Packetriot

#### Install the GPG key and make sure apt can work with GPG signed packages and HTTPS sources.

```bash
sudo apt-get install apt-transport-https gnupg -y

wget -qO - https://download.packetriot.com/linux/debian/pubkey.gpg | sudo apt-key add -
```

#### Setup the Packetriot source in the apt sources directory.

```bash
echo "
deb [arch=amd64] https://download.packetriot.com/linux/debian/buster/stable/non-free/binary-amd64 / 
deb [arch=i386]  https://download.packetriot.com/linux/debian/buster/stable/non-free/binary-i386  / 
deb [arch=armhf] https://download.packetriot.com/linux/debian/buster/stable/non-free/binary-armhf / 
deb [arch=arm64] https://download.packetriot.com/linux/debian/buster/stable/non-free/binary-arm64 / 
" | sudo tee /etc/apt/sources.list.d/packetriot.list
```

#### Update the apt sources and install the client.

```bash
sudo apt-get update

sudo apt-get install pktriot
```

## Add a Domain

In order to have a static domain, you'll either need to have a paid plan or provide your own domain. In this tutorial, we'll opt for the latter.

On the Packetriot site: 
1. Go to `Domains` -> `Custom`
2. Click `Verify Domain`.
3. Enter your domain name.
4. Click `Submit`.

Now, Packetriot will show you a long string of text that you need to copy. In your DNS config in your domain registrar, you will have to create a new `TXT` record. Paste in the `TXT Record` from Packetriot and wait a few minutes. Once the domain is verified, continue to the next step.

## Enable Packetriot

Now that our domain is setup, we will actually create the tunnel. First, we enable the Packetriot service so it'll start on the server's startup. Then we will login and create the tunnel. When you run configure, make sure you choose option `1`.

```bash
sudo systemctl enable pktriot
sudo -u pktriot pktriot configure
```
After the configuration has been run, you'll be provided with an IPv4. Take this and create a new `A` record in your domain registrar's DNS, same as before with the `TXT` record. This must be the same domain as registered earlier.

Next, we will run the following command to tell the tunnel where to connect. The first part is not a typo; it is telling the server to run the command as the `pktriot` user, and then running the `pktriot` command. Change `example.com` and `80` to the relevant fields. I.e. your domain and port, respectively. For OctoPrint, this will be 5000 if no reverse proxy has been setup. Additionally, change `127.0.0.1` to the appropriate IP if not being run on the same server as the server you are tunneling.

```bash
sudo -u pktriot pktriot tunnel http add --domain example.com --destination 127.0.0.1 --http 80 --letsencrypt
```

And finally, start the Packetriot service. This may take a few minutes to get the SSL certificates. Once it is done, you can go to your URL and access your server from anywhere!

```bash
sudo systemctl start pktriot
```

Thank you so much for following allong with this tutorial! If you liked it, had any problems, or found any errors, let me know in the comments down below!

Have a great day!