$ sudo nmcli dev
注意,如果列出的设备状态是 unmanaged 的,说明网络设备不受NetworkManager管理,你需要清空 /etc/network/interfaces下的网络设置,然后重启.
$ sudo nmcli r wifi on
$ sudo nmcli dev wifi
$ sudo nmcli dev wifi connect "SSID" password "PASSWORD"
请将 SSID和 PASSWORD 替换成实际的 WiFi名称和密码。
连接成功后,下次开机,WiFi 也会自动连接。
具体例子
root@NanoPi-NEO2:~# ls
mjpg-streamer out1.mp4 test4.avi test4.mp4 WiringNP
Music test1.mp4 test4.mp3 test.avi
root@NanoPi-NEO2:~#
root@NanoPi-NEO2:~#
root@NanoPi-NEO2:~#
root@NanoPi-NEO2:~#
root@NanoPi-NEO2:~#
root@NanoPi-NEO2:~# sudo nmcli dev
DEVICE TYPE STATE CONNECTION
eth0 ethernet connected Wired connection 1
wlan0 wifi disconnected --
lo loopback unmanaged --
root@NanoPi-NEO2:~# sudo nmcli r wifi on
root@NanoPi-NEO2:~# sudo nmcli dev wifi
* SSID MODE CHAN RATE SIGNAL BARS SECURITY
root@NanoPi-NEO2:~# sudo nmcli dev wifi
* SSID MODE CHAN RATE SIGNAL BARS SECURITY
TP-2.4W Infra 1 54 Mbit/s 87 鈻傗杽鈻嗏枅 WPA1 WPA2
CTO.ZQ Infra 4 54 Mbit/s 74 鈻傗杽鈻哶 WPA2
test_2.4 Infra 13 54 Mbit/s 74 鈻傗杽鈻哶 WPA2
North-xt Infra 10 54 Mbit/s 64 鈻傗杽鈻哶 WPA2
aWiFi Infra 6 54 Mbit/s 44 鈻傗杽__
aWiFi Infra 11 54 Mbit/s 20 鈻俖__
ChinaNet Infra 11 54 Mbit/s 17 鈻俖__
Zoffice Infra 1 54 Mbit/s 4 ____ WPA1 WPA2
702 Infra 1 54 Mbit/s 4 ____ WPA1 WPA2
HTXX Infra 6 54 Mbit/s 4 ____ WPA1 WPA2
鍖楁柟绉戣 Infra 6 54 Mbit/s 4 ____
TP-LINK_0124 Infra 6 54 Mbit/s 4 ____ WPA1 WPA2
xiguo Infra 7 54 Mbit/s 4 ____ WPA2
灏忕背鍏变韩WiFi_B42F Infra 9 54 Mbit/s 4 ____
XXOO Infra 10 54 Mbit/s 4 ____ WPA1 WPA2
1+1BGS Infra 11 54 Mbit/s 4 ____ WPA2
root@NanoPi-NEO2:~# sudo nmcli dev wifi connect "TP-2.4W" password "5560558zv"
Device 'wlan0' successfully activated with 'bf6afbcf-57fa-4269-9bf0-d030bd95c4e3'.
root@NanoPi-NEO2:~#
root@NanoPi-NEO2:/etc/network# nmcli con show
NAME UUID TYPE DEVICE
TP-2.4W bf6afbcf-57fa-4269-9bf0-d030bd95c4e3 802-11-wireless wlan0
Wired connection 1 684b2cd0-741d-326c-999d-eb97ced5f224 802-3-ethernet eth0
TP.sun fd9a404d-966b-4514-a8ef-ac13e77cbf15 802-11-wireless --
test_2.4 f1800724-fec9-4af5-8d27-527dcebdbccd 802-11-wireless --
root@NanoPi-NEO2:/etc/network# nmcli con del "TP-2.4W"
Connection 'TP-2.4W' (bf6afbcf-57fa-4269-9bf0-d030bd95c4e3) successfully deleted.
root@NanoPi-NEO2:/etc/network# nmcli con show
NAME UUID TYPE DEVICE
Wired connection 1 684b2cd0-741d-326c-999d-eb97ced5f224 802-3-ethernet eth0
test_2.4 f1800724-fec9-4af5-8d27-527dcebdbccd 802-11-wireless wlan0
TP.sun fd9a404d-966b-4514-a8ef-ac13e77cbf15 802-11-wireless --
root@NanoPi-NEO2:/etc/network#