2015年10月7日 星期三

Raspberry Pi 設置無線網路 (USB WiFi: Tenda RT5370)


1. 確認硬體資訊,使用 RT5370這張無線網卡做設定。建議使用的網卡有在清單中,才可隨插即用。

pi@raspberrypi ~ $ lsusb
          
Bus 001 Device 004: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter

2. 查看目前無線網路設定,一開始還沒連接上無線網路,所以狀態會是 “off”。

pi@raspberrypi ~ $ iwconfig wlan0
        
wlan0             IEEE 802.11bgn ESSID:off/any
                       Mode:Managed Access Point: Not-Associated Tx-Power=20 dBm
                       Retry short limit:7 RTS thr:off Fragment thr:off
                        Power Management:off

3. 掃描無線網路,我們會根據掃描結果來設定無線網路。假設本例的 SSID 為AAA,加密方式為 WPA2,使用的 pre-shared key 為1234567890。

pi@raspberrypi ~ $ sudo iwlist wlan0 scan
        
Cell 03 - Address: B8:55:10:E4:30:9C
               Channel:5
                Frequency:2.432 GHz (Channel 5)
                Quality=65/70 Signal level=-45 dBm
                Encryption key:on
                ESSID:"AAA "
                Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s9 Mb/s; 12 Mb/s; 18 Mb/s
                Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s 

4. 修改 /etc/wpa_supplicant/wpa_supplicant.conf

pi@raspberrypi:~$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
        
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
                  ssid="AAA"
                  psk="123456789"proto=RSNkey_mgmt=WPA-PSKpairwise=CCMP auth_alg=OPEN
} 

5. 停用 wlan0 網卡。

pi@raspberrypi ~ $ sudo ifdown wlan0

6. 啟用 wlan0 網卡。

pi@raspberrypi ~ $ sudo ifup wlan0

7. 查尋 IP 位址,成功取得 192.168.1.14

pi@raspberrypi ~ $ ifconfig wlan0
        
wlan0   Link encap:Ethernet HWaddr c8:3a:35:c5:55:76
             inet addr:192.168.1.14 Bcast:192.168.1.255 Mask:255.255.255.0
             inet6 addr: fe80::7469:1703:e2e3:3afa/64 Scope:Link
             UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
             RX packets:155 errors:0 dropped:0 overruns:0 frame:0
            TX packets:105 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:1000
            RX bytes:34789 (33.9 KiB) TX bytes:13588 (13.2 KiB) 

Reference: