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
10.89k stars 493 forks source link

Multiple peers behind NAT getting relayed #2703

Open deatheibon opened 1 week ago

deatheibon commented 1 week ago

Describe the problem

I've setup a fresh netbird instance and added some peers which should create a p2p connection between each other. For testing i've setup one peer with a direct attached public ip and 3 peers behind the same NAT(OPNsense). With default Outbound NAT all connections to the public server getting realyed. With setting outbound NAT to static port for UDP atleast one connection to public server is getting p2p state. I figured out that the reason for this behavior is port 51820 which is the same on all peers behind my NAT, if i change ports to 51820,51821,51822 all three peers getting p2p connection cause of no duplicate source port. Shouldnt it work like this with default outbound behavior from OPNsense which is rewriting the source port automatically? I want to connect many peers over diffrent locations with some behind NAT and need the p2p connection for performance rasons. But i cant change all wgport settings to achieve this. Local connection between clients behind nat are p2p and as expected its only if NAT is involved. So maybe an idea would be NAT hole punching or to be compatible with source port rewrite or maybe a way that netbird itself is changing the wgport automatically.

To Reproduce

Steps to reproduce the behavior:

  1. add peer with direct public ip
  2. add atleas 2 peers behind nat
  3. see netbird status -d and see relayed connection to public server

Expected behavior p2p connection to public server

Are you using NetBird Cloud?

No, self-hosted

NetBird version

0.30.0

jesvinjoachim commented 2 days ago

it same for me , as long there is ony two device in a route i get p2p, if add multiple device to acce the newtork everyting atleast one is relayed , also netbird status -detail shows its a p2p host/s/p but the latecy might be still high , and on the other node it shows realyed .

i can confirm the issue .

Are you using NetBird Cloud?

No, self-hosted

NetBird version

0.30.1