netbirdio / netbird

Connect your devices into a secure WireGuard®-based overlay network with SSO, MFA and granular access controls.
https://netbird.io
BSD 3-Clause "New" or "Revised" License
11.18k stars 515 forks source link

Unable to connect via P2P even public IPv4 is available #2563

Open Integral-Tech opened 2 months ago

Integral-Tech commented 2 months ago

Describe the problem

I am pretty sure that one of my peers has public IPv4 address, however I fail to connect two peers via P2P.

To Reproduce

Steps to reproduce the behavior:

  1. Start Netbird service on two peers (one of them has public IPv4 address)
  2. Run netbird status -d

Expected behavior

  Status: Connected
  -- detail --
  Connection type: P2P
  Direct: true

Are you using NetBird Cloud?

Yes

NetBird version

0.28.9

NetBird status -dA output:

Peers detail:
 *.netbird.cloud:
  NetBird IP: *
  Public key: *
  Status: Connected
  -- detail --
  Connection type: Relayed
  Direct: true
  ICE candidate (Local/Remote): host/relay
  ICE candidate endpoints (Local/Remote): *
  Last connection update: 14 seconds ago
  Last WireGuard handshake: -
  Transfer status (received/sent) 444 B/424 B
  Quantum resistance: false
  Routes: 192.168.0.0/16
  Latency: 426.126669ms

OS: linux/amd64
Daemon version: 0.28.9
CLI version: 0.28.9
Management: Connected to https://api.netbird.io:443
Signal: Connected to https://signal.netbird.io:443
Relays: 
  [stun:stun.netbird.io:5555] is Available
  [turns:turn.netbird.io:443?transport=tcp] is Available
Nameservers: 
FQDN: *.netbird.cloud
NetBird IP: *
Interface type: Kernel
Quantum resistance: false
Routes: -
Peers count: 1/1 Connected
pascal-fischer commented 2 months ago

Hi @Integral-Tech, to have a full P2P connection both peers need to be reachable directly. In your status output you see ICE candidate (Local/Remote): host/relay so one way is connected on host level (due to the public IP) which would allow P2P but the opposite direction is relayed. Thats why overall the connection type is listed as Relayed

Marcus1Pierce commented 2 months ago

@Integral-Tech From what I know, if you want both peers to communicate via P2P, both peers must be on the same IP segment, or both peers must have a public IP and be accessible from outside.

CMIIW

Spiritreader commented 1 month ago

Hi @Integral-Tech, to have a full P2P connection both peers need to be reachable directly. In your status output you see ICE candidate (Local/Remote): host/relay so one way is connected on host level (due to the public IP) which would allow P2P but the opposite direction is relayed. Thats why overall the connection type is listed as Relayed

If one direction can connect via host, isn't it possible to just establish a direct wireguard connection? This is essentially the base scenario of manually setting up a wireguard tunnel for machines behind CGNAT:

Now, as long as there is a keepalive interval to prevent the CGNAT's stateful FW from closing the connection, you're good to go. I had to do this fairly often for peers before I used netbird, as some of my devices are behind CGNAT.

Having host/relay, kinda sounds like calling a friend on his phone via the number they gave you, they pick up and say "Hello" and in order to respond you send your grandma to his house via bike.

if we had a TCP connection on port 80 for CGNATed devices, some form of return traffic must be allowed directly because we need some form of traffic to flow between devices if they have a connection to each other.

Or am I understanding sth fundamentally wrong here, for example that the ICE candidate doesn't show an established connection, but rather only the peer addresses?

vampywiz17 commented 3 weeks ago

Hi @Integral-Tech, to have a full P2P connection both peers need to be reachable directly. In your status output you see ICE candidate (Local/Remote): host/relay so one way is connected on host level (due to the public IP) which would allow P2P but the opposite direction is relayed. Thats why overall the connection type is listed as Relayed

If one direction can connect via host, isn't it possible to just establish a direct wireguard connection? This is essentially the base scenario of manually setting up a wireguard tunnel for machines behind CGNAT:

  • Open whatever port (12345) on PeerA.
  • Configure wireguard on CTNATed PeerB to add PeerA with the address of PeerA:12345.

Now, as long as there is a keepalive interval to prevent the CGNAT's stateful FW from closing the connection, you're good to go. I had to do this fairly often for peers before I used netbird, as some of my devices are behind CGNAT.

Having host/relay, kinda sounds like calling a friend on his phone via the number they gave you, they pick up and say "Hello" and in order to respond you send your grandma to his house via bike.

if we had a TCP connection on port 80 for CGNATed devices, some form of return traffic must be allowed directly because we need some form of traffic to flow between devices if they have a connection to each other.

Or am I understanding sth fundamentally wrong here, for example that the ICE candidate doesn't show an established connection, but rather only the peer addresses?

This is how it work Tailscale. not need to "active" both client, it enought that only one is active.