2024-05-30
Before diving into specific commands, ensure NetworkManager is installed and running on your system. You can usually check its status with:
systemctl status NetworkManagerIf it’s not running, start it using:
sudo systemctl start NetworkManagerNow you’re ready to look at nmcli’s potential.
Connecting to a Wi-Fi network using nmcli is straightforward. First, use nmcli dev wifi to list available Wi-Fi networks:
nmcli dev wifiThis will display a list of SSIDs, signal strengths, and security types. To connect to a specific network (e.g., “MyNetwork”), use:
nmcli dev wifi connect "MyNetwork" password "YourPassword"Replace "MyNetwork" and "YourPassword" with your network’s SSID and password, respectively.
If your network requires a different authentication method (like WPA2-Enterprise), you may need additional parameters. Refer to the nmcli man page (man nmcli) for advanced options.
For wired connections, nmcli provides equally efficient control. To view your wired connections:
nmcli con show --activeThis displays information about currently active connections. To connect to a wired connection, assuming it’s detected, you often don’t need explicit commands as NetworkManager handles it automatically. However, you can manually control it with:
nmcli con up id <connection-id>Replace <connection-id> with the ID of the wired connection you want to activate. You can find this ID using nmcli con show.
Static IP addresses offer more control over your network settings. To configure a static IP, you’ll need to create a new connection. Let’s assume you want to create a connection named “StaticIP” with the following details:
The command to achieve this is:
nmcli con add type ethernet con-name StaticIP ifname eth0 ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.dns 8.8.8.8Replace eth0 with your ethernet interface name. After creating the connection, activate it using:
nmcli con up id StaticIPTo disconnect from a currently active connection, use the following command, replacing <connection-id> with the connection ID:
nmcli con down id <connection-id>nmcli provides a wealth of information about your network configuration. For a general overview of all connections, use:
nmcli con showTo view detailed information about a specific connection, use:
nmcli con show <connection-id>To see the status of your network devices:
nmcli dev statusThese commands provide details for troubleshooting and monitoring your network. Remember to replace placeholders like <connection-id> with the actual values from your system. Consult the nmcli man page for a detailed list of options and features.