Login

Navigation

This articles is published 871 days ago and last updated 871 days ago, some information may be out of date.

透過nmcli指命連接 WIFI

Cover.png

前言:
nmcli 是用於控制 NetworkManager 和報告網絡狀態的命令行工具;創建、編輯、開啟/關閉和刪除網絡連接 。Armbian 系統默認安裝 nmcli
基礎使用:

查看設備狀態:

nmcli device status
DEVICE TYPE STATE CONNECTION
eth0 ethernet connected Ifupdown (eth0)
docker0 bridge connected (externally) docker0
wlan0 wifi disconnected --
ip6tnl0 iptunnel unmanaged --
sit0 iptunnel unmanaged --
lo loopback unmanaged --

wlan0 是無線網卡

檢查 radio的狀態:

nmcli radio
WIFI-HW WIFI WWAN-HW WWAN
enabled enabled enabled enabled

查看可連接的無線信號:

nmcli device wifi list

IN-USE BSSID SSID MODE CHAN RATE SIGNAL BARS SECURITY

​ 3C:7C:3F:3E:BA:C0 OFFICEAP Infra 2 0 Mbit/s 100 ▂▄▆█ WPA2
​ DE:B9:70:7B:CA:62 OFFICE_Public Infra 6 16 Mbit/s 96 ▂▄▆█ WPA2
​ DE:B9:70:7B:CA:60 OFFICE_Guest Infra 6 16 Mbit/s 96 ▂▄▆█ --
​ 50:C7:BF:78:51:A6 TP-LINK Infra 10 0 Mbit/s 96 ▂▄▆█ WPA1 WPA2
​ DE:B9:70:7B:CA:61 AP-RM312 Infra 6 16 Mbit/s 93 ▂▄▆█ WPA2
​ DE:B9:70:7B:CA:63 OFFICE_Open Infra 6 16 Mbit/s 92 ▂▄▆█ --
​ DE:B9:70:7B:CA:6F OFFICE Infra 6 16 Mbit/s 90 ▂▄▆█ WPA2
​ 12:23:44:87:FA:C3 OFFICE Infra 11 16 Mbit/s 71 ▂▄▆_ WPA2
​ 12:23:44:87:FA:C5 AP-RM211 Infra 11 16 Mbit/s 68 ▂▄▆_ WPA2
​ 12:23:44:87:FA:C7 OFFICE_Open Infra 11 16 Mbit/s 63 ▂▄▆_ --
​ 12:23:44:87:FA:C4 OFFICE_Guest Infra 11 16 Mbit/s 63 ▂▄▆_ --
​ 12:23:44:87:FA:C6 OFFICE_Public Infra 11 16 Mbit/s 63 ▂▄▆_ WPA2
​ 34:20:E3:10:41:78 OFFICE_Staff_WIFI Infra 1 16 Mbit/s 42 ▂▄__ WPA2
​ 27:D0:E9:87:FA:6A OFFICE_Guest Infra 11 16 Mbit/s 42 ▂▄__ --
​ 27:D0:E9:87:FA:6B AP-RM209 Infra 11 16 Mbit/s 26 ▂___ WPA2
​ 27:D0:E9:87:FA:6C OFFICE_Public Infra 11 16 Mbit/s 23 ▂___ WPA2

連接無線信號:

nmcli device wifi connect SSID password SSID_Passwd
Device 'wlan0' successfully activated with 'd048dcc1-decd-463f-b9c8-00cdf9c77a65'.
變量註解
SSIDWIFI名稱(信號)
SSID_PasswdWIFI密碼

查看連線狀態:

nmcli device show wlan0

查看無線信號密碼:

nmcli device wifi show-password ifname wlan0
SSID: TP-LINK
Security: WPA
Password: SSID_Passwd
結語:
這是連線的基礎使用,更進階可以利用nmcli指命編寫腳本實現動動化。