Connection Profiles
NetworkManager stores connection profiles for every network you've connected to. These profiles contain the configuration needed to reconnect — SSID, credentials, IP settings, and more. nmrs provides methods to list, query, and remove these profiles.
Listing Saved Connections
use nmrs::NetworkManager; #[tokio::main] async fn main() -> nmrs::Result<()> { let nm = NetworkManager::new().await?; let connections = nm.list_saved_connections().await?; for name in &connections { println!(" {}", name); } Ok(()) }
list_saved_connections() returns the names of all saved connection profiles across all connection types — Wi-Fi, Ethernet, VPN, and Bluetooth.
Checking for a Saved Connection
#![allow(unused)] fn main() { let nm = NetworkManager::new().await?; if nm.has_saved_connection("HomeWiFi").await? { println!("Profile exists for HomeWiFi"); } else { println!("No saved profile — credentials will be needed"); } }
How Saved Profiles Affect Connection
When you call connect() with an SSID that has a saved profile, nmrs activates the saved profile directly. This means:
- Credentials are already stored — the
WifiSecurityvalue you pass is ignored - Connection is faster — no need to create a new profile
- Settings are preserved — autoconnect, priority, and IP configuration are retained
#![allow(unused)] fn main() { let nm = NetworkManager::new().await?; // First connection — credentials are required and saved nm.connect("HomeWiFi", WifiSecurity::WpaPsk { psk: "password".into(), }).await?; // Later reconnection — saved profile is used, security parameter is ignored nm.connect("HomeWiFi", WifiSecurity::Open).await?; }
Forgetting (Deleting) Connections
Wi-Fi Connections
#![allow(unused)] fn main() { let nm = NetworkManager::new().await?; nm.forget("HomeWiFi").await?; println!("Wi-Fi profile deleted"); }
If currently connected to that network, forget() disconnects first, then deletes all saved profiles matching the SSID.
VPN Connections
#![allow(unused)] fn main() { nm.forget_vpn("MyVPN").await?; }
Bluetooth Connections
#![allow(unused)] fn main() { nm.forget_bluetooth("My Phone").await?; }
Getting the D-Bus Path
For advanced use cases, you can retrieve the D-Bus object path of a saved connection:
#![allow(unused)] fn main() { let nm = NetworkManager::new().await?; if let Some(path) = nm.get_saved_connection_path("HomeWiFi").await? { println!("D-Bus path: {}", path.as_str()); } }
Profile Lifecycle
- Created — when you first connect to a network, NetworkManager creates a profile
- Persisted — profiles are saved to
/etc/NetworkManager/system-connections/ - Reused — subsequent connections to the same SSID use the saved profile
- Updated — if you connect with different credentials, the profile may be updated
- Deleted — calling
forget(),forget_vpn(), orforget_bluetooth()removes it
Next Steps
- WiFi Management – scan and connect to Wi-Fi networks
- VPN Management – manage VPN profiles
- Bluetooth – Bluetooth connection profiles