Let’s say I setup some subdomains and then point them to my home server via Cloudflare tunnel.
If I use one of those subdomains from my personal PC on the same network as my home server, to watch a movie for example, is all of that traffic going out to the internet and then back? Or does all the traffic stay internal once the connection has been made?
I would assume yes, it goes out to cloudflare and back in. You want to setup an internal DNS server on your network, and resolve your servers address to its local one. That way when your outside your network, you use the tunnel, and inside it goes direct.
yes, its also called hairpinning. to avoid this you can use a local dns resolver.
Cloudflare tunnel likely terminates TLS on the edge. So if you bypass it, you don’t have HTTPS. Not a problem locally, but then destroys the portability of the URL (because at home you need http and outside you need https). Might as well use different hosts then.
You can use caddy to get internal https via cloudflare API, and no traffic needs to go through a cloudflare tunnel for that.
Possible, true. But then the setup also becomes more complicated. In addition you end up with different certs for local and remote access, which could cause issues with clients if they try to enforce cert pinning for example.
The (wildcard) certs are the same, as it’s what caddy is pulling via API. You can either build the cloudflare module into caddy via docker build, or use a prebuilt version. It doesn’t create two separate certs for local and remote.
It works really well for me, and is actually the most straight forward way to get valid certs for internal services I’ve found. Since they’re wildcard, my internal domains don’t get exposed through certificate authorities.
what if I use a separate proxy service locally with a cert and the same domain?
If your client(s) accept irregularly changing remote certs (i.e. they don’t do cert pinning), it should work. If both cloudflare and you use the same CA, it would likely work even with cert pinning. Certainly possible, but increases the complexity of the overall setup.
Cert pinning is pretty uncommon in the self hosting community though, especially when both Cloudflare and Let’s Encrypt have a 90 day validity period and often renews after 60 days.
Should all be local after the connection is made, as long as nothing is wonky with your setup.
Locally you should resolve that DNS to your local server though, not via cloudflare.
I dont know that that is true. With cloudflare tunnels, their
server.x.y.z
will resolve to a cloudlfare IP address, which then tunnels it to their server? The traffic has to hit the cloudflare server, it can’t short circuit that connection? Am I missing something?Depends on the server obviously, but most will pass off their local once the initial handshake is made.
Once that is done, DNS isnt relevant anymore.
Edit: This is especially true for media (movies, TV) servers.
How does that work? Do they do something like what tailscale does to negotiate the connection? Can you point me to any doco for how that works?
Uhh, this might be true for WebRTC, except not much uses WebRTC other than for realtime streaming/calling. Jellyfin for example is just an mp4 stream over http; and http(s) will only use the IP in the DNS record. I’d like to see a packet capture if you are certain something is switching IP.