[PR #1943] [MERGED] Add DNS routes #14481

Closed
opened 2026-08-05 03:05:42 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/1943
Author: @lixmal
Created: 5/7/2024
Status: Merged
Merged: 6/4/2024
Merged by: @lixmal

Base: 0.28.0Head: feature/dns-routes


📝 Commits (10+)

📊 Changes

74 files changed (+2911 additions, -1327 deletions)

View changed files

📝 .github/workflows/golang-test-linux.yml (+7 -1)
📝 client/cmd/root.go (+4 -1)
📝 client/cmd/route.go (+49 -6)
📝 client/cmd/status.go (+15 -10)
📝 client/cmd/up.go (+11 -0)
client/errors/errors.go (+30 -0)
📝 client/internal/config.go (+18 -0)
📝 client/internal/connect.go (+1 -0)
📝 client/internal/dns/server_test.go (+4 -0)
📝 client/internal/dns/wgiface.go (+6 -1)
📝 client/internal/engine.go (+14 -2)
📝 client/internal/engine_test.go (+1 -1)
📝 client/internal/networkmonitor/monitor_bsd.go (+6 -8)
📝 client/internal/networkmonitor/monitor_generic.go (+7 -9)
📝 client/internal/networkmonitor/monitor_linux.go (+6 -6)
📝 client/internal/networkmonitor/monitor_windows.go (+23 -25)
📝 client/internal/peer/status.go (+48 -25)
📝 client/internal/routemanager/client.go (+96 -78)
📝 client/internal/routemanager/client_test.go (+4 -3)
client/internal/routemanager/dynamic/route.go (+362 -0)

...and 54 more files

📄 Description

Describe your changes

This PR adds DNS routes.

Given domains are resolved periodically and resolved IPs are replaced with the new ones. Unless the flag keep_route is set to true, then only new ones are added.
This option is helpful if there are long-running connections that might still point to old IP addresses from changed DNS records.

This feature is not yet ready to catch changes from resolvers that use round-robin DNS.

Example route creation


api_url="http://localhost:8080/api"
api_token=xxx
peer_group_id=xxx
group_id=xxx

curl -X POST "$api_url/routes" \
    -H 'Accept: application/json' \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $api_token" \
    --data-raw '{
      "description": "",
      "network_id": "dns-route",
      "enabled": true,
      "peer_groups": [
        "'$peer_group_id'"
      ],
      "domains": [
        "netbird.io",
        "www.netbird.io",
        "google.com",
        "ipinfo.io"
      ],
      "keep_route": true,
      "metric": 9999,
      "masquerade": true,
      "groups": [
        "'$group_id'"
      ]
    }'
}'

Viewing resolved IPs
Currently resolved IPs can be viewed by running

netbird routes ls

Example output:

Available Routes:

  - ID: dns-route
    Domains: netbird.io, www.netbird.io, google.com
    Status: Selected
    Resolved IPs:
      [netbird.io]: 2a05:d014:1f8d:7302:ebca:ec15:b24d:d07e, 18.158.22.172
      [www.netbird.io]: 2a05:d014:1f8d:7302:ebca:ec15:b24d:d07e, 18.158.22.172
      [google.com]: 172.217.161.46, 2404:6800:4004:825::200e, 172.217.161.78, 142.251.42.142, 2404:6800:4004:80b::200e, 2404:6800:4004:80a::200e, 2404:6800:4008:c06::8b, 2404:6800:4008:c06::8a, 2404:6800:4008:c06::65, 2404:6800:4008:c06::66, 142.251.222.14, 2404:6800:4004:80f::200e

Status
Routes can be tracked via netbird status -d as usual:

On the client:

Peers detail:
 router1.netbird.cloud:
  NetBird IP: 100.64.117.193
  Public key: AcqMAbqyU0/rWxLpOXvMyg3z2bVA8GnMeqONEMN6ejo=
  Status: Connected
  -- detail --
  Connection type: P2P
  Direct: true
  ICE candidate (Local/Remote): host/host
  ICE candidate endpoints (Local/Remote): 192.168.141.1:51820/172.16.127.130:51820
  Last connection update: 21 minutes, 31 seconds ago
  Last WireGuard handshake: 1 minute ago
  Transfer status (received/sent) 148 B/31.5 KiB
  Quantum resistance: false
  Routes: 1.1.1.1/32, netbird.io, www.netbird.io, google.com
  Latency: 1.891443ms

On the routing peer:

OS: linux/amd64
Daemon version: development
CLI version: development
Management: Connected to http://api.netbird.io:443
Signal: Connected to https://signal.netbird.io:443
Relays:
  [stun:turn.stage.netbird.io:3478] is Available
  [turns:turn.stage.netbird.io:3478?transport=tcp] is Available
Nameservers:
FQDN: router1.netbird.cloud
NetBird IP: 100.64.117.193/16
Interface type: Kernel
Quantum resistance: false
Routes: 1.1.1.1/32, netbird.io, www.netbird.io, google.com
Peers count: 1/1 Connected

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • Extended the README / documentation, if necessary

🔄 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/1943 **Author:** [@lixmal](https://github.com/lixmal) **Created:** 5/7/2024 **Status:** ✅ Merged **Merged:** 6/4/2024 **Merged by:** [@lixmal](https://github.com/lixmal) **Base:** `0.28.0` ← **Head:** `feature/dns-routes` --- ### 📝 Commits (10+) - [`4b8c36a`](https://github.com/netbirdio/netbird/commit/4b8c36a62b5148b2f380e1e2995965700a9bbd8e) Fix route selection IDs - [`facbfb1`](https://github.com/netbirdio/netbird/commit/facbfb123b72277d295b446501db9d51621cf503) Don't panic on nil routes on comparison - [`1279637`](https://github.com/netbirdio/netbird/commit/12796377f1ad92f48849f1dfb0dd1f8ac23f913e) Check for nil - [`65105e1`](https://github.com/netbirdio/netbird/commit/65105e14b714fbcdfc74f873f38b115a63f353cc) Improve check - [`fe18f97`](https://github.com/netbirdio/netbird/commit/fe18f9752df5ccd23ddac8fc08fa692c40061bde) Use dedicated IDs for Route ID, Route NetID and HAUniqueID - [`162440c`](https://github.com/netbirdio/netbird/commit/162440c82f7d0e89b5682c1e8381a814d64325ae) Fix tests - [`b2ab301`](https://github.com/netbirdio/netbird/commit/b2ab3018d69483f8c53b7490023ae2feaa6f05de) Fix function name - [`a847d91`](https://github.com/netbirdio/netbird/commit/a847d91c774a0ecc18f4ffea8020d03514aa8bd4) Fix test - [`bd05494`](https://github.com/netbirdio/netbird/commit/bd054948f0eee14c5e27d9658a1c354de6a38acf) Merge branch 'main' into refactor/route-ids - [`eb99e1d`](https://github.com/netbirdio/netbird/commit/eb99e1d408967d31ab04dd8f3e39494ce5ba3f03) Use NetID in route selector ### 📊 Changes **74 files changed** (+2911 additions, -1327 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/golang-test-linux.yml` (+7 -1) 📝 `client/cmd/root.go` (+4 -1) 📝 `client/cmd/route.go` (+49 -6) 📝 `client/cmd/status.go` (+15 -10) 📝 `client/cmd/up.go` (+11 -0) ➕ `client/errors/errors.go` (+30 -0) 📝 `client/internal/config.go` (+18 -0) 📝 `client/internal/connect.go` (+1 -0) 📝 `client/internal/dns/server_test.go` (+4 -0) 📝 `client/internal/dns/wgiface.go` (+6 -1) 📝 `client/internal/engine.go` (+14 -2) 📝 `client/internal/engine_test.go` (+1 -1) 📝 `client/internal/networkmonitor/monitor_bsd.go` (+6 -8) 📝 `client/internal/networkmonitor/monitor_generic.go` (+7 -9) 📝 `client/internal/networkmonitor/monitor_linux.go` (+6 -6) 📝 `client/internal/networkmonitor/monitor_windows.go` (+23 -25) 📝 `client/internal/peer/status.go` (+48 -25) 📝 `client/internal/routemanager/client.go` (+96 -78) 📝 `client/internal/routemanager/client_test.go` (+4 -3) ➕ `client/internal/routemanager/dynamic/route.go` (+362 -0) _...and 54 more files_ </details> ### 📄 Description ## Describe your changes This PR adds DNS routes. Given domains are resolved periodically and resolved IPs are replaced with the new ones. Unless the flag `keep_route` is set to `true`, then only new ones are added. This option is helpful if there are long-running connections that might still point to old IP addresses from changed DNS records. This feature is not yet ready to catch changes from resolvers that use round-robin DNS. **Example route creation** ```bash api_url="http://localhost:8080/api" api_token=xxx peer_group_id=xxx group_id=xxx curl -X POST "$api_url/routes" \ -H 'Accept: application/json' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $api_token" \ --data-raw '{ "description": "", "network_id": "dns-route", "enabled": true, "peer_groups": [ "'$peer_group_id'" ], "domains": [ "netbird.io", "www.netbird.io", "google.com", "ipinfo.io" ], "keep_route": true, "metric": 9999, "masquerade": true, "groups": [ "'$group_id'" ] }' }' ``` **Viewing resolved IPs** Currently resolved IPs can be viewed by running `netbird routes ls` Example output: ``` Available Routes: - ID: dns-route Domains: netbird.io, www.netbird.io, google.com Status: Selected Resolved IPs: [netbird.io]: 2a05:d014:1f8d:7302:ebca:ec15:b24d:d07e, 18.158.22.172 [www.netbird.io]: 2a05:d014:1f8d:7302:ebca:ec15:b24d:d07e, 18.158.22.172 [google.com]: 172.217.161.46, 2404:6800:4004:825::200e, 172.217.161.78, 142.251.42.142, 2404:6800:4004:80b::200e, 2404:6800:4004:80a::200e, 2404:6800:4008:c06::8b, 2404:6800:4008:c06::8a, 2404:6800:4008:c06::65, 2404:6800:4008:c06::66, 142.251.222.14, 2404:6800:4004:80f::200e ``` **Status** Routes can be tracked via `netbird status -d` as usual: On the client: ``` Peers detail: router1.netbird.cloud: NetBird IP: 100.64.117.193 Public key: AcqMAbqyU0/rWxLpOXvMyg3z2bVA8GnMeqONEMN6ejo= Status: Connected -- detail -- Connection type: P2P Direct: true ICE candidate (Local/Remote): host/host ICE candidate endpoints (Local/Remote): 192.168.141.1:51820/172.16.127.130:51820 Last connection update: 21 minutes, 31 seconds ago Last WireGuard handshake: 1 minute ago Transfer status (received/sent) 148 B/31.5 KiB Quantum resistance: false Routes: 1.1.1.1/32, netbird.io, www.netbird.io, google.com Latency: 1.891443ms ``` On the routing peer: ``` OS: linux/amd64 Daemon version: development CLI version: development Management: Connected to http://api.netbird.io:443 Signal: Connected to https://signal.netbird.io:443 Relays: [stun:turn.stage.netbird.io:3478] is Available [turns:turn.stage.netbird.io:3478?transport=tcp] is Available Nameservers: FQDN: router1.netbird.cloud NetBird IP: 100.64.117.193/16 Interface type: Kernel Quantum resistance: false Routes: 1.1.1.1/32, netbird.io, www.netbird.io, google.com Peers count: 1/1 Connected ``` ## Issue ticket number and link ### Checklist - [ ] Is it a bug fix - [ ] Is a typo/documentation fix - [x] Is a feature enhancement - [x] It is a refactor - [x] Created tests that fail without the change (if possible) - [ ] Extended the README / documentation, if necessary --- <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 03:05:42 -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#14481