zoukankan      html  css  js  c++  java
  • 【树莓派】树莓派配置无线网络访问

    树莓派无线配置,之前有写过,但是总有人搞不清楚,现在我再把3份文件保存在这里,供参考;

    下面包含三种配置:

    interfaces  interfaces.wlan0.dhcp  interfaces.wlan0.static

    看其中内容:

    interfaces.default

    # 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
    
    auto lo
    iface lo inet loopback
    
    iface eth0 inet manual
    
    allow-hotplug wlan0
    iface wlan0 inet manual
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    
    allow-hotplug wlan1
    iface wlan1 inet manual
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

      

    interfaces.wlan0.dhcp

    # 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
    
    auto lo
    iface lo inet loopback
    
    iface eth0 inet manual
    
    #allow-hotplug wlan0
    #iface wlan0 inet manual
    #    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    
    auto wlan0  
    allow-hotplug wlan0  
    iface wlan0 inet dhcp  
            wpa-ssid "Wingspan-Working"  
            wpa-psk  "wingspan" 
    
    allow-hotplug wlan1
    iface wlan1 inet manual
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

      

    interfaces.wlan0.static

    # 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
    
    auto lo
    iface lo inet loopback
    
    iface eth0 inet manual
    
    #allow-hotplug wlan0
    #iface wlan0 inet manual
    #    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    
    auto wlan0
    allow-hotplug wlan0
    iface wlan0 inet static
      wpa-ssid "Wingspan-Working"
      wpa-psk "wingspan"
      address 192.168.11.80
      netmask 255.255.255.0
      gateway 192.168.11.1
    
    allow-hotplug wlan1
    iface wlan1 inet manual
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

      

     之前的方式只是一种,而且并不是很稳定,不能配置多个WIfi链接

    下面的方法可以配置多个Wifi连接:

    lifeccp@raspberrypi:~ $ cat /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
    
    #auto lo
    auto lo wlan0 wlan1
    
    iface lo inet loopback
    iface eth0 inet dhcp
    
    auto wlan0
    allow-hotplug wlan0
    
    iface wlan0 inet dhcp
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    
    #wpa-conf /etc/wpa.conf
    #iface default inet dhcp
    #    wpa-ssid "Wingspan-Guest"
    #    wpa-psk "wingspanwifi"
    
    allow-hotplug wlan1
    iface wlan1 inet manual
    #    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

    文件2:

    /etc/wpa_supplicant/wpa_supplicant.conf

    country=GB
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    
    network={
    ssid="test"
    psk="12348765"
    }
    
    network={
    ssid="hao"
    psk="00009999"
    }
    
    network={
    ssid="WingSpan-Guest"
    psk="wingspanwifi"
    }

    搜索附近可用的无线网络:

    lifeccp@raspberrypi:~ $ sudo iwlist wlan0 scan | grep ESSID
    [sudo] password for lifeccp: 
                        ESSID:"HaoChuang-Guest"
                        ESSID:"HaoChuang-dispaly"
                        ESSID:"HaoChuang-Guest"
                        ESSID:"HaoChuang-Guest"
                        ESSID:"macxE7x9Ax84MacBook Pro"

    当然,配置的时候,如果有疑问,也可以参考其他的配置文档:

    玩转树莓派-Raspberry,无线网配置方法:https://my.oschina.net/u/2306127/blog/392442

    树莓派连接WiFi:http://jameszhan.github.io/2015/03/02/raspberry-with-wifi.html

    树莓派连接WiFi(最稳定的方法):https://i.cmgine.net/archives/11053.html

    树莓派 Raspberry Pi 设置无线上网:http://www.jianshu.com/p/b42e8d3df449

    ---------------补充-------------- 

    树莓派配置无线静态IP地址

    修改文件: /etc/network/interfaces,命令如下

    sudo vi /etc/network/interfaces

    注释掉这两行

    #iface wlan0 inet dhcp 
    #    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

    并补充如下信息,(或将最后一句 iface default inet dhcp,替换成):

    iface wlan0 inet static
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    address 192.168.21.181
    netmask 255.255.255.0
    gateway 192.168.21.1
    dns-nameservers 61.134.1.4

     

    则需要两个配置文件,分别如下:

    /etc/network/interfaces:

    auto lo
    iface lo inet loopback
    
    iface eth0 inet manual
    #pre-up ifconfig eth0 hw ether 00:9a:9b:96:6a:7c
    
    auto eth2
    iface eth2 inet manual
    
    auto wlan0
    allow-hotplug wlan0
    
    iface wlan0 inet static
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    address 192.168.21.181
    netmask 255.255.255.0
    gateway 192.168.21.1
    dns-nameservers 61.134.1.4
    
    #iface wlan0 inet dhcp 
    #    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    
    #allow-hotplug wlan0
    #iface wlan0 inet manual
    #    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    
    allow-hotplug wlan1
    iface wlan1 inet manual
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    /etc/wpa_supplicant/wpa_supplicant.conf:
    country=GB
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    
    
    network={
     ssid="WingSpan-Guest"
     psk="wingspanwifi"
    }
    
    network={
      ssid="tozed-1CA8D5"
      psk="691065DA"
    }

     修改之后保存退出,然后重启网络:

    sudo /etc/init.d/networking restart

    即可见结果为静态IP:

    待续。。。

  • 相关阅读:
    HDU 3555 Bomb (数位DP)
    ms sqlserver数据库主文件特别大怎么办
    w3wp.exe占用cpu特别高
    Excel的数据批量替换
    用Excel的分列功能格式化时间
    sql cte的使用
    数据结构
    http与浏览器学习
    长方形裁切优化与矩形物料排料
    架构知识
  • 原文地址:https://www.cnblogs.com/haochuang/p/6228504.html
Copyright © 2011-2022 走看看