Client Agent
The NetBird client (also called agent) runs on each machine and is responsible for establishing and maintaining peer connections.Core Responsibilities
WireGuard Interface Management
WireGuard Interface Management
The client manages a local WireGuard network interface (Capabilities:
wt0 by default).Implementation (client/internal/engine.go):- Interface creation and configuration
- Kernel WireGuard (preferred) or userspace fallback
- MTU configuration
- Platform-specific optimizations (eBPF on Linux)
Peer Connection Management
Peer Connection Management
Manages connections to all other peers in the network.Connection Manager (Features:
client/internal/conn_mgr.go):- Parallel connection attempts (ICE + Relay)
- Connection health monitoring
- Automatic reconnection
- Connection type switching (relay ↔ direct)
- Lazy connection mode for resource efficiency
ICE Agent
ICE Agent
Implements WebRTC ICE protocol for NAT traversal.Key Functions (
client/internal/peer/ice/):- Candidate gathering (host, srflx, relay)
- STUN binding requests
- Connectivity checks
- Network interface monitoring
- Candidate prioritization
Firewall Management
Firewall Management
Applies network access policies locally.Firewall Manager (Backend Implementations:
client/firewall/manager):- Linux: nftables, iptables, or eBPF
- macOS: pf (packet filter)
- Windows: Windows Filtering Platform (WFP)
- Android/iOS: Platform-specific APIs
DNS Management
DNS Management
Manages local DNS resolution and private DNS zones.DNS Server (
client/internal/dns/):- Resolves NetBird private zones (*.netbird.cloud, custom domains)
- Forwards queries to appropriate nameservers
- Integrates with system DNS configuration
- Handles split-horizon DNS
Route Management
Route Management
Applies network routes for accessing remote networks.Route Manager (Route Types:
client/internal/routemanager/):- Client routes: Routes to access networks through routing peers
- Server routes: Routes this peer advertises to others
- HA routes: High-availability route groups
Client Architecture
Management Service
The Management Service is the centralized control plane that orchestrates the entire NetBird network.Core Responsibilities
1. Authentication and Authorization
- SSO Integration: OAuth2/OIDC with providers (Google, Microsoft, Okta, etc.)
- Setup Keys: Pre-generated keys for bulk provisioning
- JWT Validation: Token-based authentication for API access
- Service Accounts: For automated peer registration
2. Network State Management
Account Structure (management/server/account.go):
- Peer registry with metadata
- Access control policies (ACLs)
- Network routes
- DNS zones and nameservers
- User and group memberships
- Network configuration
3. Network Map Distribution
- Remote Peers: List of peers this peer can connect to
- Access Policies: Firewall rules and access controls
- Routes: Network routes to apply
- DNS Config: DNS zones, nameservers, custom records
- STUN/TURN Servers: Infrastructure server addresses
4. Real-Time Updates
Management Service maintains streaming gRPC connections with all online peers:- Peer added/removed
- Policy changes
- Route modifications
- DNS configuration updates
- Group membership changes
Management Service Architecture
Data Storage
Supported Backends:- SQLite: Default for single-instance deployments
- PostgreSQL: Recommended for production/HA deployments
- In-Memory: For testing
- Account configurations
- Peer registry and metadata
- User accounts and permissions
- Access policies and rules
- Network routes
- Activity logs and events
Signal Service
The Signal Service is a lightweight message relay for WebRTC signaling.Responsibilities
Message Forwarding
Relays encrypted offer/answer messages and ICE candidates between peers during connection establishment.
Peer Registration
Maintains registry of connected peers and their signaling addresses.
Connection Metrics
Tracks peer connections, message counts, and latency metrics.
Stateless Design
Does not store messages; forwards immediately or drops if recipient offline.
Implementation
Signal Exchange (signal/server/server.go):
Protocol
Message Types:OFFER: Initial connection offer with SDP and ICE candidatesANSWER: Connection answer in response to offerCANDIDATE: Additional ICE candidate discoveredGO_IDLE: Request peer to close connection (lazy mode)
Security
Encryption:- Messages encrypted with recipient’s public key
- Signal Service only sees encrypted payload
- Forward secrecy maintained
- No message persistence
Relay Servers (TURN)
Relay servers provide fallback connectivity when direct peer-to-peer connection fails.NetBird Relay Service
NetBird includes its own relay implementation (relay/server/):
Relay Protocol
Connection Process:- Peer authenticates with relay using HMAC token from Management Service
- Relay allocates relay address for peer
- Peer communicates relay address to remote peer via Signal
- Remote peer connects to relay address
- Relay forwards encrypted WireGuard packets
Performance Considerations
Optimizations:- QUIC transport for reduced latency
- Zero-copy packet forwarding where possible
- Connection pooling
- Regional distribution for proximity
- Stateless design allows horizontal scaling
- Load balancing across multiple relay instances
- Geographic distribution for global deployments
Coturn Alternative
NetBird also supports standard TURN servers like Coturn: Configuration:Supporting Components
STUN Servers
Purpose: Help peers discover their public IP addresses and ports as seen through NAT. Protocol: RFC 5389 STUN (Session Traversal Utilities for NAT) Usage in NetBird:stun:stun.netbird.io:3478(NetBird default)stun:stun.l.google.com:19302(Google)- Self-hosted Coturn instances
Admin Dashboard
Web-based UI for network management (netbirdio/dashboard): Features:- Peer management and monitoring
- Access policy configuration
- Route management
- DNS zone configuration
- User and group administration
- Activity logs and audit trails
- Network topology visualization
- Consumes Management Service HTTP API
- Real-time updates via WebSocket
- OAuth2 authentication
Component Communication
Protocol Summary
- Client ↔ Management
- Client ↔ Signal
- Client ↔ Relay
- Peer ↔ Peer
Protocol: gRPC over HTTP/2 with TLSPort: 443 (HTTPS) or customMessages:
Login: Authenticate and get initial configSync: Long-lived stream for network map updatesGetDeviceAuthorizationFlow: SSO device flow
- Bidirectional streaming
- Automatic reconnection
- Compression
Deployment Patterns
Self-Hosted
Minimal Deployment:- Management Service
- Signal Service
- STUN/TURN server (Coturn or NetBird Relay)
- Database (PostgreSQL recommended)
- Identity Provider (or use hosted)
NetBird Cloud
Managed Components:- Management Service (multi-region)
- Signal Service (globally distributed)
- Relay servers (multiple regions)
- Admin Dashboard
- Identity Provider integration
- NetBird client runs on your infrastructure
- Data flows peer-to-peer (not through cloud)
- Zero-knowledge architecture
Next Steps
Architecture Overview
Understand the high-level design and principles
How It Works
Learn about the connection flow and NAT traversal