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?

all 17 comments

sorted by: hot top controversial new old
[–] 8 points 1 year ago (4 children)

yes, its also called hairpinning. to avoid this you can use a local dns resolver.

  • source
  • hideshow 4 child comments
  • [–] 5 points 1 year ago (3 children)

    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.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 6 points 1 year ago (2 children)

    You can use caddy to get internal https via cloudflare API, and no traffic needs to go through a cloudflare tunnel for that.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 1 year ago (1 child)

    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.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 4 points 1 year ago

    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.

  • source
  • parent
  • [–] 7 points 1 year ago

    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.

  • source
  • [–] 0 points 1 year ago* (10 children)

    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.

  • source
  • hideshow 10 child comments
  • [–] 7 points 1 year ago (9 children)

    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?

  • source
  • parent
  • hideshow 9 child comments
  • [–] 3 points 1 year ago* (8 children)

    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.

  • source
  • parent
  • hideshow 8 child comments
  • [–] 5 points 1 year ago* (last edited 1 year ago)

    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.

  • source
  • parent
  • [–] 2 points 1 year ago (6 children)

    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?

  • source
  • parent
  • hideshow 6 child comments
  • [–] 2 points 1 year ago (2 children)

    Remember that we're talking about a server on your local network, and a device on the local network to make the connection for the stream. We aren't talking about streaming over the internet.

    • Client looks up server via DNS
    • Client connects to public IP
    • Client handshakes to server
    • Server announces to client available connections (public, local)
    • Client continues connections with local address

    There is no need for tailscale or anything, this is a local connection. The only thing the public address is doing is the initial call to the server.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 3 points 1 year ago (1 child)

    I get how that could work, but what services actually do that? Homeassistant can, but that needs to be setup explicitly for it to work.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 1 year ago

    Plex is a good example that does just that (not on my rec list but a good example) along with many business grade IPTV and media streaming products (think digital signage).

    I'd really love to rework JF to do it, but structurally it wouldn't work, you'd need a management service in front of it.

  • source
  • parent
  • [–] 2 points 1 year ago (2 children)

    Plex does this on its own. It's one of the features they provide. The client/service knows when the server is local even though you go outside to make the initial connection. They go through a lot of trouble to do this. You connect externally it brokers the initial connection proxies date of back and forth to see if you can talk to each other directly, your client knows your server is now local and it switches over.

    I don't know if any other video hosting package that does this. Jellyfin certainly would not. I 'think' if you threw a tailscale in the middle, It would be able to do it without hair pinning as long as you were using a local exit node instead of tailnet. They'd still probably go through that local exit node.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 1 year ago (1 child)

    As you've described it, and from what I have read, its very similar to how tailscale negotiates its connections.

    Does seem to be unique to Plex though.

  • source
  • parent
  • hideshow 1 child comment