Create a locally-managed tunnel (CLI)
Follow this step-by-step guide to get your first tunnel up and running using the CLI.
Before you start, make sure you:
-
Download
cloudflared
on your machine. Visit the downloads page to find the right package for your OS. -
Rename the executable to
cloudflared.exe
-
In PowerShell, change directory to your Downloads folder and run
.\cloudflared.exe --version
. It should output the version ofcloudflared
. Note thatcloudflared.exe
could becloudflared-windows-amd64.exe
orcloudflared-windows-386.exe
if you have not renamed it.
To download and install cloudflared
:
Alternatively, you can download the latest Darwin amd64 release directly.
Debian and Ubuntu APT
Use the apt package manager to install cloudflared
on compatible machines.
- Add Cloudflare’s package signing key:
- Add Cloudflare’s apt repo to your apt repositories:
- Update repositories and install cloudflared:
RHEL RPM
Use the rpm package manager to install cloudflared
on compatible machines.
- Add Cloudflare’s repository:
- Update repositories and install cloudflared:
Arch Linux
cloudflared
is in the Arch Linux community
repository ↗.
Use pacman
to install cloudflared
on compatible machines.
Other
Alternatively you can download the cloudflared
binary or the linux packages to your machine and install manually. Visit the downloads page to find the right package for your OS.
To build the latest version of cloudflared
from source:
Depending on where you installed cloudflared
, you can move it to a known path as well.
Running this command will:
- Open a browser window and prompt you to log in to your Cloudflare account. After logging in to your account, select your hostname.
- Generate an account certificate, the cert.pem file, in the default
cloudflared
directory.
Running this command will:
- Create a tunnel by establishing a persistent relationship between the name you provide and a UUID for your tunnel. At this point, no connection is active within the tunnel yet.
- Generate a tunnel credentials file in the default
cloudflared
directory. - Create a subdomain of
.cfargotunnel.com
.
From the output of the command, take note of the tunnel’s UUID and the path to your tunnel’s credentials file.
Confirm that the tunnel has been successfully created by running:
-
In your
.cloudflared
directory, create aconfig.yml
file using any text editor. This file will configure the tunnel to route traffic from a given origin to the hostname of your choice. -
Add the following fields to the file:
If you are connecting an application:
If you are connecting a private network:
-
Confirm that the configuration file has been successfully created by running:
-
Now assign a
CNAME
record that points traffic to your tunnel subdomain:- If you are connecting an application, route the service to a public hostname:
- If you are connecting a private network, route an IP address or CIDR through the tunnel:
-
Confirm that the route has been successfully established:
Run the tunnel to proxy incoming traffic from the tunnel to any number of services running locally on your origin.
If your configuration file has a custom name or is not in the .cloudflared
directory, add the --config
flag and specify the path.
Cloudflare Tunnel can install itself as a system service on Linux and Windows and as a launch agent on macOS. For more information, refer to run as a service.
Your tunnel configuration is complete! If you want to get information on the tunnel you just created, you can run:
You can now route traffic to your tunnel using Cloudflare DNS or determine who can reach your tunnel with Cloudflare Access.
To secure your origin, you must validate the application token issued by Cloudflare Access. Token validation ensures that any requests which bypass Cloudflare Access (for example, due to a network misconfiguration) are rejected.
One option is to configure the Cloudflare Tunnel daemon, cloudflared
, to validate the token on your behalf. This is done by enabling Protect with Access in your Cloudflare Tunnel settings. Alternatively, if you do not wish to perform automatic validation with Cloudflare Tunnel, you can instead manually configure your origin to check all requests for a valid token.