樹(shù)莓派有多種聯(lián)網(wǎng)的方式,通過(guò)有線(xiàn)網(wǎng)或者通過(guò)無(wú)線(xiàn)網(wǎng)。通過(guò)有線(xiàn)網(wǎng)連接是比較簡(jiǎn)單的,在開(kāi)啟dhcp的路由器下,直接插上網(wǎng)線(xiàn)就可以聯(lián)網(wǎng),本文介紹樹(shù)莓派無(wú)線(xiàn)聯(lián)網(wǎng)的方式。再?zèng)]聯(lián)網(wǎng)的情況下,如果沒(méi)有屏幕等外設(shè),通過(guò)串口連接是一種比較簡(jiǎn)單有效的方式。
使用如下命令可以?huà)呙韪浇臒o(wú)線(xiàn)網(wǎng):
sudo iwlist wlan0 scan
掃描結(jié)果如下:
wlan0 Scan completed : Cell 01 - Address: F0:B4:29:1F:28:F1 ESSID:"00H Studio" Protocol:IEEE 802.11bgn Mode:Master Frequency:2.422 GHz (Channel 3) Encryption key:on Bit Rates:300 Mb/s Extra:rsn_ie=30140100000fac040100000fac040100000fac020000 IE: IEEE 802.11i/WPA2 Version 1 Group Cipher : CCMP Pairwise Ciphers (1) : CCMP Authentication Suites (1) : PSK Quality=100/100 Signal level=84/100 Cell 02 - Address: 06:74:9C:08:3F:7C ESSID:"QLU-2.4G" Protocol:IEEE 802.11bgn Mode:Master Frequency:2.412 GHz (Channel 1) Encryption key:off Bit Rates:144 Mb/s Quality=100/100 Signal level=72/100 Cell 03 - Address: D6:50:3F:0B:81:D1 ESSID:"7788" Protocol:IEEE 802.11bgn Mode:Master Frequency:2.422 GHz (Channel 3) Encryption key:on Bit Rates:72 Mb/s Extra:rsn_ie=30140100000fac040100000fac040100000fac020c00 IE: IEEE 802.11i/WPA2 Version 1 Group Cipher : CCMP Pairwise Ciphers (1) : CCMP Authentication Suites (1) : PSK IE: Unknown: DD180050F204104A00011010440001021049000600372A000120 Quality=44/100 Signal level=62/100
這里的“00H Studio”是無(wú)線(xiàn)網(wǎng)的名稱(chēng)。IEEE 802.11i/WPA2 Version 1是加密的方式。加密的類(lèi)型是WPA2類(lèi)型的。
通過(guò)配置wpa_supplicant.conf可以設(shè)置要連接的無(wú)線(xiàn)網(wǎng)。
sudo vim /etc/wpa_supplicant/wpa_supplicant.conf
在文件末尾出添加一下代碼,并替換掉ssid_name以及password即可。
network={ ssid="ssid_name" key_mgmt=WPA-PSK psk="password"}
通過(guò)
ifconfig wlan0
可以查看IP地址是否分配成功
wlan0 Link encap:Ethernet HWaddr e8:4e:06:34:f8:f5 inet addr:192.168.9.177 Bcast:192.168.9.255 Mask:255.255.255.0 inet6 addr: fdf5:a28:b70c:0:746:52db:d822:14bd/64 Scope:Global inet6 addr: fdf5:a28:b70c::6c5/128 Scope:Global inet6 addr: fe80::ea4e:6ff:fe34:f8f5/64 Scope:Link inet6 addr: fdf5:a28:b70c:0:ea4e:6ff:fe34:f8f5/64 Scope:Global UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:100930 errors:0 dropped:36149 overruns:0 frame:0 TX packets:290150 errors:0 dropped:2 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:146598855 (139.8 MiB) TX bytes:3218776758 (2.9 GiB)
如果要連接的是隱藏的網(wǎng)絡(luò),需要在配置文件中添加scan_ssid
連接。需要添加的內(nèi)容如下:
network={ ssid="yourHiddenSSID" scan_ssid=1 psk="Your_wifi_password"}
network={ ssid="SchoolNetworkSSID" psk="passwordSchool" id_str="school"}network={ ssid="HomeNetworkSSID" psk="passwordHome" id_str="home"}
如果您有兩個(gè)網(wǎng)絡(luò)的范圍,可以添加優(yōu)先級(jí)選項(xiàng)來(lái)在它們之間進(jìn)行選擇。具有最高優(yōu)先級(jí)的范圍內(nèi)的網(wǎng)絡(luò)將是連接的網(wǎng)絡(luò)。
network={ ssid="HomeOneSSID" psk="passwordOne" priority=1 id_str="homeOne"}network={ ssid="HomeTwoSSID" psk="passwordTwo" priority=2 id_str="homeTwo"}
添加沒(méi)有密碼的WIFI網(wǎng)絡(luò)需要注意將key_mgmt設(shè)置為NONE
network={ ssid="ssid_name" key_mgmt=NONE}
auto wlan0iface wlan0 inet static address 192.168.0.1 netmask 255.255.255.0 wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
如果出現(xiàn)連接不成功的情況,有很大的可能是由于配置文件配置錯(cuò)誤的原因。
sudo wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlan0
通過(guò)wpa_supplicant的直接連接,如果配置文件出現(xiàn)問(wèn)題,則會(huì)直接提示配置文件的錯(cuò)誤詳情。
如果出現(xiàn)一下結(jié)果,則一般代表配置文件沒(méi)有問(wèn)題
Successfully initialized wpa_supplicantnl80211: Driver does not support authentication/association or connect commandswlan0: Failed to initialize driver interface
聯(lián)系客服