1. 程式人生 > >樹莓派的無線網絡卡安裝

樹莓派的無線網絡卡安裝

首先,從網上買一個適用於樹莓派的無線網絡卡,一般大家都推薦EDUP

0 準備工作,插入USB無線網絡卡之前,檢查網路介面狀態。當然,這時候還是插著網線的。

$ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:75:29:09
          inet addr:192.168.2.109  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:232 errors:0 dropped:0 overruns:0 frame:0
          TX packets:145 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:26447 (25.8 KiB)  TX bytes:25209 (24.6 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

1 插入USB的無線網絡卡,網路介面是這樣的,出現了wlan0,就是我們的無線網絡卡

可以使用命令sudo lsusb 檢視掛載的USB裝置,也可以看到我們的無線網絡卡

當然,這時候無線網絡卡還沒有配置好,不能正常工作

$ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:75:29:09
          inet addr:192.168.2.109  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:232 errors:0 dropped:0 overruns:0 frame:0
          TX packets:145 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:26447 (25.8 KiB)  TX bytes:25209 (24.6 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr e8:4e:06:26:d2:4d
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

$ sudo lsusb
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter

2 修改樹莓派的網絡卡配置,藍色部分是新加的無線配置。

這裡使用靜態IP地址,方便以後ssh遠端連線。

$ sudo vim /etc/network/interfaces

auto lo

iface lo inet loopback

#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.2.109
netmask 255.255.255.0
gateway 192.168.2.1

#allow-hotplug wlan0
#iface wlan0 inet manual
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
wpa-ssid "your_ssid"
wpa-psk "your_password"
address 192.168.2.110
netmask 255.255.255.0
gateway 192.168.2.1

3 執行下面的命令,重啟網路介面。

這時候,拔掉網線,無線網絡卡應該能夠正常工作了。如果不行,power cycle一下樹莓派。

$ sudo /etc/init.d/networking restart

最後,如果一起正常,網絡卡狀態如下。

注意,我發現這個無線網絡卡如果長時間不用,好像就inactive了。需要主機ping一下,重新ssh一下才好用,搞不懂是怎麼回事?

$ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:75:29:09
          inet addr:192.168.2.109  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:12 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:558 (558.0 B)  TX bytes:250 (250.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr e8:4e:06:26:d2:4d
          inet addr:192.168.2.110  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:81 errors:0 dropped:0 overruns:0 frame:0
          TX packets:103 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:11361 (11.0 KiB)  TX bytes:16209 (15.8 KiB)