zoukankan      html  css  js  c++  java
  • 树莓派Raspberry命令行配置无线网络连接

    前言:

    树莓派有多种联网的方式,通过有线网或者通过无线网。通过有线网连接是比较简单的,在开启dhcp的路由器下,直接插上网线就可以联网,本文介绍树莓派无线联网的方式。再没联网的情况下,如果没有屏幕等外设,通过串口连接是一种比较简单有效的方式。

    扫描WIFI:

    使用如下命令可以扫描附近的无线网:

    sudo iwlist wlan0 scan

    扫描结果如下:

    wlan0     Scan completed :
              Cell 01 - Address: F0:B4:29:1F:28:F1
                        ESSID:"00H Studio"
                        Protocol:IEEE 802.11bgn
                        Mode:Master
                        Frequency:2.422 GHz (Channel 3)
                        Encryption key:on
                        Bit Rates:300 Mb/s
                        Extra:rsn_ie=30140100000fac040100000fac040100000fac020000
                        IE: IEEE 802.11i/WPA2 Version 1
                            Group Cipher : CCMP
                            Pairwise Ciphers (1) : CCMP
                            Authentication Suites (1) : PSK
                        Quality=100/100  Signal level=84/100  
              Cell 02 - Address: 06:74:9C:08:3F:7C
                        ESSID:"QLU-2.4G"
                        Protocol:IEEE 802.11bgn
                        Mode:Master
                        Frequency:2.412 GHz (Channel 1)
                        Encryption key:off
                        Bit Rates:144 Mb/s
                        Quality=100/100  Signal level=72/100  
              Cell 03 - Address: D6:50:3F:0B:81:D1
                        ESSID:"7788"
                        Protocol:IEEE 802.11bgn
                        Mode:Master
                        Frequency:2.422 GHz (Channel 3)
                        Encryption key:on
                        Bit Rates:72 Mb/s
                        Extra:rsn_ie=30140100000fac040100000fac040100000fac020c00
                        IE: IEEE 802.11i/WPA2 Version 1
                            Group Cipher : CCMP
                            Pairwise Ciphers (1) : CCMP
                            Authentication Suites (1) : PSK
                        IE: Unknown: DD180050F204104A00011010440001021049000600372A000120
                        Quality=44/100  Signal level=62/100  

    这里的“00H Studio”是无线网的名称。IEEE 802.11i/WPA2 Version 1是加密的方式。加密的类型是WPA2类型的。

    添加有密码的WIFI网络

    通过配置wpa_supplicant.conf可以设置要连接的无线网。

    sudo vim /etc/wpa_supplicant/wpa_supplicant.conf

    在文件末尾出添加一下代码,并替换掉ssid_name以及password即可。

    network={
            ssid="ssid_name"
            key_mgmt=WPA-PSK
            psk="password"
    }

    通过

    ifconfig wlan0

    可以查看IP地址是否分配成功

    wlan0     Link encap:Ethernet  HWaddr e8:4e:06:34:f8:f5  
              inet addr:192.168.9.177  Bcast:192.168.9.255  Mask:255.255.255.0
              inet6 addr: fdf5:a28:b70c:0:746:52db:d822:14bd/64 Scope:Global
              inet6 addr: fdf5:a28:b70c::6c5/128 Scope:Global
              inet6 addr: fe80::ea4e:6ff:fe34:f8f5/64 Scope:Link
              inet6 addr: fdf5:a28:b70c:0:ea4e:6ff:fe34:f8f5/64 Scope:Global
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:100930 errors:0 dropped:36149 overruns:0 frame:0
              TX packets:290150 errors:0 dropped:2 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:146598855 (139.8 MiB)  TX bytes:3218776758 (2.9 GiB)

    连接隐藏网络

    如果要连接的是隐藏的网络,需要在配置文件中添加scan_ssid连接。需要添加的内容如下:

    network={
        ssid="yourHiddenSSID"
        scan_ssid=1
        psk="Your_wifi_password"
    }

    添加多个无线网络配置

    network={
        ssid="SchoolNetworkSSID"
        psk="passwordSchool"
        id_str="school"
    }
    
    network={
        ssid="HomeNetworkSSID"
        psk="passwordHome"
        id_str="home"
    }

    如果您有两个网络的范围,可以添加优先级选项来在它们之间进行选择。具有最高优先级的范围内的网络将是连接的网络。

    network={
        ssid="HomeOneSSID"
        psk="passwordOne"
        priority=1
        id_str="homeOne"
    }
    
    network={
        ssid="HomeTwoSSID"
        psk="passwordTwo"
        priority=2
        id_str="homeTwo"
    }

    添加没有密码的WIFI网络

    添加没有密码的WIFI网络需要注意将key_mgmt设置为NONE

    network={
            ssid="ssid_name"
            key_mgmt=NONE
    }

    IP的设置

    auto wlan0
    iface wlan0 inet static
       address 192.168.0.1
       netmask 255.255.255.0
      wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

    错误的调试

    如果出现连接不成功的情况,有很大的可能是由于配置文件配置错误的原因。

    sudo wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf  -i wlan0

    通过wpa_supplicant的直接连接,如果配置文件出现问题,则会直接提示配置文件的错误详情。

    如果出现一下结果,则一般代表配置文件没有问题

    Successfully initialized wpa_supplicant
    nl80211: Driver does not support authentication/association or connect commands
    wlan0: Failed to initialize driver interface
  • 相关阅读:
    Educational Codeforces Round 72 (Rated for Div. 2)
    2249: Altruistic Amphibians 01背包
    lh的简单图论
    E. XOR Guessing 交互题 Educational Codeforces Round 71 (Rated for Div. 2)
    C. Helga Hufflepuff's Cup 树形dp 难
    B. Marvolo Gaunt's Ring 前缀后缀
    android学习-IPC机制之ACtivity绑定Service通信
    大数组分时加载算法 timedChunk
    log4j 配置和使用
    fastjson 配置和使用
  • 原文地址:https://www.cnblogs.com/shubin/p/7746399.html
Copyright © 2011-2022 走看看