Linux NetworkManager: Command line examples

Hi,

this post contains some NetworkManager nmcli command line examples for frequently used tasks.



Show devices

root@debdev ~# nmcli dev status

Show all connections

root@debdev ~# nmcli connection show

Add a new connection with DHCP enabled

root@debdev ~# nmcli connection add type ethernet ifname eth0 

Change Connection name/id

root@debdev ~# nmcli connection modify "Wired connection 2" connection.id "ethernet 2"

Static IP Address

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

root@debdev ~# nmcli con mod "ethernet 2" ipv4.dns "10.254.10.252 10.254.10.253"

Add DNS

root@debdev ~# nmcli con mod "ethernet 2" +ipv4.dns 10.254.10.252

Add a static route

root@debdev ~# nmcli con mod "ethernet 3" +ipv4.routes "192.168.122.0/24 10.10.11.254"

Change a static IP

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

root@debdev ~# nmcli con up "ethernet 2" ip4 10.254.10.12/24

Switch from static IP to DHCP

root@debdev ~#  nmcli con mod "ethernet 2" ipv4.method auto

Connection set up

root@debdev ~# nmcli con up "ethernet 2" ifname eth0

Delete a connection

root@debdev ~# nmcli con delete con-name "eth IoT"

WiFi
List alle WLAN’s

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

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

Leave a Reply Cancel reply