Cloudflare - Installation and How to use it?
Download the cloudflared binary: Use wget to download the latest version of the cloudflared binary from Cloudflare's repository.
wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64
chmod +x cloudflared-linux-amd64
sudo cp cloudflared-linux-amd64 /usr/local/bin/cloudflared
cloudflared --version
cloudflared tunnel --url http://localhost:8000
To start `cloudflared` using the terminal, you typically use it to create a secure tunnel to a web server or service running on your local machine. Here are the basic steps to get you started:
1. **Start a Basic Tunnel**: To start a basic tunnel, you can use the following command:
```bash
cloudflared tunnel --url http://localhost:8080
```
Replace `http://localhost:8080` with the URL of the service you want to expose. This command will create a tunnel to your local service running on port 8080.
2. **Login to Your Cloudflare Account**: If you haven't already, you need to log in to your Cloudflare account to set up tunnels with your domain. Use this command:
```bash
cloudflared login
```
This command will open a browser window where you can authenticate with your Cloudflare account.
3. **Create and Manage Named Tunnels**: You can create a named tunnel, which is useful for persistent tunnels and easier management. First, create a tunnel with a name:
```bash
cloudflared tunnel create my-tunnel
```
This command will create a tunnel configuration file for `my-tunnel`.
4. **Configure the Tunnel**: Next, you need to configure the tunnel. Edit the configuration file located at `~/.cloudflared/config.yml` or wherever it was created, and specify the service you want to expose. Here's an example configuration file:
```yaml
tunnel: my-tunnel
credentials-file: /home/youruser/.cloudflared/my-tunnel.json
ingress:
- hostname: myapp.example.com
service: http://localhost:8080
- service: http_status:404
```
Replace `myapp.example.com` with your domain and `http://localhost:8080` with the URL of your local service.
5. **Run the Tunnel**: Finally, start the tunnel using the following command:
```bash
cloudflared tunnel run my-tunnel
```
This will start the tunnel as configured.
6. **Check the Status**: You can check the status of the tunnel using:
```bash
cloudflared tunnel info my-tunnel
```
By following these steps, you can start and manage `cloudflared` tunnels using the terminal. This allows you to securely expose local services to the internet through Cloudflare's network.
Comments
Post a Comment