Nmcli
Network Manager Command Line - is used for controlling NetworkManager and reporting network status.
Check connection status of interfaces
nmcli dev status
# nmcli dev status DEVICE TYPE STATE CONNECTION docker0 bridge connected docker0 virbr0 bridge connected virbr0 enp0s3 ethernet connected enp0s3 virbr0-nic ethernet disconnected -- lo loopback unmanaged --
Turn Connection Up or Down
nmcli connection down <interface> or nmcli connection up <interface>
# nmcli connection down ens192 Connection 'ens192' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)
# nmcli connection up ens192 Connection 'ens192' successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
Turn Networking Up or Down
nmcli networking off nmcli networking on
Turn Autoconnect On/Off
Turn on:
# nmcli connection modify ens192 connection.autoconnect "yes"
Turn of:
# nmcli connection modify ens192 connection.autoconnect "no"
For changes to take effect, turn the interface down and up (in some cases, this works better than restarting NetworkManager):
# nmcli con down ens192 # nmcli con up ens192
Error: unknown connection
If you tried adding a secondary NIC and you see it there in ip a command output, but you are getting the error: "Error: unknown connection <interface>", that can be because NetworkManager is unable to recognize or find the specified connection. This can happen due to various reasons such as incorrect configuration files, missing connections, or permission issues.
# nmcli connection up enp0s8 Error: unknown connection 'enp0s8'.
Ensure that the connection file is correctly configured and placed in the appropriate directory. The file should be located in /etc/NetworkManager/system-connections/ and have the correct permissions. Example:
$ sudo cat /etc/NetworkManager/system-connections/ens3.nmconnection [sudo] password for cisadmin: [connection] id=ens3 uuid=761c9d6a-3e4d-47a3-8c0d-f5ce612ee301 type=ethernet interface-name=ens3 [ethernet] [ipv4] method=auto [ipv6] addr-gen-mode=eui64 method=auto [proxy]
If the interface configuration file for the secondary NIC is not there, then you can add it using the following nmcli command (You would usually have to do this when adding a secondary NIC):
$ nmcli con add con-name <connection name> type ethernet ifname <interface> ipv4.method auto