Hi,
this post contains some NetworkManager nmcli command line examples for frequently used tasks.
Show devices
1 | root@debdev ~ # nmcli dev status |
Show all connections
1 | root@debdev ~ # nmcli connection show |
Add a new connection with DHCP enabled
1 | root@debdev ~ # nmcli connection add type ethernet ifname eth0 |
Change Connection name/id
1 | root@debdev ~ # nmcli connection modify "Wired connection 2" connection.id "ethernet 2" |
Static IP Address
1 | root@debdev ~ # nmcli con add con-name "ethernet 2" ifname eth0 type ethernet ip4 10.254.10.10/24 gw4 10.254.10.254 |
Set DNS
1 | root@debdev ~ # nmcli con mod "ethernet 2" ipv4.dns "10.254.10.252 10.254.10.253" |
Add DNS
1 | root@debdev ~ # nmcli con mod "ethernet 2" +ipv4.dns 10.254.10.252 |
Add a static route
1 | root@debdev ~ # nmcli con mod "ethernet 3" +ipv4.routes "192.168.122.0/24 10.10.11.254" |
Change a static IP
1 | root@debdev ~ # nmcli con mod "ethernet 2" ipv4.addresses 10.254.10.11/24 |
Add a second static IP to an interface
Connection set up
1 | root@debdev ~ # nmcli con up "ethernet 2" ip4 10.254.10.12/24 |
Switch from static IP to DHCP
1 | root@debdev ~ # nmcli con mod "ethernet 2" ipv4.method auto |
Connection set up
1 | root@debdev ~ # nmcli con up "ethernet 2" ifname eth0 |
Delete a connection
1 | root@debdev ~ # nmcli con delete con-name "eth IoT" |
WiFi
List alle WLAN’s
1 | root@debdev ~ # nmcli device wifi list |
Network Manager as WiFi Access Point with SSID MyHomeWiFi, WPA2 authentication and “My Secret WiFi Password 999!” as PreSharedkey
1 2 3 4 5 6 7 8 | root@debdev ~ # nmcli connection add type wifi ifname wlan0 con-name "MyAccessPoint-Home" autoconnect no ssid "MyHomeWiFi" root@debdev ~ # nmcli connection modify "MyAccessPoint-Home" 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared root@debdev ~ # nmcli connection modify "MyAccessPoint-Home" wifi-sec.key-mgmt wpa-psk root@debdev ~ # nmcli connection modify "MyAccessPoint-Home" wifi-sec.psk "My Secret WiFi Password 999!" root@debdev ~ # nmcli connection modify "MyAccessPoint-Home" ipv4.addresses "10.11.1.1/24" root@debdev ~ # nmcli connection modify "MyAccessPoint-Home" ipv4.method manual root@debdev ~ # nmcli connection modify "MyAccessPoint-Home" autoconnect yes root@debdev ~ # nmcli connection up "MyAccessPoint-Home" |
Michael