Linux: How to use nmcli to display current network configuraton and reconfigure a network adapter

nmcli is a command-line tool used to interact with NetworkManager, a network management daemon used in many Linux distributions. It allows you to view and configure network settings. Here’s how you can use nmcli to display the current network configuration and reconfigure a network adapter:

  1. Display Current Network Configuration:You can use nmcli to display the current network configuration:nmcli connection show This command will list all network connections along with their configuration details.
  2. Display Detailed Information about a Specific Connection:To view detailed information about a specific connection, such as the IP address, gateway, DNS servers, etc., use:nmcli connection show <connection_name> Replace <connection_name> with the name of the connection you want to inspect.
  3. Reconfigure a Network Adapter:To reconfigure a network adapter, you can modify its settings directly using nmcli. Here’s a basic example to set a static IP address:nmcli connection modify <connection_name> ipv4.addresses <ip_address>/<subnet_mask> ipv4.gateway <gateway_address> ipv4.dns <dns_server> Replace <connection_name>, <ip_address>, <subnet_mask>, <gateway_address>, and <dns_server> with appropriate values.For example:nmcli connection modify "Wired Connection 1" ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.dns 8.8.8.8 This command modifies the “Wired Connection 1” connection to use the specified static IP address, subnet mask, gateway, and DNS server.
  4. Apply Changes:After modifying the connection settings, apply the changes:nmcli connection up <connection_name> Replace <connection_name> with the name of the connection you modified.
  5. Verify Changes:Use nmcli connection show <connection_name> to verify that the changes have been applied successfully.

Remember to replace placeholders such as <connection_name>, <ip_address>, <subnet_mask>, <gateway_address>, and <dns_server> with actual values relevant to your network configuration. Additionally, ensure that you have appropriate permissions (usually root or sudo) to modify network settings.

Leave a comment