iwconfig 與 iwlist 是 Linux Wireless Extensions (LWE) 的核心用戶空間工具,雖然現代系統逐漸轉向 nmcli / iw (nl80211),但在嵌入式裝置、舊版內核、精簡容器環境中仍不可或缺。本文系統整理所有參數與實戰範例,作為快速查閱手冊。
iwconfig interface [參數...]
參數支援:essid | nwid | mode | freq/channel | ap | rate | txpower | sens | retry | rts | frag | key/enc | power | commit
| 參數 | 功能 | 典型範例 |
|---|---|---|
essid | 設定/查詢 ESSID(網路名稱) | iwconfig wlan0 essid "MyWiFi" / essid any(混雜模式) |
mode | 工作模式 | Managed(基礎架構)、Ad-Hoc(點對點)、Monitor(監聽)、Master(AP) |
freq/channel | 頻率/頻道 | freq 2.422G、channel 6、channel auto(Managed 模式下由 AP 決定) |
ap | 指定 AP MAC 或自動選擇 | ap 00:11:22:33:44:55、ap any、ap off |
rate | 傳輸速率 | rate 11M、rate auto、rate 5.5M auto(上限 5.5M 自動) |
txpower | 發射功率 | txpower 15 (dBm)、txpower 30mW、txpower off(關閉射頻) |
key/enc | WEP 加密金鑰 | key s:password (ASCII)、key 0123-4567-89 (Hex)、key [2] 0123... (指定索引)、key off (關閉) |
power | 電源管理 | power period 2、power timeout 300u、power off |
rts :RTS/CTS 門檻,隱藏節點環境建議 250-512 bytes。frag :分片門檻,高干擾環境降低至 512 bytes 提高到達率。retry limit / retry lifetime :重傳次數/時間上限。sens -80:接收靈敏度門檻(dBm),低於此值觸發漫遊。commit:強制提交緩存參數至驅動(除錯用)。iwlist wlan0 scan
# 輸出關鍵欄位:Cell Address (BSSID)、ESSID、Mode、Frequency、Quality/Signal/Noise、Encryption key、Bit Rates
iwlist wlan0 channel
iwlist wlan0 freq
iwlist wlan0 bitrate # 支援速率
iwlist wlan0 txpower # 支援功率
iwlist wlan0 retry # 重傳能力
#!/bin/bash
# 連接 WPA2-PSK 網路(需 wpa_supplicant)
cat > /etc/wpa_supplicant/wpa_supplicant.conf <<EOF
network={
ssid="MyWiFi"
psk="secretpass"
key_mgmt=WPA-PSK
}
EOF
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
udhcpc -i wlan0 # 或 dhclient wlan0
CAP_NET_ADMIN。nmcli dev set wlan0 managed no 釋放。掌握 iwconfig/iwlist 完整參數,能在無 NetworkManager 的嵌入式、救援、容器環境中精準控制無線介面,是 Linux 網管與嵌入式開發者的必備硬功夫。