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

Posted 闭关苦炼内功

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了树莓派 RaspberryPi 终端命令行配置无线网络连接wifi相关的知识,希望对你有一定的参考价值。

root@raspberrypi:~# ifconfig wlan0 up
root@raspberrypi:~#

root@raspberrypi:~# iwlist wlan0 scan
wlan0     Scan completed :
          Cell 01 - Address: 68:A0:3E:5C:CA:70
                    Channel:1
                    Frequency:2.412 GHz (Channel 1)
                    Quality=39/70  Signal 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=CN

network={
        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:a1  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

root@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=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=CN

network={
        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.229  netmask 255.255.0.0  broadcast 169.254.255.255
        inet6 fe80::e65f:1ff:fe00:3ba0  prefixlen 64  scopeid 0x20<link>
        ether e4:5f:01:00:3b:a0  txqueuelen 1000  (Ethernet)
        RX packets 1841  bytes 150781 (147.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1483  bytes 179352 (175.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 5938  bytes 341948 (333.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5938  bytes 341948 (333.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet6 fe80::e65f:1ff:fe00:3ba1  prefixlen 64  scopeid 0x20<link>
        ether e4:5f:01:00:3b:a1  txqueuelen 1000  (Ethernet)
        RX packets 1  bytes 46 (46.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 75  bytes 14475 (14.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

root@raspberrypi:~#

root@raspberrypi:~# reboot

重启后重新连接

Linux raspberrypi 5.4.83-v7l+ #1379 SMP Mon Dec 14 13:11:54 GMT 2020 armv7l

The 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.229  netmask 255.255.0.0  broadcast 169.254.255.255
        inet6 fe80::e65f:1ff:fe00:3ba0  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::3fa1:9571:af73:8712  prefixlen 64  scopeid 0x20<link>
        ether e4:5f:01:00:3b:a0  txqueuelen 1000  (Ethernet)
        RX packets 168  bytes 18457 (18.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 125  bytes 21969 (21.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 86  bytes 8628 (8.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 86  bytes 8628 (8.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.190  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::e65f:1ff:fe00:3ba1  prefixlen 64  scopeid 0x20<link>
        ether e4:5f:01:00:3b:a1  txqueuelen 1000  (Ethernet)
        RX packets 37  bytes 2926 (2.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 80  bytes 14266 (13.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

root@raspberrypi:~#

其实到这里还没完,应该手动再配置一波,搞成静态IP(下期再说)


参考这篇
https://www.cnblogs.com/shubin/p/7746399.html

打完收工!我们下期见!

2:11了,得赶紧睡了,明天要早起去上班!

以上是关于树莓派 RaspberryPi 终端命令行配置无线网络连接wifi的主要内容,如果未能解决你的问题,请参考以下文章

树莓派命令行配置无线网络

树莓派命令行配置无线网络

树莓派3代-命令行配置wifi无线连接

树莓派配置wifi地址

树莓派3 命令行配置无线

(17)树莓派配置成路由器