查看USB-WIFI是否工作正常
pi@raspberrypi:~ $ lsusb
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:9512 Standard Microsystems Corp. SMC9512/9514 USB Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 004: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter(看见这一条说明USB-WIFI成功识别)
pi@raspberrypi:~ $ ifconfig
eth0: flags=4099 mtu 1500
ether b8:27:eb:82:81:07 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163 mtu 1500
inet 192.168.31.106 netmask 255.255.255.0 broadcast 192.168.31.255
inet6 fe80::2939:8b92:a422:ca01 prefixlen 64 scopeid 0x20
ether e8:4e:06:19:bf:84 txqueuelen 1000 (Ethernet)
RX packets 20719 bytes 3667779 (3.4 MiB)
RX errors 0 dropped 88 overruns 0 frame 0
TX packets 18509 bytes 2502715 (2.3 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
看到有wlan0显示,说明USB-WIFI工作正常(一开始wlan0下面的信息是没有ip地址,网关和子网掩码的)
开始配置
/etc/network/interfaces文件配置如下
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
/etc/dhcpcd.conf文件配置如下
pi@raspberrypi:~ $ sudo nano /etc/dhcpcd.conf
# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.
# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel
# Inform the DHCP server of our hostname for DDNS.
hostname
# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid
# Persist interface configuration when dhcpcd exits.
persistent
# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit
# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu
# A ServerID is required by RFC2131.
require dhcp_server_identifier
# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private
# Example static IP configuration:
#interface eth0
#static ip_address=192.168.0.10/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1
# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1
# fallback to static profile on eth0
#interface eth0
#fallback static_eth0
interface eth0
static ip_address=111.111.111.111/24
static routers=111.111.111.1interface eth0(有线网口配置)
static ip_address=111.111.111.111/24 (IP地址和子网掩码)
static routers=111.111.111.1(网关)
/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="WiFi-name1"
psk="WiFi-password1"
priority=5
}
network={
ssid="WiFi-name2"
psk="WiFi-password2"
priority=4
}ssid="WiFi-name1"(WIFI名字)
psk="WiFi-password1" (WIFI密码)
priority=5(优先级,数字越大优先连接这个WIFI)
配置完成重启树莓派
sudo reboot