Skip to main content

Every Fly.io organization comes with a private network that lets all your apps connect to each other. This is super convenient when you need to have microservices call each other’s endpoints or use Flycast to let your private apps turn off when you’re not using them. However, this isn’t just limited to your apps. You can jack into this network with WireGuard. This blueprint shows you how to create a WireGuard peer to your private network and connect to it so that you can access it from anywhere.

Prerequisites

To get started, you need to have the following:

Steps

To create a WireGuard peer, you need the following information:
  • The organization you want to create the peer in, such as your personal organization.
  • The Fly.io region that’s closest to you.
  • The name of the peer, such as your computer’s hostname.
  • A filename to save the configuration to.
You can figure out your list of organizations with fly orgs list:
You can figure out which region is nearest you with fly platform regions or by checking the regions page in the documentation:
With all this in mind, let’s assemble the command. Each of these steps is going to build up the command, but don’t hit enter until it’s all done. Start with the base command fly wireguard create:
I want to create this in my personal organization, so I’ll enter in personal for the organization name.
I’m in Ottawa, so I’m using the Montreal region yul.
My computer’s hostname is Camellia, so I’ll use that as the peer name.
Finally I want to save this as camellia.conf so that WireGuard can load it.
Then run the command (you can hit enter now), and once it’s done open up the WireGuard app. Import the tunnel from the configuration file and then turn it on. macOS may prompt if you want the WireGuard app to manage VPN connections. If it does, hit accept, otherwise you won’t be able to get into your network. The above video shows how you import a WireGuard config on macOS. Here’s a summary of the steps:
  • Click on the “Import tunnel(s) from file” button.
  • Select the configuration file you saved earlier.
  • Click on the “Activate” button.
  • macOS will ask you if you want to allow the WireGuard app to manage VPN connections. Click “Allow” if you trust it.
On a Linux system you can use wg-quick:
To test the connection, ping _api.internal (on macOS you need to run ping6 _api.internal because it’s an IPv6 address):
To test the connection with an instance of Ollama, you can fire it up with the following commands in an empty folder (don’t forget to delete it after!):
Then you can set the OLLAMA_HOSTNAME environment variable to the hostname of the instance you just created (it will be something like xe-ollama.flycast), and then run the following commands:
And then the model will reply with something like this:
The sky appears blue because of a phenomenon called Rayleigh scattering, where shorter wavelengths of light (like blue and violet) are scattered more than longer wavelengths (like red and orange) by tiny molecules of gases like nitrogen and oxygen in the Earth’s atmosphere.
And there you go! You’re in your private network and can access all your apps and Machines like they were right next to you.