pureexe
Cadet
- Joined
- Nov 27, 2022
- Messages
- 7
I just switched from the cloud to the NAS, especially TrueNAS core, and Really love it.
However, I tried to google the method to push a file to the public using Cloudflare tunnel on FreeBSD (Especially TrueNAS), and I found a lot of people struggle with the same problem as me, such as [This], [This] and [This]
One simple solution is to use Linux VM instead (recommended by [This comment]). But as a person with a small ram capacity like me, VM is not a good choice.
Cloudflare also doesn't provide any document on FreeBSD even though its library supports FreeBSD. Here, I write a how-to cloudflared on TrueNAS jail for those who might have the same problem in the future.
TLDR;
If you are new to FreeBSD (like me), Here I also provide a step-by-step picture guide
Step-by-Step guide
Step 0: Setup you TrueNAS Core and Cloudflare account
I assume that you already have TrueNAS setup. Here is my machine for demostration.
Also, I assume that your Cloudflare is already pointing to the domain. Here, I use ph.in.th for demonstration.
Step 1: Setup a jail
You can use any jail as you want. But for this guide, I will use FAMP. For the less messy, I prefer to use DHCP (make jail to have different IP from the host)
Step 1.1: Mount the dataset to the jail
I will create this jail for sharing my file to the public. You may skip this step if you use other plugins / jails. But if you use FAMP to share files like me. Mount the dataset to /usr/local/www/apache24/data to share across the internet. I prefer to check read-only. It will prevent the jail that exposing to the internet write something back to my dataset.
Also, if you cannot mount because the folder doesn't empty. You have to delete index.html first by opening the jail's shell and using the command "rm /usr/local/www/apache24/data/index.html"
Step 2: Install cloudflared to the jail
In the jail page, you will found the shell button
Then, type: pkg install cloudflared
It will confirm your request, press "y"
Step 3: Setup on the cloudflare website
Under the traffic tab, it will be a Cloudflare tunnel button, click on Lauch Zero Trust Dashboard
In the zero trush dashboard, go to Access > Tunnels, then click "Create a tunnel"
Then, it will ask to name a tunnel, i will set it to "share" but you can use whatever you prefer.
Then it will give you a "<token>". However, there is no instruction for FreeBSD here. So, just keep the token to use in the next step.
At the bottom, it will have "Next" button, which you can click without waiting for the connectors to be connected.
Now, I will set my domain name to "share.ph.in.th". Set it to the domain that you already have. and for service block. "HTTP://localhost" for the FAMP. you may have to change this option if you have a different kind of jail. For example, the "Qbittorrent" jail will use "HTTP://localhost:8080" instead.
Step 4: Setup the jail with the token
The cloudflared service install that shows on Cloudflare's documentation is not working at all on FreeBSD. Here we will make cloudflared run every time that the jail starts instead.
Type the command:
Don't forgot to replace YOUR-TOKEN with the token from previous step.
Now, Restart the jail! (Go to jail page and click restart)
Step 5: Done!
If everything works as expected, Our tunnel "Share" will show as ACTIVE
Now you can access your jail from anywhere on the internet. I will show accessing share.ph.in.th from Mobile's 5G. And it will show the file inside of the dataset to share with the public.
However, I tried to google the method to push a file to the public using Cloudflare tunnel on FreeBSD (Especially TrueNAS), and I found a lot of people struggle with the same problem as me, such as [This], [This] and [This]
One simple solution is to use Linux VM instead (recommended by [This comment]). But as a person with a small ram capacity like me, VM is not a good choice.
Cloudflare also doesn't provide any document on FreeBSD even though its library supports FreeBSD. Here, I write a how-to cloudflared on TrueNAS jail for those who might have the same problem in the future.
TLDR;
pkg install cloudflared
cloudflared tunnel run --token <your token>
cloudflared tunnel run --token <your token>
If you are new to FreeBSD (like me), Here I also provide a step-by-step picture guide
Step-by-Step guide
Step 0: Setup you TrueNAS Core and Cloudflare account
I assume that you already have TrueNAS setup. Here is my machine for demostration.
Also, I assume that your Cloudflare is already pointing to the domain. Here, I use ph.in.th for demonstration.
Step 1: Setup a jail
You can use any jail as you want. But for this guide, I will use FAMP. For the less messy, I prefer to use DHCP (make jail to have different IP from the host)
Step 1.1: Mount the dataset to the jail
I will create this jail for sharing my file to the public. You may skip this step if you use other plugins / jails. But if you use FAMP to share files like me. Mount the dataset to /usr/local/www/apache24/data to share across the internet. I prefer to check read-only. It will prevent the jail that exposing to the internet write something back to my dataset.
Also, if you cannot mount because the folder doesn't empty. You have to delete index.html first by opening the jail's shell and using the command "rm /usr/local/www/apache24/data/index.html"
Step 2: Install cloudflared to the jail
In the jail page, you will found the shell button
Then, type: pkg install cloudflared
It will confirm your request, press "y"
Step 3: Setup on the cloudflare website
Under the traffic tab, it will be a Cloudflare tunnel button, click on Lauch Zero Trust Dashboard
In the zero trush dashboard, go to Access > Tunnels, then click "Create a tunnel"
Then, it will ask to name a tunnel, i will set it to "share" but you can use whatever you prefer.
Then it will give you a "<token>". However, there is no instruction for FreeBSD here. So, just keep the token to use in the next step.

At the bottom, it will have "Next" button, which you can click without waiting for the connectors to be connected.

Now, I will set my domain name to "share.ph.in.th". Set it to the domain that you already have. and for service block. "HTTP://localhost" for the FAMP. you may have to change this option if you have a different kind of jail. For example, the "Qbittorrent" jail will use "HTTP://localhost:8080" instead.

Step 4: Setup the jail with the token
The cloudflared service install that shows on Cloudflare's documentation is not working at all on FreeBSD. Here we will make cloudflared run every time that the jail starts instead.
Type the command:
Code:
echo "/usr/local/bin/cloudflared tunnel run --token YOUR-TOKEN >/dev/null 2>/dev/null &" > /etc/rc.local
Don't forgot to replace YOUR-TOKEN with the token from previous step.

Now, Restart the jail! (Go to jail page and click restart)

Step 5: Done!
If everything works as expected, Our tunnel "Share" will show as ACTIVE

Now you can access your jail from anywhere on the internet. I will show accessing share.ph.in.th from Mobile's 5G. And it will show the file inside of the dataset to share with the public.

Last edited: