How To Add Connection Using Nmcli A Step By Step Guide

How To Add Connection Using Nmcli A Step By Step Guide

Adding a connection using nmcli is straightforward once you understand the basic commands. This guide walks you through every step, from checking your network devices to creating custom connection profiles. You will learn how to configure Wi-Fi, ethernet, and static IP settings using simple terminal commands.

Managing network connections on Linux can feel intimidating at first. But once you learn the basics, it becomes second nature. One of the most useful tools for this task is nmcli. Short for Network Manager Command Line Interface, nmcli lets you control your network settings directly from the terminal. Whether you are setting up a new Wi-Fi network or configuring a static IP address, nmcli has you covered. In this guide, we will walk you through exactly how to add a connection using nmcli, step by step.

You might be wondering why you would use nmcli instead of a graphical tool. The answer is simple. The command line gives you more control and precision. It also works on servers and headless systems where no desktop environment exists. If you have ever connected Bluetooth to your TV or paired devices wirelessly, you already understand the idea of setting up a connection manually. nmcli does the same thing, but for Linux network interfaces. It is fast, reliable, and incredibly powerful once you get the hang of it.

Key Takeaways

  • nmcli is a powerful command-line tool that lets you manage NetworkManager connections on Linux systems without a graphical interface.
  • You can add Wi-Fi, ethernet, and VPN connections using simple nmcli commands with just a few parameters.
  • Saving connections as persistent profiles ensures your network settings survive reboots and reconnect automatically.
  • Checking device status and connection details before adding a new connection helps avoid common configuration errors.
  • Modifying and deleting connections is just as easy as creating them, giving you full control over your network setup.

What Is Nmcli and Why Should You Use It?

Nmcli is the official command-line client for NetworkManager, which is the default network management service on most modern Linux distributions. It handles both wired and wireless connections. Think of it as the brain behind your network settings. Every time you connect to a Wi-Fi network or plug in an ethernet cable, NetworkManager takes care of the details. Nmcli simply gives you a way to talk to that brain directly.

There are several reasons why learning nmcli is worth your time. First, it works on virtually every Linux distribution that uses NetworkManager. That includes Ubuntu, Fedora, CentOS, Debian, and Arch Linux. Second, it is perfect for remote administration. You can manage network connections on a server from your laptop over SSH. Third, it is faster than clicking through multiple menus in a graphical interface. Once you memorize a few commands, you can add, modify, or delete connections in seconds.

Key Nmcli Commands You Should Know

Before diving into adding connections, let us cover the essential nmcli commands that you will use constantly. These form the foundation of everything else you will do:

  • nmcli device status — Shows all network devices and their current state.
  • nmcli connection show — Lists all saved connection profiles on your system.
  • nmcli connection add — Creates a new connection profile.
  • nmcli connection modify — Changes settings on an existing connection.
  • nmcli connection up — Activates a specific connection.
  • nmcli connection down — Deactivates a connection.
  • nmcli connection delete — Removes a saved connection profile.

These commands are your bread and butter. You will use them every time you work with nmcli. The good news is that they follow a logical pattern. Once you understand the structure, you can figure out new commands on your own.

Step By Step: How To Add Connection Using Nmcli

Now let us get into the core of this guide. Adding a connection using nmcli involves a few clear steps. We will start with the basics and build up to more advanced configurations. Follow along, and you will have a working connection in no time.

Step 1: Check Your Network Devices

Before adding any connection, you need to know what network devices are available on your system. Open your terminal and type the following command:

nmcli device status

This command displays a list of all network interfaces on your machine. You will see entries for Wi-Fi adapters, ethernet ports, and sometimes virtual interfaces. Each device will show a state, such as connected, disconnected, or unavailable. Make sure your Wi-Fi or ethernet device is in an available or disconnected state before proceeding. If a device shows as unavailable, you may need to check your hardware or drivers first.

For example, you might see output like this:

DEVICE TYPE STATE CONNECTION
wlan0 wifi disconnected --
eth0 ethernet connected Wired connection 1

In this example, wlan0 is your wireless adapter and eth0 is your ethernet port. The wlan0 device is disconnected and ready for a new connection profile.

Step 2: Identify the Connection Type

Next, decide what type of connection you want to add. Nmcli supports several connection types, and choosing the right one matters. The most common types include Wi-Fi, ethernet, VPN, and Bluetooth. Each type has its own set of required parameters.

For a Wi-Fi connection, you will need the SSID (the network name) and the password. For an ethernet connection, you typically just need to specify the device name. If you are setting up a static IP address, you will need additional details like the IP address, subnet mask, gateway, and DNS servers. Knowing what you need before you start saves time and prevents errors.

It is also worth noting that you can create a connection profile that does not auto-connect. This is useful for temporary setups or for connections you only need occasionally. We will cover this in more detail later in the guide.

Step 3: Add the Connection Using Nmcli

This is the main step. Here is where you actually create the connection profile. The basic syntax for adding a Wi-Fi connection looks like this:

nmcli connection add type wifi con-name "My-WiFi" ifname wlan0 ssid "NetworkName" wifi-sec.psk "password"

Let us break this down. The type wifi part tells nmcli this is a wireless connection. The con-name is a friendly name you choose for the connection profile. The ifname specifies which network interface to use. The ssid is the name of the Wi-Fi network you want to connect to. And wifi-sec.psk is the password for that network.

For an ethernet connection, the command is simpler:

nmcli connection add type ethernet con-name "Wired-Connection" ifname eth0

This creates a basic ethernet profile that uses DHCP by default, which means it will automatically get an IP address from your router. Most home and office networks work this way, so you usually do not need to specify anything else.

Step 4: Configure Additional Settings (Optional)

Once the basic connection is added, you can customize it further. This is where nmcli really shines. You can set a static IP address, change DNS servers, configure MAC address cloning, and much more. All of this is done using the nmcli connection modify command.

For example, to set a static IP address on your ethernet connection, you would run:

nmcli connection modify "Wired-Connection" ipv4.addresses 192.168.1.100/24
nmcli connection modify "Wired-Connection" ipv4.gateway 192.168.1.1
nmcli connection modify "Wired-Connection" ipv4.dns 8.8.8.8 8.8.4.4
nmcli connection modify "Wired-Connection" ipv4.method manual

These four commands set the IP address, gateway, DNS servers, and change the method from DHCP to manual. After making these changes, you can bring the connection back up with:

nmcli connection up "Wired-Connection"

You can also set whether the connection should autoconnect on boot. By default, most connections are set to autoconnect. To change this behavior, use:

nmcli connection modify "My-WiFi" connection.autoconnect no

This is handy when you have multiple Wi-Fi networks and only want certain ones to connect automatically.

Step 5: Verify and Activate the Connection

After adding a connection, always verify that it was created correctly. Run this command to see all saved profiles:

nmcli connection show

You should see your new connection listed with all its settings. To activate it, simply use the nmcli connection up command followed by the connection name:

nmcli connection up "My-WiFi"

You should see a message confirming the connection is active. You can also check the device status again with nmcli device status to confirm the interface is now connected.

If you are connecting to a network similar to how you would connect your laptop to your Vizio TV wirelessly, the process of scanning and selecting a network is conceptually similar. Both involve identifying the target network, providing credentials, and establishing a link. The difference is that nmcli does this entirely through text commands in the terminal.

Common Connection Types and Their Nmcli Commands

Different network setups require different configurations. Here is a quick reference for the most common connection types you might need to add.

Wi-Fi Connections

Wi-Fi connections are the most common type you will add with nmcli. The key parameters are the SSID and the security password. Nmcli supports WPA, WPA2, and open networks. For an open network with no password, you simply omit the wifi-sec.psk parameter.

To scan for available Wi-Fi networks first, use:

nmcli device wifi list

This shows all nearby networks, their signal strength, and security type. It is a great way to confirm the network name before creating a profile.

Ethernet Connections

Ethernet connections are the simplest to add. They usually require only the device name and a profile name. Most ethernet connections use DHCP, so minimal configuration is needed. However, if you are in a corporate or server environment, you might need to set static IP details as shown in Step 4 above.

VPN Connections

Nmcli also supports adding VPN connections. You can create OpenVPN, WireGuard, or IPSec profiles using the type vpn parameter. VPN connections require additional files or parameters depending on the protocol. For example, an OpenVPN connection might reference a configuration file stored on your system.

Bonding and VLAN Connections

For more advanced networking setups, nmcli supports bond interfaces and VLAN tagging. These are common in enterprise environments where link aggregation or network segmentation is needed. The commands follow the same pattern but include additional parameters specific to each type.

Managing Your Connections After Adding Them

Adding a connection is only the beginning. You will likely need to modify, rename, or delete connections over time. Nmcli makes all of these tasks easy.

Renaming a Connection

To rename a connection profile, use the modify command with the connection.id property:

nmcli connection modify "Old-Name" connection.id "New-Name"

This changes the display name without affecting the actual connection settings. It is a clean way to keep your connection list organized.

Modifying Existing Connections

Beyond renaming, you can change any setting on an existing connection. For example, to change the Wi-Fi password on a saved profile:

nmcli connection modify "My-WiFi" wifi-sec.psk "new-password"

Then bring the connection back up for the changes to take effect.

Deleting a Connection

If you no longer need a connection profile, you can delete it entirely:

nmcli connection delete "My-WiFi"

This removes the profile from your system. The device itself remains intact and ready for a new connection profile if needed.

Troubleshooting Common Nmcli Issues

Even with simple commands, things can sometimes go wrong. Here are a few common issues and how to fix them.

Device Shows as Unavailable

If your device shows as unavailable in the nmcli device status output, the driver might not be loaded properly. Try restarting the NetworkManager service with sudo systemctl restart NetworkManager. You can also check if the device is blocked using nmcli radio wifi or nmcli radio ethernet.

Connection Fails to Activate

If a connection you just added fails to activate, double-check the SSID and password for Wi-Fi connections. For ethernet, make sure the cable is plugged in and the device name matches. You can also check system logs with journalctl -u NetworkManager for detailed error messages.

Profile Not Persisting After Reboot

Connection profiles should persist across reboots by default. If a profile disappears, check that it was saved correctly. You can also verify the connection file exists in /etc/NetworkManager/system-connections/. Make sure the file has the correct permissions, typically 600.

Expert Tips for Working With Nmcli

Here are some pro tips that will make your nmcli experience smoother and more efficient.

  • Use tab completion. Most modern terminals support tab completion for nmcli commands. This saves typing and reduces errors.
  • Save your commands. When setting up a new server, keep a text file of all nmcli commands you run. This makes it easy to replicate the setup on other machines.
  • Use descriptive connection names. Instead of naming a connection “Connection 1,” use something like “Office-WiFi-5G” or “Home-Ethernet-Static.” This makes it much easier to identify connections later.
  • Check for conflicts. Before adding a new connection, run nmcli connection show to make sure you are not creating a duplicate profile.
  • Use the help flag. Whenever you are unsure about a command, add --help to see all available options. For example, nmcli connection add --help shows every parameter you can use.
  • Connect a USB hub to your laptop if you need to add more network interfaces, such as a USB-to-ethernet adapter, and nmcli will detect the new device automatically.

These small habits make a big difference. They save time, reduce frustration, and help you build a reliable network configuration that works consistently across reboots and system updates.

Key Takeaways

  • Nmcli is the go-to tool for managing network connections from the Linux command line with precision and speed.
  • Adding a connection using nmcli follows a clear process: check devices, identify the type, add the profile, configure settings, and activate.
  • Wi-Fi and ethernet connections are the most common types, but nmcli also supports VPNs, bonds, and VLANs for advanced setups.
  • Persistent connection profiles are saved automatically and survive system reboots without extra configuration.
  • Modifying and deleting connections is just as simple as creating them, giving you full lifecycle control over your network settings.
  • Troubleshooting is straightforward when you know where to look, from device status to system logs and connection files.

Conclusion

Learning how to add a connection using nmcli opens up a world of possibilities for managing your Linux network. Whether you are a beginner just getting started or an experienced administrator managing multiple servers, nmcli gives you the tools you need. The commands are logical, the process is repeatable, and the results are reliable.

Start with the basic commands we covered in this guide. Practice adding a Wi-Fi connection and an ethernet connection on your own system. Once you are comfortable, explore the more advanced options like static IP configuration and VPN setup. The more you use nmcli, the more natural it becomes. You will find yourself reaching for the terminal every time you need to manage a network connection, and that is exactly where you want to be.

Network management does not have to be complicated. With the right tools and a little practice, you can handle any connection scenario confidently. Now go ahead and add your first connection using nmcli. You will be surprised how quick and satisfying it can be.

Frequently Asked Questions

What is nmcli used for in Linux?

Nmcli is used to manage network connections through the command line on Linux systems. It lets you add, modify, delete, and activate network profiles for Wi-Fi, ethernet, VPN, and other connection types without needing a graphical interface.

Can I add a Wi-Fi connection using nmcli without a password?

Yes, you can add an open Wi-Fi connection by omitting the wifi-sec.psk parameter. This creates a profile for networks that do not require a password. However, be cautious when connecting to open networks, as they may not be secure.

How do I know which network device to use with nmcli?

Run the command nmcli device status to see all available network devices on your system. The device name (like wlan0 for Wi-Fi or eth0 for ethernet) is what you specify in the ifname parameter when adding a connection.

Will my nmcli connection survive a system reboot?

Yes, connection profiles created with nmcli are persistent by default. They are saved in /etc/NetworkManager/system-connections/ and will automatically reconnect on boot, provided the autoconnect setting is enabled.

Can I use nmcli on a remote server via SSH?

Absolutely. Nmcli works perfectly over SSH sessions. This is one of its biggest advantages. You can manage network connections on a headless server or remote machine just as easily as on a local desktop.

What is the difference between nmcli and editing NetworkManager config files directly?

Using nmcli is safer and more reliable than manually editing config files. Nmcli validates your input and updates all related files and services properly. Manual edits can lead to syntax errors or inconsistent configurations that break your network.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *