[PR #1904] Monitor network changes #18239

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

Original Pull Request: https://github.com/netbirdio/netbird/pull/1904

State: closed
Merged: Yes


Describe your changes

This introduces a network monitor feature that automatically restarts our engine in response to significant changes in network configurations.

The network monitor is disabled by default and can be enabled by passing the flag --network-monitor to the netbird up command
Upon engine startup, the network monitor collects the current default IPv4 and/or IPv6 route's next hop and associated interfaces. It then actively monitors network changes that require an engine restart. The triggers for these restarts vary by operating system:

Linux:

  • Monitored interface deletion: Engine restarts on the deletion of any interfaces associated with the default route.
  • Interface going down: Engine restarts when any monitored interfaces go down.
  • Default route deletion: Engine restarts if the default route with our next hop is deleted.
  • Addition of any default route: Engine restarts when a new default route is added, which might provide a better path due to different network interface priorities (e.g., switching from WiFi to Ethernet with both being available).

BSD (including macOS):

  • Default route changes: Engine restarts when the default route with our next hop disappears or any new default route is added.
  • Interface status: Engine restarts if any network interfaces associated with our monitored default route go down.

Windows:

  • Default route monitoring: Engine restarts if the default route with any of our next hops disappears.
  • Neighbor state monitoring: Restarts if the state of any neighbor with our next hops changes to anything other than permanent or reachable.

Testing

To ensure the Network Watcher functions correctly across different platforms, follow these OS-specific testing steps:

Linux:

  1. Change interface state: ip link set <interface> down, restore with ip link set <interface> up
  2. Change default route: ip route replace default via <new-ip> and restore with ip route replace default via <old-ip>
  3. Add another default route: ip route add default via <some-other-ip> metric 100, restore with ip route delete default via <some-other-ip> metric 100
  4. Delete default route: ip route delete default, restore with ip route add default via <old-params>

BSD (including macOS):

  1. Change interface state: ifconfig <interface> down, restore with ifonfig <interface> up
  2. Change default route: route change default <new-ip>, restore with route change default <old-ip>
  3. Add default route: route add default <new-ip>, restore with route delete default <new-ip>
  4. Delete default route: route delete default, restore with route add default <old-params>

Windows:

  1. Modify routing table: route change 0.0.0.0/0 <new-gateway> and restore with route change 0.0.0.0/0 <old-gateway>
  2. Add a new route: route add 0.0.0.0/0 <new-gateway> metric 1 and restore with route delete 0.0.0.0/0 <new-gateway>
  3. Clear entry in arp cache: arp -d <gateway IP>

In all cases, you can simulate a network switch (e.g., from local WiFi to Ethernet or a mobile hotspot) to trigger the network watcher and observe the engine's response.

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
**Original Pull Request:** https://github.com/netbirdio/netbird/pull/1904 **State:** closed **Merged:** Yes --- ## Describe your changes This introduces a network monitor feature that automatically restarts our engine in response to significant changes in network configurations. The network monitor is disabled by default and can be enabled by passing the flag `--network-monitor` to the `netbird up` command Upon engine startup, the network monitor collects the current default IPv4 and/or IPv6 route's next hop and associated interfaces. It then actively monitors network changes that require an engine restart. The triggers for these restarts vary by operating system: #### **Linux:** - **Monitored interface deletion:** Engine restarts on the deletion of any interfaces associated with the default route. - **Interface going down:** Engine restarts when any monitored interfaces go down. - **Default route deletion:** Engine restarts if the default route with our next hop is deleted. - **Addition of any default route:** Engine restarts when a new default route is added, which might provide a better path due to different network interface priorities (e.g., switching from WiFi to Ethernet with both being available). #### **BSD (including macOS):** - **Default route changes:** Engine restarts when the default route with our next hop disappears or any new default route is added. - **Interface status:** Engine restarts if any network interfaces associated with our monitored default route go down. #### **Windows:** - **Default route monitoring:** Engine restarts if the default route with any of our next hops disappears. - **Neighbor state monitoring:** Restarts if the state of any neighbor with our next hops changes to anything other than permanent or reachable. ### **Testing** To ensure the Network Watcher functions correctly across different platforms, follow these OS-specific testing steps: #### **Linux:** 1. **Change interface state:** `ip link set <interface> down`, restore with `ip link set <interface> up` 2. **Change default route:** `ip route replace default via <new-ip>` and restore with `ip route replace default via <old-ip>` 3. **Add another default route:** `ip route add default via <some-other-ip> metric 100`, restore with `ip route delete default via <some-other-ip> metric 100` 4. **Delete default route:** `ip route delete default`, restore with `ip route add default via <old-params>` #### **BSD (including macOS):** 1. **Change interface state:** `ifconfig <interface> down`, restore with `ifonfig <interface> up` 2. **Change default route:** `route change default <new-ip>`, restore with `route change default <old-ip>` 3. **Add default route:** `route add default <new-ip>`, restore with `route delete default <new-ip>` 4. **Delete default route:** `route delete default`, restore with `route add default <old-params>` #### **Windows:** 1. **Modify routing table:** `route change 0.0.0.0/0 <new-gateway>` and restore with `route change 0.0.0.0/0 <old-gateway>` 2. **Add a new route:** `route add 0.0.0.0/0 <new-gateway> metric 1` and restore with `route delete 0.0.0.0/0 <new-gateway>` 3. **Clear entry in arp cache:** `arp -d <gateway IP>` In all cases, you can simulate a network switch (e.g., from local WiFi to Ethernet or a mobile hotspot) to trigger the network watcher and observe the engine's response. ## Issue ticket number and link ### Checklist - [ ] Is it a bug fix - [ ] Is a typo/documentation fix - [x] Is a feature enhancement - [ ] It is a refactor - [ ] Created tests that fail without the change (if possible) - [ ] Extended the README / documentation, if necessary
saavagebueno added the pull-request label 2026-08-05 04:08:16 -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#18239