How to use the command 'nmcli connection' (with examples)

How to use the command 'nmcli connection' (with examples)

Manage connections with NetworkManager using the ’nmcli connection’ command.

Use case 1: List all NetworkManager connections

Code:

nmcli connection

Motivation: The ’nmcli connection’ command is used to list all NetworkManager connections. This is useful to view the name, UUID, type, and device information of each connection.

Explanation: The command ’nmcli connection’ is used to list all the available NetworkManager connections. It displays the name, UUID, type, and device details of each connection.

Example output:

NAME      UUID                                  TYPE      DEVICE  
Wi-Fi     4e8e371a-8e55-4440-90cc-2f71ad014eb7  wifi      wlan0   
Ethernet  b26db577-0a2c-4f9d-9b9a-633eac14c8e2  ethernet  eth0    

Use case 2: Activate a connection

Code:

nmcli connection up uuid <connection_uuid>

Motivation: The ’nmcli connection up’ command is used to activate a specific connection. This command is useful when you want to manually start a connection.

Explanation: The command ’nmcli connection up’ is used to activate a specific connection identified by its UUID. By providing the connection UUID, NetworkManager will start the specified connection.

Example output:

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)

Use case 3: Deactivate a connection

Code:

nmcli connection down uuid <connection_uuid>

Motivation: The ’nmcli connection down’ command is used to deactivate a specific connection. This command is useful when a connection needs to be manually stopped.

Explanation: The command ’nmcli connection down’ is used to deactivate a specific connection identified by its UUID. By providing the connection UUID, NetworkManager will stop the specified connection.

Example output:

Connection successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)

Use case 4: Create an auto-configured dual stack connection

Code:

nmcli connection add ifname <interface_name> type ethernet ipv4.method auto ipv6.method auto

Motivation: The ’nmcli connection add’ command with suitable arguments is used to create a new auto-configured dual stack connection. This is useful when you want to create a connection that automatically configures both IPv4 and IPv6 settings.

Explanation: The command ’nmcli connection add’ is used to create a new connection. In this case, we are creating a dual stack connection using an Ethernet interface. The ‘ipv4.method auto’ and ‘ipv6.method auto’ arguments specify that both IPv4 and IPv6 configurations will be automatically handled by the connection.

Example output:

Connection 'AutoDualStack' (b6db5f17-af8e-4da5-a8bc-386453f113c5) successfully added.

Use case 5: Create a static IPv6-only connection

Code:

nmcli connection add ifname <interface_name> type ethernet ip6 2001:db8::2/64 gw6 2001:db8::1 ipv6.dns 2001:db8::1 ipv4.method ignore

Motivation: The ’nmcli connection add’ command with suitable arguments is used to create a new static IPv6-only connection. This is useful when you want to create a connection that is configured with specific IPv6 settings and ignores IPv4.

Explanation: The command ’nmcli connection add’ is used to create a new connection. In this case, we are creating an IPv6-only connection using an Ethernet interface. The ‘ip6 2001:db8::2/64’ argument specifies the IPv6 address and subnet. The ‘gw6 2001:db8::1’ argument specifies the IPv6 gateway address. The ‘ipv6.dns 2001:db8::1’ argument specifies the IPv6 DNS server address. The ‘ipv4.method ignore’ argument specifies that the connection should ignore IPv4 configurations.

Example output:

Connection 'IPv6Only' (eff5df29-2de8-4611-96ba-75e86d89955f) successfully added.

Use case 6: Create a static IPv4-only connection

Code:

nmcli connection add ifname <interface_name> type ethernet ip4 10.0.0.7/8 gw4 10.0.0.1 ipv4.dns 10.0.0.1 ipv6.method ignore

Motivation: The ’nmcli connection add’ command with suitable arguments is used to create a new static IPv4-only connection. This is useful when you want to create a connection that is configured with specific IPv4 settings and ignores IPv6.

Explanation: The command ’nmcli connection add’ is used to create a new connection. In this case, we are creating an IPv4-only connection using an Ethernet interface. The ‘ip4 10.0.0.7/8’ argument specifies the IPv4 address and subnet. The ‘gw4 10.0.0.1’ argument specifies the IPv4 gateway address. The ‘ipv4.dns 10.0.0.1’ argument specifies the IPv4 DNS server address. The ‘ipv6.method ignore’ argument specifies that the connection should ignore IPv6 configurations.

Example output:

Connection 'IPv4Only' (7d829610-326f-4b54-b982-cb51f8a84e00) successfully added.

Use case 7: Create a VPN connection using OpenVPN from an OVPN file

Code:

nmcli connection import type openvpn file <path/to/vpn_config.ovpn>

Motivation: The ’nmcli connection import’ command is used to create a VPN connection using OpenVPN from an OVPN file. This is useful when you want to import an existing OpenVPN configuration for NetworkManager to manage.

Explanation: The command ’nmcli connection import’ is used to import a VPN connection. In this case, we are using the ’type openvpn’ argument to specify that the connection is an OpenVPN connection. The ‘file <path/to/vpn_config.ovpn>’ argument provides the path to the OVPN file.

Example output:

Connection 'OpenVPNConnection' (5a2240a5-9511-4aac-8e28-5ace3ab0429f) successfully added.

Conclusion:

The ’nmcli connection’ command is a powerful tool for managing connections with NetworkManager. It allows you to list connections, activate and deactivate connections, as well as create new connections with various configurations. These examples demonstrate the versatility and usefulness of this command in different scenarios.

Related Posts

How to use the command 'sysctl' (with examples)

How to use the command 'sysctl' (with examples)

Sysctl is a command-line tool that allows users to view and modify kernel runtime variables on a Unix-like operating system.

Read More
How to use the command 'dlv' (with examples)

How to use the command 'dlv' (with examples)

This article will provide examples and explanations for different use cases of the ‘dlv’ command, which is a debugger for the Go programming language.

Read More
How to use the command pstopnm (with examples)

How to use the command pstopnm (with examples)

The pstopnm command is used to convert PostScript files to PNM images.

Read More