树莓派3链接wifi

查看网卡状态

我们可以使用ifconfig命令查看当前的网卡状态信息。

root@raspberrypi:~# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.31.159  netmask 255.255.255.0  broadcast 192.168.31.255
        inet6 fe80::a579:e25:d60e:838a  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:08:b2:02  txqueuelen 1000  (Ethernet)
        RX packets 42954  bytes 2101217 (2.0 MiB)
        RX errors 0  dropped 27  overruns 0  frame 0
        TX packets 292  bytes 26175 (25.5 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 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=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b8:27:eb:5d:e7:57  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

其中eth0为有线网卡,lo代表127.0.0.1即localhost,wlan0代表无线网卡。

下表对参数做一下简单解释

<>

UP 网卡已启用

BROADCAST 广播

LOOPBACK 本地访问

RUNNING 网卡正在运行

MULTICAST 多路广播

mtu MTU(Maximum Transmission Unit)最大传输单元
inet IPV4地址
netmask 网络掩码
broadcast 广播地址
inet6 IPV6地址
prefixlen 前缀长度
ether 网卡地址(MAC)
txqueuelen 传输缓区长度大小意思
RX packets bytes 接收{数据包数量 数据包大小}
RX errors dropped overruns frame 接收{错误数 丢包数 溢出数 框架}
TX packets bytes 发送{数据包数量 数据包大小}
TX errors  dropped overruns  carrier  collisions 发送{错误数 丢包数 溢出数 载体 冲突}

查看无线连接状态

ESSID参数为off显然还没有链接无线网络

root@raspberrypi:~# iwconfig
wlan0     IEEE 802.11  ESSID:off/any  
          Mode:Managed  Access Point: Not-Associated   Tx-Power=31 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:on
          
lo        no wireless extensions.

eth0      no wireless extensions.

查找无线网络

列出能够搜索到的全部无线网络

root@raspberrypi:~# iwlist wlan0 scan    
wlan0     Scan completed :
          Cell 01 - Address: A8:57:4E:86:7B:7E
                    Channel:1
                    Frequency:2.412 GHz (Channel 1)
                    Quality=43/70  Signal level=-67 dBm  
                    Encryption key:on
                    ESSID:"TP-LINK_867"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 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: 80ms ago
                    IE: Unknown: 000B54502D4C494E4B5F383637
                    IE: Unknown: 010882848B960C121824
                    IE: Unknown: 030101
                    IE: Unknown: 2A0100
                    IE: Unknown: 32043048606C
                    IE: Unknown: 2D1A6E1003FFFF000000000000000000000000000000000000000000
                    IE: Unknown: 3D1601050200000000000000000000000000000000000000
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: WPA Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: Unknown: DD180050F2020101000003A4000027A4000042435E0062322F00
                    IE: Unknown: DD05000AEB0100
                    IE: Unknown: DD8E0050F204104A0001101044000102103B0001031047001000000000000010000000A8574E867B7E1021000754502D4C494E4B10230009544C2D57523834324E10240003342E3010420007312E312E312E331054000800060050F204000110110018576972656C657373204E20526F757465722057523834324E100800022288103C0001011049000600372A000120

配置wifi信息

root@raspberrypi:~# vim /etc/wpa_supplicant/wpa_supplicant.conf 

在配置文件中增加无线wifi的配置

...
network={    
    ssid="Xiaomi_F636"
    psk="imlichao"
}   

重启系统

重启系统后我们可以看到无线网卡已经启用并连接到了wifi。

root@raspberrypi:/home/imlichao# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.31.159  netmask 255.255.255.0  broadcast 192.168.31.255
        inet6 fe80::a579:e25:d60e:838a  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:08:b2:02  txqueuelen 1000  (Ethernet)
        RX packets 895  bytes 48460 (47.3 KiB)
        RX errors 0  dropped 1  overruns 0  frame 0
        TX packets 91  bytes 13742 (13.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 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<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.31.134  netmask 255.255.255.0  broadcast 192.168.31.255
        inet6 fe80::36eb:7046:a7fb:ddb3  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:5d:e7:57  txqueuelen 1000  (Ethernet)
        RX packets 69  bytes 8121 (7.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 36  bytes 6014 (5.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
root@raspberrypi:/home/imlichao# iwconfig 
wlan0     IEEE 802.11  ESSID:"Xiaomi_F636"  
          Mode:Managed  Frequency:2.412 GHz  Access Point: 64:09:80:12:F6:37   
          Bit Rate=24 Mb/s   Tx-Power=31 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:on
          Link Quality=55/70  Signal level=-55 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

lo        no wireless extensions.

eth0      no wireless extensions.

猜你喜欢

转载自my.oschina.net/u/3452433/blog/1814037