Small helper script to quickly switch the local port used by a Cloudflare Tunnel and start the tunnel with a single command.
The script:
- Updates the
service: http://localhost:<port>line in your Cloudflare config. - Prints the effective port and hostname.
- Kills any running
cloudflaredprocesses. - Starts the specified tunnel with the updated config.
Create an alias:
echo 'alias port-forward="$HOME/.cloudflared/run-tunnel.sh"' >> ~/.bashrc(or your path to the script)source ~/.bashrc
Then use:
port-forward 3000
- Linux (tested on Ubuntu).
bashcloudflared- A configured named tunnel (e.g.
localhost-tunnel). - Config file at:
~/.cloudflared/config.yml
With structure similar to:
tunnel: localhost-tunnel
credentials-file: /home/USER/.cloudflared/<uuid>.json
ingress:
- hostname: localhost.hasso.tech
service: http://localhost:3000
- service: http_status:404
Replace
hasso.tech/localhost.hasso.techwith your own zone and hostname.
- In your zone (e.g.
hasso.tech) go to: Rules → Cache Rules → Create rule. - Rule name:
no-cache localhost - When incoming requests match:
- Condition:
- Field:
Hostname - Operator:
equals - Value:
localhost.hasso.tech← your hostname
- Field:
- Condition:
- Then… (action):
- Action:
Cache - Setting:
Bypass cache(orCache level: Bypassin the old UI)
- Action:
- Save and ensure the rule is Enabled.