樹莓派配置 USB 無線網卡來上網的過程。
shell
本人使用的USB無線網卡型號:EP-N8508GS(樹莓派專用型號)
bash
將無線 USB 網卡插入樹莓派後啓動樹莓派,比較不建議熱插拔,由於插入的一瞬間會有比較高的電流,若是電源輸出不夠可能致使樹莓派重啓。
進入 shell 界面後輸入命令 lsusb
若是樹莓派已經正常識別,在顯示相似於以下的信息中能夠看到你的USB無線網卡設備 ID 和芯片型號:網絡
Bus 001 Device 004: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
如上,個人 pi 已經識別 RTL8188CUS 802.11n WLAN Adapter
再使用 iwconfig
命令確認一下:less
wlan0 unassociated Nickname:"<WIFI@REALTEK>" Mode:Managed Frequency=2.412 GHz Access Point: Not-Associated Sensitivity:0/0 Retry:off RTS thr:off Fragment thr:off Power Management:off Link Quality:0 Signal level:0 Noise level:0 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. eth0 no wireless extensions.
若是出現了 wlan0,那說明網卡已經正常工做了,若是這裏的顯示不正常,請安裝鏈接 wifi 必要的包。post
sudo apt-get install wireless-tools wpasupplicant firmware-realtek
輸入以下命令能夠搜索附近全部可鏈接的 WIFI AP:ui
sudo iwlist wlan0 scan
這邊搜到了十幾個 wifi 熱點,下圖是我本身家的:rest
Cell 09 - Address: 10:0D:7F:45:9E:D9 ESSID:"OpenWrt_2.4G" Protocol:IEEE 802.11bgn Mode:Master Frequency:2.462 GHz (Channel 11) Encryption key:on Bit Rates:144 Mb/s Extra:wpa_ie=dd1a0050f20101000050f20202000050f2040050f20201000050f202 IE: WPA Version 1 Group Cipher : TKIP Pairwise Ciphers (2) : CCMP TKIP Authentication Suites (1) : PSK Extra:rsn_ie=30180100000fac020200000fac04000fac020100000fac020c00 IE: IEEE 802.11i/WPA2 Version 1 Group Cipher : TKIP Pairwise Ciphers (2) : CCMP TKIP Authentication Suites (1) : PSK Quality=36/100 Signal level=66/100
使用以下命令得到 wifi 設置:code
wpa_passphrase SSID 名稱 密碼
回顯以下:ip
network={ ssid="OpenWrt_2.4G" #psk=" 密碼 " psk=ff5e84f34e6f496acff05d1a97271508bb4405d5d07864c2dc321941e427f778 }
複製這段回顯並保存到本身的配置文件中:ci
sudo nano /etc/wpa_supplicant/wpa_supplicant . conf
而後配置/etc/network/interfaces
:
sudo nano /etc/network/interfaces
配置 自動得到 IP 地址,配置內容以下:
allow-hotplug wlan0 auto wlan0 iface wlan0 inet dhcp pre-up wpa_supplicant -B w -D wext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf post-down killall -q wpa_supplicant
鏈接網絡:
sudo /etc/init.d/networking restart sudo ifup wlan0
關閉網絡:
sudo ifdown wlan0
iwconfig
和 ifconfig
驗證查看鏈接速度iwconfig
信息:
wlan0 IEEE 802.11bgn ESSID:"OpenWrt_2.4G" Nickname:"<WIFI@REALTEK>" Mode:Managed Frequency:2.462 GHz Access Point: 10:0D:7F:45:9E:D9 Bit Rate:65 Mb/s Sensitivity:0/0 Retry:off RTS thr:off Fragment thr:off Power Management:off Link Quality=100/100 Signal level=71/100 Noise level=0/100 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. eth0 no wireless extensions.
查看 ifconfig
信息:
wlan0 Link encap:Ethernet HWaddr e8:4e:06:20:03:7c inet addr:192.168.0.206 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fd1a:b6c5:65ca:0:d10a:30ca:da70:e8c7/64 Scope:Global inet6 addr: fd1a:b6c5:65ca::c3b/128 Scope:Global inet6 addr: fe80::733a:6f84:a823:d26a/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:440 errors:0 dropped:27 overruns:0 frame:0 TX packets:90 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:81492 (79.5 KiB) TX bytes:17685 (17.2 KiB)