|
| 1 | +import {Note} from "@/components/mdx"; |
| 2 | + |
| 3 | +# Overview |
| 4 | +NetBird now includes an experimental lazy connection feature designed to improve performance and reduce resource usage by connecting to peers only when needed. Instead of maintaining always-on connections, NetBird activates them on-demand based on activity or signaling. |
| 5 | + |
| 6 | +This guide walks you through enabling and configuring this feature in your NetBird client. |
| 7 | + |
| 8 | +<Note> |
| 9 | + Minimum supported agent version: <strong>v0.45.0</strong> |
| 10 | +</Note> |
| 11 | + |
| 12 | +<Note> |
| 13 | + <strong>Self-hosted only:</strong> This feature also requires an upgraded NetBird management server. Make sure your server is updated to the <strong>v0.45.0</strong> version that supports lazy connections. |
| 14 | +</Note> |
| 15 | + |
| 16 | + |
| 17 | +## What Are Lazy Connections? |
| 18 | + |
| 19 | +When enabled, Lazy Connections allow the NetBird agent to: |
| 20 | + |
| 21 | +- Establish peer-to-peer connections **only when required** (e.g., when ping the remote peer). |
| 22 | +- Monitor peer activity and **automatically disconnect peers** that remain inactive **and unreachable** for a specified time. |
| 23 | +- Keep critical peers (such as routers or excluded peers) **always connected** to ensure uninterrupted communication. |
| 24 | + |
| 25 | +This feature is especially useful in **large-scale deployments** or **resource-constrained environments**, where maintaining full-mesh, permanent connections to all peers is unnecessary and inefficient. |
| 26 | + |
| 27 | +<Note> |
| 28 | + When using lazy connections, there may be a **slight delay** when initiating a connection to a peer that is not yet connected. This is expected behavior, as the connection is established on-demand. |
| 29 | +</Note> |
| 30 | + |
| 31 | + |
| 32 | +### How Automatic Disconnection Works |
| 33 | + |
| 34 | +Once a connection between two peers is established, it will remain open **as long as the remote peer is reachable**. The connection is **not** closed just because there is no data transfer. |
| 35 | + |
| 36 | +In other words, the inactivity timer only triggers a disconnect if the peer is both <em>inactive</em> and <em>unreachable</em> for the full duration of the threshold. |
| 37 | + |
| 38 | +<Note> |
| 39 | + The default inactivity threshold is <strong>60 minutes</strong>, and can be configured via the <code>NB_LAZY_CONN_INACTIVITY_THRESHOLD</code> environment variable. |
| 40 | +</Note> |
| 41 | + |
| 42 | +Additionally, the disconnection logic is being improved and will be enhanced in future releases to better support mobile devices—providing more intelligent reconnection behavior and improved handling of intermittent connectivity. |
| 43 | + |
| 44 | +## Enabling Lazy Connections |
| 45 | + |
| 46 | +Lazy connections are disabled by default. To enable them: |
| 47 | + |
| 48 | +You can enable Lazy Connections using the following environment variable: |
| 49 | + |
| 50 | +```bash |
| 51 | +export NB_ENABLE_EXPERIMENTAL_LAZY_CONN=true |
| 52 | +``` |
| 53 | + |
| 54 | +Or pass the flag directly via the CLI when running the agent: |
| 55 | + |
| 56 | +```bash |
| 57 | +netbird up --enable-lazy-connection |
| 58 | +``` |
| 59 | +<Note> |
| 60 | + This configuration is <strong>not persistent</strong>. You must reapply the flag or environment variable after each restart unless it is built into your service definition (e.g., systemd or Docker). |
| 61 | +</Note> |
| 62 | + |
| 63 | +### Platform-Specific Examples |
| 64 | +For platform-specific examples of how to configure this: |
| 65 | + |
| 66 | +- [See Windows example](/how-to/troubleshooting-client#windows) |
| 67 | +- [See Linux with systemd example](/how-to/troubleshooting-client#on-linux-with-systemd) |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +## Get started |
| 73 | +<p float="center" > |
| 74 | + <Button name="button" className="button-5" onClick={() => window.open("https://netbird.io/pricing")}>Use NetBird</Button> |
| 75 | +</p> |
| 76 | + |
| 77 | +- Make sure to [star us on GitHub](https://github.com/netbirdio/netbird) |
| 78 | +- Follow us [on Twitter](https://twitter.com/netbird) |
| 79 | +- Join our [Slack Channel](https://join.slack.com/t/netbirdio/shared_invite/zt-31rofwmxc-27akKd0Le0vyRpBcwXkP0g) |
| 80 | +- NetBird [latest release](https://github.com/netbirdio/netbird/releases) on GitHub |
0 commit comments