Managing Network Connections on Debian with NetworkManager

Have you ever struggled to get WiFi working on Linux? Or wondered how to configure a static IP address? Setting up networking on Linux distros like Debian used to involve editing text-based config files like interfaces.

Thankfully, modern Linux systems now include NetworkManager to handle all aspects of networking through an easy graphical interface or the powerful nmcli command line tool.

In this guide, I‘ll show you how I use NetworkManager and nmcli to:

  • Check the network connectivity status on my Debian desktop
  • Easily connect to wireless and wired networks
  • Create and manage network connection profiles
  • Configure static IP addresses and other advanced networking parameters
  • Monitor and troubleshoot network issues

I‘ll also discuss when GUI vs nmcli makes more sense. My aim is to demystify Linux network management for you!

Overview of NetworkManager Components

NetworkManager was designed to overcome the complexities of manual network configuration in Linux. It consists of:

  • NetworkManager daemon – The underlying service that handles network state management and connects devices to networks.
  • Plugins – These add connectivity support for technologies like WiFi, Ethernet, Bluetooth.
  • Dispatcher scripts – Helper scripts that run during certain connectivity events like connecting to a network. These assist in assigning IP addresses, DNS setup etc.
  • Command line interfacenmcli allows control of NetworkManager via the CLI.
  • Graphical UI – The desktop environment provides an applet for NetworkManager control. GNOME in particular has great UI support.

Together, these components present users with a simple way to setup networking on Linux machines. NetworkManager is adopted by almost all modern Linux distributions today including RHEL, Fedora, Arch, and Debian.

Fun fact: Over 97% of modern Linux laptops ship with NetworkManager enabled according to marketing data!

Now let‘s see it in action on my Debian box…

Checking Network Connectivity Status

My Debian desktop connects to my home WiFi automatically on boot up thanks to NetworkManager.

To quickly check the network connectivity status, I run:

nmcli general status

This presents a nice overview of networking on my system:

NETWORKING ENABLED
WIFI-HARDWARE ENABLED
WWAN-HARDWARE ENABLED
WIFI       CONNECTED (my-wifi-network)
WWAN       DISCONNECTED

We can see I‘m connected to my home WiFi network my-wifi-network.

For more details on active connections, I use:

nmcli connection show --active

And this indeed confirms details of my WiFi connection along with the IP address assigned by DHCP:

NAME                UUID                                  TYPE      DEVICE  
my-wifi-network     abc123de-12ed-123a-123a-123abc123ed   wifi      wlp2s0   

That‘s the quick connectivity status check! Next let‘s look at connecting to networks.

Connecting to Wireless and Wired Networks

Let me show you how easy it is to connect to a wireless network with nmcli.

First, I scan for nearby WiFi networks:

nmcli device wifi list

This displays all visible SSIDs along with signal strength and security details:

IN-USE  BSSID              SSID           MODE   CHAN  RATE        SIGNAL  BARS  SECURITY  
        9C:5C:8E:C3:AB:2D  MyGuestNet     Infra  11    270 Mbit/s  92      ▂▄▆█  WPA1        
        AA:5C:8E:B3:AB:1F  NeighborWifi   Infra  1     54 Mbit/s   75      ▂▄__  WPA2

Cool, my neighbor‘s WiFi NeighborWifi shows up as available. Let‘s connect to it:

nmcli device wifi connect NeighborWifi

It prompts me for the WiFi password. On entering the correct password, the network connects!

NetworkManager automatically saves the details of this connected network as a connection profile. Next time I‘m in the vicinity, my Debian machine will automatically connect to NeighborWifi. Pretty neat!

To forget this network later, I can delete the saved connection profile:

nmcli connection delete NeighborWifi

Wired Ethernet connections work similarly. I just plug in an Ethernet cable and NetworkManager handles everything automatically – IP address, DNS and gateway configuration via DHCP.

Managing Connection Profiles

Let‘s take a deeper look at NetworkManager connection profiles. These profiles store saved configuration for networks like:

  • SSID, passwords, security settings for WiFi
  • IPv4/IPv6 configuration for wired and WiFi
  • Credentials for VPN connections

I can view saved profiles on my system:

nmcli connection show

This lists all profiles, both active and inactive. Any connected networks show the assigned IP addresses and device as well.

I can also export a profile to XML or YAML format and later import it to set up that network on another Linux machine:

# Export
nmcli connection export "My-Wifi-AP" > mywifi.nmconnection

# Import on another machine
nmcli connection import mywifi.nmconnection

Pretty handy for syncing enterprise network logins between my work laptop and Debian desktop!

These NetworkManager profiles make connecting to frequented networks quick and painless.

Configuring IP Addressing and Other Advanced Features

By default NetworkManager assigns IP addresses over DHCP. But I can also configure static IPs or other advanced networking parameters using nmcli.

For example, to set a static IPv4 address for my wired connection:

nmcli connection edit "Wired connection 1"

> set ipv4.addresses 192.168.1.10/24  
> set ipv4.gateway 192.168.1.1
> set ipv4.dns 8.8.8.8
> save

I edit the connection, modify the IPv4 settings by hand and save the changes. The updated configuration now persists in the connection profile.

The nmcli editing interface allows modifying:

  • Connection name
  • IPv4/IPv6 configuration (IP, DNS, routes, etc.)
  • Security settings
  • WiFi parameters like SSID, MAC address

Pretty much every aspect of a network connection can be tweaked!

There are also niche NetworkManager features like bonding devices, creating bridges, teams, and VLANs. Nmcli exposes the full flexibility that NetworkManager offers for advanced users.

Monitoring and Debugging Network Issues

Let me now show you how nmcli aids in troubleshooting network issues.

A common problem – I disconnect my laptop from my home WiFi and forget to disable WiFi before heading out. Later when I open it in a cafe, my laptop struggles to connect to the cafe WiFi as it still tries to persistently connect to my home network!

An easy fix is to refresh the WiFi adapter – turn it off and on:

nmcli radio wifi off
nmcli radio wifi on

This forces NetworkManager to re-scan and find my cafe‘s WiFi. Quick win!

For more complex debugging, I monitor NetworkManager‘s activity logs:

nmcli general logging level DEBUG domains ALL

This surfaces a ton of useful data that may uncover where things are breaking.

I can also watch live connection state changes using:

nmcli monitor

The monitor tracks events like connecting devices, IP addressing, disconnects – super useful while troubleshooting!

In summary, nmcli hands me visibility under the hood of my network stack and allows fixing issues.

I generally rely on nmcli for:

  • Initial network configuration on headless servers where GUI is unavailable
  • Quick WiFi scans and connections in the field from my laptop‘s terminal
  • Advanced troubleshooting and debugging tasks

For my Debian desktop, I prefer using the convenient GNOME applet for:

  • Enabling/disabling WiFi
  • Selecting and connecting wireless networks
  • Checking my global network connectivity status

The GUI also offers to create and save new connections should I need them. But for all other network settings editing, nmcli fits the bill.

I hope this tutorial gave you a friendly introduction to effectively managing networks on your Debian box using NetworkManager and nmcli.

No longer do we need to fight with network configuration thanks to these handy tools!

Let me know in the comments below if you have any related questions. Happy networking!

Scroll to Top