[PR #487] [MERGED] External NAT IP mapping support #12673

Closed
opened 2026-08-05 02:06:25 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/487
Author: @tkunicki
Created: 9/30/2022
Status: Merged
Merged: 11/23/2022
Merged by: @mlsmaycon

Base: mainHead: nat_external_ip


📝 Commits (5)

  • db8882b External NAT IP mapping support
  • bc69a0a Remove STUN derived external IP determination, per review comments
  • fd1bd7a No need to recheck external IP mapping every peer connection attempt after STUN option removed
  • 2313ae8 Ignore blacklisted interfaces, even if in user specified in mapping
  • eed95df don't return any NATExternalIP mappings if one or more fail to parse

📊 Changes

5 files changed (+120 additions, -17 deletions)

View changed files

📝 .gitignore (+2 -1)
📝 client/internal/config.go (+21 -3)
📝 client/internal/connect.go (+4 -2)
📝 client/internal/engine.go (+84 -6)
📝 client/internal/peer/conn.go (+9 -5)

📄 Description

Support external IP mappings for host interface IPs

The external IP must not be behind a CGNAT and port-forwarding for incoming UDP packets from WgPort on from the external IP to WgPort on the host interface IP must be present. This can take form of:

  • single port-forwarding rule from external IP to host interface IP
  • 1:1 DNAT mapping ExternalIP to host interface IP
  • NAT DMZ to host interface IP.

Configuration

A special value of stun will use the STUN server's XORMappedAddress to set the External IP value; this is for installations behind dynamic DHCP assuming the above restrictions are met.

A single mapping will take the form of external[/internal]

  • external (required):
    • external IP address or stun to use STUN to determine the external IP address
  • internal (optional)
    • the host interface IP address or an interface name
    • if the "internal" argument is present and "stun" is specified for external, the STUN request will be generated by a connection originating from the specified host interface IP

Examples:

 "stun"                 => all interface IPs will be mapped to external IP reported by stun
 "12.34.56.78"          => all interfaces IPs will be mapped to external IP of 12.34.56.78
 "stun/eth0"            => IPv4 assigned to interface eth0 will be mapped to external IP reported by stun
 "stun/10.1.2.3"        => interface IP 10.1.2.3 will be mapped to external IP reported by stun
 "12.34.56.78/eth0"     => IPv4 assigned to interface eth0 will be mapped to external IP of 12.34.56.78
 "12.34.56.78/10.1.2.3" => interface IP 10.1.2.3 will be mapped to external IP of 12.34.56.78

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/487 **Author:** [@tkunicki](https://github.com/tkunicki) **Created:** 9/30/2022 **Status:** ✅ Merged **Merged:** 11/23/2022 **Merged by:** [@mlsmaycon](https://github.com/mlsmaycon) **Base:** `main` ← **Head:** `nat_external_ip` --- ### 📝 Commits (5) - [`db8882b`](https://github.com/netbirdio/netbird/commit/db8882b01a2bdc3db7a09cc1fc77966d3c80b74d) External NAT IP mapping support - [`bc69a0a`](https://github.com/netbirdio/netbird/commit/bc69a0ad6c8abd1d21026161b50d12b2894af9c0) Remove STUN derived external IP determination, per review comments - [`fd1bd7a`](https://github.com/netbirdio/netbird/commit/fd1bd7a6cd838be61e196f26bb51c801ae6e6dd8) No need to recheck external IP mapping every peer connection attempt after STUN option removed - [`2313ae8`](https://github.com/netbirdio/netbird/commit/2313ae837839a3ab300111ba69315de738b65f33) Ignore blacklisted interfaces, even if in user specified in mapping - [`eed95df`](https://github.com/netbirdio/netbird/commit/eed95df43ffdddfe1c452cbe94e98dee9b1aa8f2) don't return any NATExternalIP mappings if one or more fail to parse ### 📊 Changes **5 files changed** (+120 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+2 -1) 📝 `client/internal/config.go` (+21 -3) 📝 `client/internal/connect.go` (+4 -2) 📝 `client/internal/engine.go` (+84 -6) 📝 `client/internal/peer/conn.go` (+9 -5) </details> ### 📄 Description ### Support external IP mappings for host interface IPs The external IP **_must not be behind_** a CGNAT **_and_** port-forwarding for incoming UDP packets from `WgPort` on from the external IP to `WgPort` on the host interface IP **_must be present_**. This can take form of: - single port-forwarding rule from external IP to host interface IP - 1:1 DNAT mapping ExternalIP to host interface IP - NAT DMZ to host interface IP. #### Configuration A special value of `stun` will use the STUN server's XORMappedAddress to set the External IP value; this is for installations behind dynamic DHCP assuming the above restrictions are met. A single mapping will take the form of `external[/internal]` - `external` (required): - external IP address or `stun` to use STUN to determine the external IP address - `internal` (optional) - the host interface IP address or an interface name - if the "internal" argument is present and "stun" is specified for `external`, the STUN request will be generated by a connection originating from the specified host interface IP #### Examples: ``` "stun" => all interface IPs will be mapped to external IP reported by stun "12.34.56.78" => all interfaces IPs will be mapped to external IP of 12.34.56.78 "stun/eth0" => IPv4 assigned to interface eth0 will be mapped to external IP reported by stun "stun/10.1.2.3" => interface IP 10.1.2.3 will be mapped to external IP reported by stun "12.34.56.78/eth0" => IPv4 assigned to interface eth0 will be mapped to external IP of 12.34.56.78 "12.34.56.78/10.1.2.3" => interface IP 10.1.2.3 will be mapped to external IP of 12.34.56.78 ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 02:06:25 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#12673