nmcli connection Command Examples in Linux

The nmcli connection subcommand is part of the nmcli tool and is used to manage network connections with NetworkManager. It provides various options for working with network connections, such as creating, modifying, listing, and deleting connections.

With this subcommand, you can create new network connections, configure existing connections, view information about the current status of connections, and more. Some common tasks that can be performed using nmcli connection include:

  • Listing all available connections: nmcli connection show
  • Creating a new connection: nmcli connection add type [type] con-name [name]
  • Modifying an existing connection: nmcli connection modify [name] [property] [value]
  • Activating a connection: nmcli connection up [name]
  • Deactivating a connection: nmcli connection down [name]
  • Deleting a connection: nmcli connection delete [name]

nmcli connection Command Examples

1. List all NetworkManager connections (shows name, UUID, type and device):

# nmcli connection

2. Activate a connection by specifying a UUID:

# nmcli connection up uuid {{uuid}}

3. Deactivate a connection:

# nmcli connection down uuid {{uuid}}

4. Create an auto-configured dual stack connection:

# nmcli connection add ifname {{interface_name}} type{{ethernet}} ipv4.method {{auto}} ipv6.method {{auto}}

5. Create a static IPv6-only connection:

# 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}}

6. Create a static IPv4-only connection:

# 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}}

7. Create a VPN connection using OpenVPN from a OVPN file:

# nmcli connection import type {{openvpn}} file {{path/to/vpn_config.ovpn}}

Summary

In summary, the nmcli connection subcommand is a powerful tool for managing network connections with NetworkManager. It provides a variety of options for creating, modifying, and managing connections, making it a useful tool for administrators and network engineers.

Related Post