Skip to content

Instantly share code, notes, and snippets.

@diyism
Last active December 4, 2024 09:02
Show Gist options
  • Save diyism/bc88e0bcc310a88f8debf95aab29fc94 to your computer and use it in GitHub Desktop.
Save diyism/bc88e0bcc310a88f8debf95aab29fc94 to your computer and use it in GitHub Desktop.
cloudflared tunnel
# don't use cloudflared-linux-arm64, will happen error to use /etc/resolv.conf which doesn't exist in android
// wget https://github.com/cloudflare/cloudflared/releases/download/2022.4.1/cloudflared-linux-arm64
$ wget https://github.com/diyism/TermuxXserver/releases/download/test/termux-cloudflared
$ install termux-cloudflared /data/data/com.termux/files/usr/bin/cloudflared
$ cloudflared tunnel login #it will auto open android browser from termux, generate ~/.cloudflared/cert.pem
$ cloudflared tunnel create www1 #generate ~/.cloudflared/<tunnel id>.json, include tunnel secret
$ cloudflared tunnel route dns www1 www1.mysite.com #add dns record in dns server
$ nano ~/.cloudflared/www1.yml
url: http://localhost:3000
tunnel: <tunnel id>
# need no this line of "credentials-file: /data/data/com.termux/files/home/.cloudflared/<tunnel id>.json" in www1.yml
# and after create tunnel id and tunnel secret, you can delete the login token file: ~/.cloudflared/cert.pem
$ echo 'nameserver 8.8.4.4' >/data/data/com.termux/files/usr/etc/resolv.conf
#it's weird, "cloudflared tunnel login" won't use resolv.conf, but "cloudflared tunnel run" will use resolv.conf
$ cloudflared tunnel --config ~/.cloudflared/www1.yml run
#if there's QoS on udp egress of your server, you should add "--protocol http2 --no-autoupdate" to avoid default quic protocol:
$ cloudflared tunnel --protocol http2 --no-autoupdate --config ~/.cloudflared/www1.yml run
# even need no www1.yml, but need ~/.cloudflared/<tunnel id>.json(AccountTag, TunnelSecret):
$ cloudflared tunnel --protocol http2 --no-autoupdate --url http://localhost:3000 run <tunnel id>
# if there's no SRV function in local DNS server(dig srv _v2-origintunneld._tcp.argotunnel.com, dig +short A region2.v2.argotunnel.com):
$ cloudflared tunnel --protocol http2 --no-autoupdate --edge-ip-version 4 --edge 198.41.200.233:7844 --url http://localhost:3000 run <tunnel id>
# to see all created tunnels and original ip:
# Zero Trust > Networks > Tunnels > click "Connector ID" links
# https://one.dash.cloudflare.com/.../networks/tunnels
$ wget https://github.com/xyproto/algernon/releases/download/1.12.14/algernon-1.12.14-linux_arm64.tar.xz
$ tar xf algernon-1.12.14-linux_arm64.tar.xz
$ ./algernon-1.12.14-linux_arm64/algernon
#algernon web server listens on localhost:3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment