树莓派 RaspberryPi 终端命令行配置无线网络连接wifi

观书散遗帙,探古穷至妙。这篇文章主要讲述树莓派 RaspberryPi 终端命令行配置无线网络连接wifi相关的知识,希望能为你提供帮助。

root@raspberrypi:~# ifconfig wlan0 up root@raspberrypi:~#root@raspberrypi:~# iwlist wlan0 scan wlan0Scan completed : Cell 01 - Address: 68:A0:3E:5C:CA:70 Channel:1 Frequency:2.412 GHz (Channel 1) Quality=39/70Signal level=-71 dBm Encryption key:on ESSID:"wifi名称" Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 6 Mb/s; 9 Mb/s 11 Mb/s; 12 Mb/s; 18 Mb/s Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s Mode:Master Extra:tsf=0000000000000000 Extra: Last beacon: 10ms ago IE: Unknown: 000D436C6F7564616E745F4B485A58 IE: Unknown: 010882848B0C12961824 IE: Unknown: 030101 IE: Unknown: 0706434E20010D1B IE: Unknown: 23021E00 IE: Unknown: 46050000000000 IE: Unknown: 2A0103 IE: IEEE 802.11i/WPA2 Version 1 Group Cipher : CCMP Pairwise Ciphers (1) : CCMP Authentication Suites (1) : PSK IE: Unknown: DD180050F2020101800003A4000027A4000042435E0062322F00 IE: Unknown: 32043048606C IE: Unknown: 0B0507006E0000

root@raspberrypi:~# vi /etc/wpa_supplicant/wpa_supplicant.conf root@raspberrypi:~# root@raspberrypi:~# cat /etc/wpa_supplicant/wpa_supplicant.conf ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=CNnetwork={ ssid="wifi名称" key-mgmt=WPA-PSK psk="wifi密码" } root@raspberrypi:~# root@raspberrypi:~# ifconfig wlan0 wlan0: flags=4099< UP,BROADCAST,MULTICAST> mtu 1500 ether e4:5f:01:00:3b:a1txqueuelen 1000(Ethernet) RX packets 0bytes 0 (0.0 B) RX errors 0dropped 0overruns 0frame 0 TX packets 0bytes 0 (0.0 B) TX errors 0dropped 0 overruns 0carrier 0collisions 0root@raspberrypi:~#root@raspberrypi:~# wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlan0 Successfully initialized wpa_supplicant Line 7: too large scan_ssid (value=https://www.songbingjia.com/android/11 max_value=1) Line 7: failed to parse scan_ssid /'11\'. Line 10: failed to parse network block. Failed to read or parse configuration \'/etc/wpa_supplicant/wpa_supplicant.conf\'. root@raspberrypi:~#

root@raspberrypi:~# vi /etc/wpa_supplicant/wpa_supplicant.conf root@raspberrypi:~# root@raspberrypi:~# cat /etc/wpa_supplicant/wpa_supplicant.conf ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=CNnetwork={ ssid="wifi名称" scan_ssid=11 key-mgmt=WPA-PSK psk="wifi密码" }

root@raspberrypi:~# wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlan0 Successfully initialized wpa_supplicant wlan0: CTRL-EVENT-REGDOM-CHANGE init=USER type=COUNTRY alpha2=CN wlan0: Trying to associate with SSID \'wifi名称\' wlan0: Associated with b8:27:c5:a7:9d:b0 wlan0: CTRL-EVENT-CONNECTED - Connection to b8:27:c5:a7:9d:b0 completed [id=0 id_str=] wlan0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0 wlan0: CTRL-EVENT-REGDOM-CHANGE init=COUNTRY_IE type=COUNTRY alpha2=CN nl80211: Failed to open /proc/sys/net/ipv4/conf/p2p-dev-wlan0/drop_unicast_in_l2_multicast: No such file or directory nl80211: Failed to set IPv4 unicast in multicast filter nl80211: Failed to open /proc/sys/net/ipv4/conf/p2p-dev-wlan0/drop_unicast_in_l2_multicast: No such file or directory nl80211: Failed to set IPv4 unicast in multicast filter nl80211: deinit ifname=p2p-dev-wlan0 disabled_11b_rates=0 p2p-dev-wlan0: CTRL-EVENT-TERMINATING wlan0: CTRL-EVENT-DISCONNECTED bssid=b8:27:c5:a7:9d:b0 reason=3 locally_generated=1 nl80211: deinit ifname=wlan0 disabled_11b_rates=0 wlan0: CTRL-EVENT-TERMINATING root@raspberrypi:~# root@raspberrypi:~# ifconfig eth0: flags=4163< UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 169.254.205.229netmask 255.255.0.0broadcast 169.254.255.255 inet6 fe80::e65f:1ff:fe00:3ba0prefixlen 64scopeid 0x20< link> ether e4:5f:01:00:3b:a0txqueuelen 1000(Ethernet) RX packets 1841bytes 150781 (147.2 KiB) RX errors 0dropped 0overruns 0frame 0 TX packets 1483bytes 179352 (175.1 KiB) TX errors 0dropped 0 overruns 0carrier 0collisions 0lo: flags=73< UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1netmask 255.0.0.0 inet6 ::1prefixlen 128scopeid 0x10< host> looptxqueuelen 1000(Local Loopback) RX packets 5938bytes 341948 (333.9 KiB) RX errors 0dropped 0overruns 0frame 0 TX packets 5938bytes 341948 (333.9 KiB) TX errors 0dropped 0 overruns 0carrier 0collisions 0wlan0: flags=4099< UP,BROADCAST,MULTICAST> mtu 1500 inet6 fe80::e65f:1ff:fe00:3ba1prefixlen 64scopeid 0x20< link> ether e4:5f:01:00:3b:a1txqueuelen 1000(Ethernet) RX packets 1bytes 46 (46.0 B) RX errors 0dropped 0overruns 0frame 0 TX packets 75bytes 14475 (14.1 KiB) TX errors 0dropped 0 overruns 0carrier 0collisions 0root@raspberrypi:~#root@raspberrypi:~# reboot

重启后重新连接
Linux raspberrypi 5.4.83-v7l+ #1379 SMP Mon Dec 14 13:11:54 GMT 2020 armv7lThe programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright.Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Sun Aug 22 19:00:09 2021 from 169.254.205.222 root@raspberrypi:~# ifconfig eth0: flags=4163< UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 169.254.205.229netmask 255.255.0.0broadcast 169.254.255.255 inet6 fe80::e65f:1ff:fe00:3ba0prefixlen 64scopeid 0x20< link> inet6 fe80::3fa1:9571:af73:8712prefixlen 64scopeid 0x20< link> ether e4:5f:01:00:3b:a0txqueuelen 1000(Ethernet) RX packets 168bytes 18457 (18.0 KiB) RX errors 0dropped 0overruns 0frame 0 TX packets 125bytes 21969 (21.4 KiB) TX errors 0dropped 0 overruns 0carrier 0collisions 0lo: flags=73< UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1netmask 255.0.0.0 inet6 ::1prefixlen 128scopeid 0x10< host> looptxqueuelen 1000(Local Loopback) RX packets 86bytes 8628 (8.4 KiB) RX errors 0dropped 0overruns 0frame 0 TX packets 86bytes 8628 (8.4 KiB) TX errors 0dropped 0 overruns 0carrier 0collisions 0wlan0: flags=4163< UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.3.190netmask 255.255.255.0broadcast 192.168.3.255 inet6 fe80::e65f:1ff:fe00:3ba1prefixlen 64scopeid 0x20< link> ether e4:5f:01:00:3b:a1txqueuelen 1000(Ethernet) RX packets 37bytes 2926 (2.8 KiB) RX errors 0dropped 0overruns 0frame 0 TX packets 80bytes 14266 (13.9 KiB) TX errors 0dropped 0 overruns 0carrier 0collisions 0root@raspberrypi:~#

其实到这里还没完,应该手动再配置一波,搞成静态IP(下期再说)
【树莓派 RaspberryPi 终端命令行配置无线网络连接wifi】
打完收工!我们下期见!



    推荐阅读