以下操作已在Raspberry Pi 2配合RTL8188CUS 802.11n WLAN Adapter验证实践。
先通过有线网络SSH连接到树莓派,需要说明的一点是自2016年12月后发布的新Raspbain系统默认是不开启SSH的,连接时会提示错误ssh: connect to host 192.168.10.100 port 22: Connection refused,开启SSH需要在boot目录下创建一个名为ssh的空白文件。SSH连接到树莓派后可以使用lsusb和ifconfig命令查看该无线网卡是否支持。
#查看原配置 pi@raspberrypi:~ $ sudo cat /etc/network/interfaces # interfaces(5) file used by ifup(8) and ifdown(8) # Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' # Include files from /etc/network/interfaces.d: source-directory /etc/network/interfaces.d auto lo iface lo inet loopback iface eth0 inet manual allow-hotplug wlan0 iface wlan0 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf allow-hotplug wlan1 iface wlan1 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
#修改后的配置 #若你不使用树莓派的有线网口连接网络的话最好把auto eth0去掉,因为它会导致树莓派开机时等待有线网卡动态分配IP,但实际上有线网口并没有连接到路由器,会让内核等待更长的时间而拖慢开机速度。 pi@raspberrypi:~ $ sudo nano /etc/network/interfaces # interfaces(5) file used by ifup(8) and ifdown(8) # Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' # Include files from /etc/network/interfaces.d: source-directory /etc/network/interfaces.d auto lo iface lo inet loopback auto eth0 iface eth0 inet dhcp allow-hotplug wlan0 auto wlan0 iface wlan0 inet dhcp wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf allow-hotplug wlan1 iface wlan1 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
配置WiFi信息
#可能需要安装的工具 sudo apt install wireless-tools #查看附近的WiFi iwlist wlan0 scan #ssid:网络的ssid #psk:密码 #priority:连接优先级,数字越大优先级越高(不可以是负数) #scan_ssid:连接隐藏WiFi时需要指定该值为1 pi@raspberrypi:~ $ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf country=CN ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="MyHome" psk="1234567890" priority=10 } network={ ssid="TestAP0" psk="ABCDEFGHI" priority=9 scan_ssid=1 } network={ ssid="TestAP1" psk="jklmnopqr" priority=8 }
连接到WiFi需要重启一下wlan0端口
#禁用wlan0端口 sudo ifdown wlan0 #启用wlan0端口 sudo ifup wlan0 #检查一下WiFi连接状态 iwconfig
本文标题:树莓派配置USB无线网卡
版权声明:本文使用「署名 4.0 国际」创作共享协议,转载或使用请遵守署名协议。
上一篇:树莓派配置USB声卡