[GH-ISSUE #3949] Clarify how to get P2P connections #8156

Closed
opened 2026-08-05 01:16:16 -04:00 by saavagebueno · 20 comments
Owner

Originally created by @Silex on GitHub (Jun 10, 2025).
Original GitHub issue: https://github.com/netbirdio/netbird/issues/3949

Is your feature request related to a problem? Please describe.

I have many 5G routers that runs netbird but have relayed connections with windows peers (behind firewall / home wifi). But with peers located on hetzner linux servers, they get P2P connections. I'm trying to open/forward ports so these routers also have P2P connection with the windows peers.

I tried forwarding UDP 51820 to my laptop (home wifi) but that does not seem to help.

I understand the 5G routers suffer from CGNAT issues/etc, but given the Hetzner server is able to get P2P connection with them, I should be able to open ports until I also get P2P connection with them at home.

From what I understand from the ICE logs, it basically tries all interfaces UDP port 51820 until one of them succeed.

Describe the solution you'd like

Something like this in the docs:

NetBird's agent doesn't require any incoming port to be open, but if you want to help it negociate P2P please open the following ports:

- Inbound UDP 51820

Describe alternatives you've considered

Access the 5G routers with a routing peer through the linux server that has P2P connection, but that sounds like a silly solution.

Additional context

I checked these for clues but found nothing:

https://docs.netbird.io/how-to/troubleshooting-client
https://docs.netbird.io/about-netbird/faq

I'm opening a technical issue about why P2P does not work and I'll link it for additional context.

Originally created by @Silex on GitHub (Jun 10, 2025). Original GitHub issue: https://github.com/netbirdio/netbird/issues/3949 **Is your feature request related to a problem? Please describe.** I have many 5G routers that runs netbird but have relayed connections with windows peers (behind firewall / home wifi). But with peers located on hetzner linux servers, they get P2P connections. I'm trying to open/forward ports so these routers also have P2P connection with the windows peers. I tried forwarding UDP 51820 to my laptop (home wifi) but that does not seem to help. I understand the 5G routers suffer from CGNAT issues/etc, but given the Hetzner server is able to get P2P connection with them, I should be able to open ports until I also get P2P connection with them at home. From what I understand from the ICE logs, it basically tries all interfaces UDP port 51820 until one of them succeed. **Describe the solution you'd like** Something like this in the docs: ``` NetBird's agent doesn't require any incoming port to be open, but if you want to help it negociate P2P please open the following ports: - Inbound UDP 51820 ``` **Describe alternatives you've considered** Access the 5G routers with a routing peer through the linux server that has P2P connection, but that sounds like a silly solution. **Additional context** I checked these for clues but found nothing: https://docs.netbird.io/how-to/troubleshooting-client https://docs.netbird.io/about-netbird/faq I'm opening a technical issue about why P2P does not work and I'll link it for additional context.
saavagebueno added the feature-request label 2026-08-05 01:16:16 -04:00
Author
Owner

@Blackclaws commented on GitHub (Jun 10, 2025):

Have you tried changing the port from 51820? If multiple peers behind a firewall share a port it can lead to problems. We've had this issue behind a opnsense firewall.

Most of the things that hold for tailscale hold for netbird as well: https://tailscale.com/kb/1181/firewalls

<!-- gh-comment-id:2958376726 --> @Blackclaws commented on GitHub (Jun 10, 2025): Have you tried changing the port from 51820? If multiple peers behind a firewall share a port it can lead to problems. We've had this issue behind a opnsense firewall. Most of the things that hold for tailscale hold for netbird as well: https://tailscale.com/kb/1181/firewalls
Author
Owner

@Silex commented on GitHub (Jun 10, 2025):

@Blackclaws thanks, will give it a try.

<!-- gh-comment-id:2959508099 --> @Silex commented on GitHub (Jun 10, 2025): @Blackclaws thanks, will give it a try.
Author
Owner

@demanuPL commented on GitHub (Jun 11, 2025):

Have you tried changing the port from 51820? If multiple peers behind a firewall share a port it can lead to problems. We've had this issue behind a opnsense firewall.

Most of the things that hold for tailscale hold for netbird as well: https://tailscale.com/kb/1181/firewalls

It working with tailscale, but not with netbird. I can clearly see how OPNSense is blocking netbird traffic to netbird port. I've changed port to 51821, still nothing, also tried to randromize port with -1 in config, still blocked, but tailscale connects p2p without issues, same 2 hosts, I've tried both on and only one (netbird or tailscale) on.

<!-- gh-comment-id:2964533259 --> @demanuPL commented on GitHub (Jun 11, 2025): > Have you tried changing the port from 51820? If multiple peers behind a firewall share a port it can lead to problems. We've had this issue behind a opnsense firewall. > > Most of the things that hold for tailscale hold for netbird as well: https://tailscale.com/kb/1181/firewalls It working with tailscale, but not with netbird. I can clearly see how OPNSense is blocking netbird traffic to netbird port. I've changed port to 51821, still nothing, also tried to randromize port with -1 in config, still blocked, but tailscale connects p2p without issues, same 2 hosts, I've tried both on and only one (netbird or tailscale) on.
Author
Owner

@Silex commented on GitHub (Jun 12, 2025):

Same here, at home wifi it looks like netbird is unable to use UPnP while Zerotier can, and the rule for port 51820 does not help much (I'm the only netbird laptop at home):

Image

There are ICE logs in the linked issue.

<!-- gh-comment-id:2965266379 --> @Silex commented on GitHub (Jun 12, 2025): Same here, at home wifi it looks like netbird is unable to use UPnP while Zerotier can, and the rule for port 51820 does not help much (I'm the only netbird laptop at home): ![Image](https://github.com/user-attachments/assets/97c0a0b1-92d7-4949-ac37-2430a3e9d766) There are ICE logs in the linked issue.
Author
Owner

@lixmal commented on GitHub (Jun 12, 2025):

@Silex did you also open up the firewall for the port or is that included in the port forwarding configuration?

Can you run tcpdump or similar to verify traffic actually arrives on the machine with netbird?

Netbird currently doesn't implement upnp and friends, that's the discrepancy you see

<!-- gh-comment-id:2965472673 --> @lixmal commented on GitHub (Jun 12, 2025): @Silex did you also open up the firewall for the port or is that included in the port forwarding configuration? Can you run tcpdump or similar to verify traffic actually arrives on the machine with netbird? Netbird currently doesn't implement upnp and friends, that's the discrepancy you see
Author
Owner

@demanuPL commented on GitHub (Jun 12, 2025):

@Silex did you also open up the firewall for the port or is that included in the port forwarding configuration?

Can you run tcpdump or similar to verify traffic actually arrives on the machine with netbird?

Netbird currently doesn't implement upnp and friends, that's the discrepancy you see

Are there any plans to implement upnp? In cases like mine where I'm using OPNSense that is the best way to get p2p connection

<!-- gh-comment-id:2967103567 --> @demanuPL commented on GitHub (Jun 12, 2025): > [@Silex](https://github.com/Silex) did you also open up the firewall for the port or is that included in the port forwarding configuration? > > Can you run tcpdump or similar to verify traffic actually arrives on the machine with netbird? > > Netbird currently doesn't implement upnp and friends, that's the discrepancy you see Are there any plans to implement upnp? In cases like mine where I'm using OPNSense that is the best way to get p2p connection
Author
Owner

@Silex commented on GitHub (Jun 13, 2025):

@lixmal: ah, ok thanks I can stop trying to make UPnP work then 😁

I provided debug logs in #3964 and #3952, but I feel I can improve. I'll try to provide tcpdump traces as well.

I mainly have 2 issues:

  • Cannot establish P2P despite opening ports.
  • Relay not working or flakey for some peers (seems like it's tied to wiregard handshakes sometimes not happening anymore (e.g last handshake was 1h ago))

Are you ok if I ping you when I have all the debug/network traces? Also I'm in the process of adding more relay servers in the hope it helps isolate the issue.

<!-- gh-comment-id:2969356390 --> @Silex commented on GitHub (Jun 13, 2025): @lixmal: ah, ok thanks I can stop trying to make UPnP work then 😁 I provided debug logs in #3964 and #3952, but I feel I can improve. I'll try to provide tcpdump traces as well. I mainly have 2 issues: - Cannot establish P2P despite opening ports. - Relay not working or flakey for some peers (seems like it's tied to wiregard handshakes sometimes not happening anymore (e.g last handshake was 1h ago)) Are you ok if I ping you when I have all the debug/network traces? Also I'm in the process of adding more relay servers in the hope it helps isolate the issue.
Author
Owner

@Silex commented on GitHub (Jun 13, 2025):

Ah, good news! I get P2P connexions at home since I removed traefik in front of the relay server (I basically separated the relay server on a machine of its own and it serves HTTPS directly instead of being proxied through traefik).

That opens a lot of explorations, maybe traefik drops connexions or does not handle http3/websockets like netbird is expecting.

I don't get P2P everywhere but much more than before. Will try at work on monday.

<!-- gh-comment-id:2971232892 --> @Silex commented on GitHub (Jun 13, 2025): Ah, good news! I get P2P connexions at home since I removed traefik in front of the relay server (I basically separated the relay server on a machine of its own and it serves HTTPS directly instead of being proxied through traefik). That opens a lot of explorations, maybe traefik drops connexions or does not handle http3/websockets like netbird is expecting. I don't get P2P _everywhere_ but much more than before. Will try at work on monday.
Author
Owner

@Silex commented on GitHub (Jun 13, 2025):

Image

These are the monitoring of pings of 8 routers, around 16h15 I switched to relay serving directly, I think the image speaks for itself.

The P2P connexions went away as they came (I'm not relayed again) so there's still investigations to be done but at least it's promising.

<!-- gh-comment-id:2971320824 --> @Silex commented on GitHub (Jun 13, 2025): ![Image](https://github.com/user-attachments/assets/e4e47c1b-0667-4603-8c54-e4cbe5b554d7) These are the monitoring of pings of 8 routers, around 16h15 I switched to relay serving directly, I think the image speaks for itself. The P2P connexions went away as they came (I'm not relayed again) so there's still investigations to be done but at least it's promising.
Author
Owner

@Silex commented on GitHub (Jun 13, 2025):

lololol @lixmal you were right, I also needed to open the port in windows firewall 🤯 I always assumed netbird took care of the firewall rule but apparently not. Ok I'll make a documentation PR with my findings.

<!-- gh-comment-id:2971477725 --> @Silex commented on GitHub (Jun 13, 2025): lololol @lixmal you were right, I also needed to open the port in windows firewall 🤯 I always assumed netbird took care of the firewall rule but apparently not. Ok I'll make a documentation PR with my findings.
Author
Owner

@demanuPL commented on GitHub (Jun 13, 2025):

It doesn't help in my case (OpenSuse Tumbleweed with firewalld), I have port open od UDP traffic on both firewalld and opnsense but still netbird cannot figure out how to open p2p connection to some hosts.

<!-- gh-comment-id:2971887648 --> @demanuPL commented on GitHub (Jun 13, 2025): It doesn't help in my case (OpenSuse Tumbleweed with firewalld), I have port open od UDP traffic on both firewalld and opnsense but still netbird cannot figure out how to open p2p connection to some hosts.
Author
Owner

@Silex commented on GitHub (Jun 14, 2025):

@demanuPL selfhosted or netbird.io ?

<!-- gh-comment-id:2972748227 --> @Silex commented on GitHub (Jun 14, 2025): @demanuPL selfhosted or netbird.io ?
Author
Owner

@demanuPL commented on GitHub (Jun 16, 2025):

@demanuPL selfhosted or netbird.io ?

Self hosted, some of P2P connections works, but not when both routers between are pfSense or OPNSense. Other solutions clearly using NAT-PNP on these routers (both OPNSense and PFSense have upnp monitoring), but not netbird doesn't and falling back to Relayed Connection, even with ports open and NAT udp traffic redirection

<!-- gh-comment-id:2977330783 --> @demanuPL commented on GitHub (Jun 16, 2025): > [@demanuPL](https://github.com/demanuPL) selfhosted or netbird.io ? Self hosted, some of P2P connections works, but not when both routers between are pfSense or OPNSense. Other solutions clearly using NAT-PNP on these routers (both OPNSense and PFSense have upnp monitoring), but not netbird doesn't and falling back to Relayed Connection, even with ports open and NAT udp traffic redirection
Author
Owner

@Silex commented on GitHub (Jun 17, 2025):

@demanuPL: interesting, actually the part where I have trouble getting P2P connection is for peers behind pfSense 😂 I always assumed it's because I'm bad at creating the fw rule but maybe it's something deeper related to pfSense.

At home wifi I get P2P with all peers, by opening port UDP 51820.

Maybe there's something subtle to do in addition to NAT UDP 51820...

<!-- gh-comment-id:2979304575 --> @Silex commented on GitHub (Jun 17, 2025): @demanuPL: interesting, actually the part where I have trouble getting P2P connection is for peers behind pfSense 😂 I always assumed it's because I'm bad at creating the fw rule but maybe it's something deeper related to pfSense. At home wifi I get P2P with _all_ peers, by opening port UDP 51820. Maybe there's something subtle to do in addition to NAT UDP 51820...
Author
Owner

@Silex commented on GitHub (Jun 17, 2025):

@demanuPL managed to make it work!

Image

You need to make a NAT > Port forward and now I have P2P with peers behind pfsense. You also need to change the default port to 51821 in netbird settings, but 51820 should also work it's just we'll need one port per peer behind the pfsense.

Also the peer needs to have inbound UDP 51821 allowed of course.

<!-- gh-comment-id:2979646592 --> @Silex commented on GitHub (Jun 17, 2025): @demanuPL managed to make it work! ![Image](https://github.com/user-attachments/assets/db13e094-5391-4332-b656-87c2cf3dd3da) You need to make a NAT > Port forward and now I have P2P with peers behind pfsense. You also need to change the default port to 51821 in netbird settings, but 51820 should also work it's just we'll need one port per peer behind the pfsense. Also the peer needs to have inbound UDP 51821 allowed of course.
Author
Owner

@Silex commented on GitHub (Jun 23, 2025):

Should be fixed by https://github.com/netbirdio/docs/pull/374

<!-- gh-comment-id:2995567790 --> @Silex commented on GitHub (Jun 23, 2025): Should be fixed by https://github.com/netbirdio/docs/pull/374
Author
Owner

@the-project-group commented on GitHub (Jul 7, 2025):

I also struggle to get P2P working with my home-office setup and self hosted Netbird.

Setup

  • 5G Router (MikroTik) with german Telekom SIM (CGNAT)
  • clients (windows / mac) behind this router only have one P2P connection to a machine on the public internet
  • all other peers (behind corp. firewall) are relayed - I have P2P to these peers when using a different ISP (no CGNAT)
  • I tried DSTNAT 51820 or 51821 (netbird up --wireguard-port 51821)
  • Image
  • I don't see any packets on the DST NAT rule...
    Latest 0.50.1 Netbird installed. Any tips?
<!-- gh-comment-id:3044874442 --> @the-project-group commented on GitHub (Jul 7, 2025): I also struggle to get P2P working with my home-office setup and self hosted Netbird. **Setup** - 5G Router (MikroTik) with german Telekom SIM (CGNAT) - clients (windows / mac) behind this router only have one P2P connection to a machine on the public internet - all other peers (behind corp. firewall) are relayed - I have P2P to these peers when using a different ISP (no CGNAT) - I tried DSTNAT 51820 or 51821 (netbird up --wireguard-port 51821) - ![Image](https://github.com/user-attachments/assets/e3dcf231-0a8f-4495-b8f3-8d85876525f7) - I don't see any packets on the DST NAT rule... Latest 0.50.1 Netbird installed. Any tips?
Author
Owner

@demanuPL commented on GitHub (Dec 6, 2025):

@demanuPL managed to make it work!

Image

You need to make a NAT > Port forward and now I have P2P with peers behind pfsense. You also need to change the default port to 51821 in netbird settings, but 51820 should also work it's just we'll need one port per peer behind the pfsense.

Also the peer needs to have inbound UDP 51821 allowed of course.

I have 12 servers which I want to use Netbird on. You're giving me the solution for just one machine, and I need open port for each one which is security issue for me to keep open ports all the time on both OPNsense and local machine firewall. This is more like workaround than not a solution. UPnP is a solution. If I need to open ports, Netbird is pointless. Tailscale is successfully using UPnP at the moment and as long as Netbird constantly refuses to implement UPnP I'm forced to stick to Tailscale.

Your solution is unacceptable

<!-- gh-comment-id:3619930540 --> @demanuPL commented on GitHub (Dec 6, 2025): > [@demanuPL](https://github.com/demanuPL) managed to make it work! > > ![Image](https://github.com/user-attachments/assets/db13e094-5391-4332-b656-87c2cf3dd3da) > > You need to make a NAT > Port forward and now I have P2P with peers behind pfsense. You also need to change the default port to 51821 in netbird settings, but 51820 should also work it's just we'll need one port per peer behind the pfsense. > > Also the peer needs to have inbound UDP 51821 allowed of course. I have 12 servers which I want to use Netbird on. You're giving me the solution for just one machine, and I need open port for each one which is security issue for me to keep open ports all the time on both OPNsense and local machine firewall. This is more like workaround than not a solution. UPnP is a solution. If I need to open ports, Netbird is pointless. Tailscale is successfully using UPnP at the moment and as long as Netbird constantly refuses to implement UPnP I'm forced to stick to Tailscale. Your solution is unacceptable
Author
Owner

@Silex commented on GitHub (Dec 9, 2025):

UPnP is considered a security anti-pattern in the enterprise world. If you are happy with tailscale juste continue using it 🤷‍♂️

<!-- gh-comment-id:3631438626 --> @Silex commented on GitHub (Dec 9, 2025): UPnP is considered a security anti-pattern in the enterprise world. If you are happy with tailscale juste continue using it 🤷‍♂️
Author
Owner

@Blackclaws commented on GitHub (Dec 9, 2025):

@demanuPL managed to make it work!
Image
You need to make a NAT > Port forward and now I have P2P with peers behind pfsense. You also need to change the default port to 51821 in netbird settings, but 51820 should also work it's just we'll need one port per peer behind the pfsense.
Also the peer needs to have inbound UDP 51821 allowed of course.

I have 12 servers which I want to use Netbird on. You're giving me the solution for just one machine, and I need open port for each one which is security issue for me to keep open ports all the time on both OPNsense and local machine firewall. This is more like workaround than not a solution. UPnP is a solution. If I need to open ports, Netbird is pointless. Tailscale is successfully using UPnP at the moment and as long as Netbird constantly refuses to implement UPnP I'm forced to stick to Tailscale.

Your solution is unacceptable

If you are running servers and have UPnP enabled on your router then you're already running a security risky setup. UPnP is for home setups where gaming equipment needs to punch holes through your firewall. For enterprise setups you really want fixed port forwarding setups where you know what's going on instead of devices being able to manually create hole punches.

Netbird is not pointless as you're opening a wireguard port only and not exposing the other ports. I'm not sure how "keeping ports open all the time" is a security issue for you while UPnP is not 🤷

<!-- gh-comment-id:3631450496 --> @Blackclaws commented on GitHub (Dec 9, 2025): > > [@demanuPL](https://github.com/demanuPL) managed to make it work! > > ![Image](https://github.com/user-attachments/assets/db13e094-5391-4332-b656-87c2cf3dd3da) > > You need to make a NAT > Port forward and now I have P2P with peers behind pfsense. You also need to change the default port to 51821 in netbird settings, but 51820 should also work it's just we'll need one port per peer behind the pfsense. > > Also the peer needs to have inbound UDP 51821 allowed of course. > > I have 12 servers which I want to use Netbird on. You're giving me the solution for just one machine, and I need open port for each one which is security issue for me to keep open ports all the time on both OPNsense and local machine firewall. This is more like workaround than not a solution. UPnP is a solution. If I need to open ports, Netbird is pointless. Tailscale is successfully using UPnP at the moment and as long as Netbird constantly refuses to implement UPnP I'm forced to stick to Tailscale. > > Your solution is unacceptable If you are running servers and have UPnP enabled on your router then you're already running a security risky setup. UPnP is for home setups where gaming equipment needs to punch holes through your firewall. For enterprise setups you really want fixed port forwarding setups where you know what's going on instead of devices being able to manually create hole punches. Netbird is not pointless as you're opening a wireguard port only and not exposing the other ports. I'm not sure how "keeping ports open all the time" is a security issue for you while UPnP is not 🤷
Sign in to join this conversation.
No Label feature-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#8156