![USB Wifi 适配器未连接到 AP (CLI)](https://linux22.com/image/108670/USB%20Wifi%20%E9%80%82%E9%85%8D%E5%99%A8%E6%9C%AA%E8%BF%9E%E6%8E%A5%E5%88%B0%20AP%20(CLI).png)
我最近设置了一个基于 armhf 的板,并且其网络配置遇到了这个问题。现在它连接了一个 TP-Link USB WiFi 适配器,似乎我能够连接到我的 WiFi,但是当我拔下以太网电缆时,我无法使用我在 中配置的 IP 地址连接到开发板/etc/network/interfaces
。我也检查了接入点,但根据它,我的设备从未通过 WiFi 连接到它。
我有点迷失了,因为根据统计数据,它似乎运行得很好。这是我到目前为止所拥有的:
$ tail -n [changes] /var/log/syslog
Mar 30 23:09:24 localhost kernel: [ 830.968410] sun7i-dwmac 1c50000.ethernet eth0: Link is Down
Mar 30 23:09:50 localhost kernel: [ 856.968094] sun7i-dwmac 1c50000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
连接似乎已启动并正在运行
$ iw wlan0 link
Connected to xx:67:5x:e1:9f:af (on wlan0)
SSID: UPCA887FD1
freq: 2452
RX: 187653 bytes (1131 packets)
TX: 500 bytes (6 packets)
signal: -48 dBm
tx bitrate: 57.8 MBit/s MCS 5 short GI
bss flags: short-slot-time
dtim period: 1
beacon int: 100
$ iwconfig
eth0 no wireless extensions.
wlan0 IEEE 802.11 ESSID:"nietwurk"
Mode:Managed Frequency:2.452 GHz Access Point: xx:67:5x:e1:9f:af
Bit Rate=72.2 Mb/s Tx-Power=20 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
Link Quality=66/70 Signal level=-44 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
lo no wireless extensions.
$ ifconfig
...
wlan0 Link encap:Ethernet HWaddr 64:70:02:0e:10:99
inet addr:192.168.0.35 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4494 errors:0 dropped:2 overruns:0 frame:0
TX packets:11 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:498743 (487.0 KiB) TX bytes:1338 (1.3 KiB)
$ ifup -vvv wlan0
Configuring interface wlan0=wlan0 (inet)
run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
run-parts: executing /etc/network/if-pre-up.d/bridge
run-parts: executing /etc/network/if-pre-up.d/ethtool
run-parts: executing /etc/network/if-pre-up.d/hostapd
run-parts: executing /etc/network/if-pre-up.d/ifenslave
+ [ inet = meta ]
+ IF_BOND_SLAVES=
+ [ ]
+ [ ]
+ [ -z ]
+ exit
run-parts: executing /etc/network/if-pre-up.d/vlan
run-parts: executing /etc/network/if-pre-up.d/wireless-tools
run-parts: executing /etc/network/if-pre-up.d/wpasupplicant
wpa_supplicant: wpa-driver nl80211,wext (default)
wpa_supplicant: /sbin/wpa_supplicant -s -B -P /run/wpa_supplicant.wlan0.pid -i wlan0 -D nl80211,wext -C /run/wpa_supplicant
Starting /sbin/wpa_supplicant...
wpa_supplicant: creating sendsigs omission pidfile: /run/sendsigs.omit.d/wpasupplicant.wpa_supplicant.wlan0.pid
wpa_supplicant: ctrl_interface socket located at /run/wpa_supplicant/wlan0
wpa_supplicant: configuring network block -- 0
wpa_supplicant: wpa-ssid "nietwurk" -- OK
wpa_supplicant: wpa-psk ***** -- OK
wpa_supplicant: enabling network block 0 -- OK
ip addr add 192.168.0.35/255.255.255.0 broadcast 192.168.0.255 dev wlan0 label wlan0
ip link set dev wlan0 up
run-parts --exit-on-error --verbose /etc/network/if-up.d
run-parts: executing /etc/network/if-up.d/ethtool
run-parts: executing /etc/network/if-up.d/ifenslave
+ [ inet = meta ]
+ [ ]
run-parts: executing /etc/network/if-up.d/ip
run-parts: executing /etc/network/if-up.d/mountnfs
run-parts: executing /etc/network/if-up.d/openssh-server
run-parts: executing /etc/network/if-up.d/upstart
run-parts: executing /etc/network/if-up.d/wpasupplicant
/etc/network/interfaces
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.35
netmask 255.255.255.0
wpa-ssid nietwurk
wpa-psk <the psk, not in quotes>
wireless-mode Managed
有任何想法吗?
答案1
限制 /etc/network/interfaces 的权限,以防止预共享密钥 (PSK) 泄露(或者在较新的 Debian 版本上使用单独的配置文件,例如 /etc/network/interfaces.d/wlan0):
chmod 0600 /etc/network/interfaces
通过更改以下示例,使用 WPA 密码计算 SSID 的正确 WPA PSK 哈希值:
wpa_passphrase myssid my_very_secret_passphrase
如果您未在命令行中输入密码,系统会提示您输入密码。上述命令给出输出:
network={
ssid="myssid"
#psk="my_very_secret_passphrase"
psk=ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b
}
您需要从“psk=”复制到该行的末尾,以放入您的 /etc/network/interfaces 文件中。
在文本编辑器中打开 /etc/network/interfaces :
nano /etc/network/interfaces
为您的无线接口定义适当的节,以及 SSID 和 PSK HASH。例如:
auto wlan0 iface wlan0 inet dhcp wpa-ssid myssid wpa-psk ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b
“auto”节将在系统启动时打开您的界面。如果不需要,请删除或注释此行。
- 保存文件并退出编辑器。
打开你的界面。这将启动 wpa_supplicant 作为后台进程。
# ifup wlan0