树莓派无线配置,之前有写过,但是总有人搞不清楚,现在我再把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.dauto loiface lo inet loopbackiface eth0 inet manualallow-hotplug wlan0iface wlan0 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.confallow-hotplug wlan1iface 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.dauto loiface lo inet loopbackiface eth0 inet manual#allow-hotplug wlan0#iface wlan0 inet manual# wpa-conf /etc/wpa_supplicant/wpa_supplicant.confauto wlan0 allow-hotplug wlan0 iface wlan0 inet dhcp wpa-ssid "Wingspan-Working" wpa-psk "wingspan" allow-hotplug wlan1iface 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.dauto loiface lo inet loopbackiface eth0 inet manual#allow-hotplug wlan0#iface wlan0 inet manual# wpa-conf /etc/wpa_supplicant/wpa_supplicant.confauto wlan0allow-hotplug wlan0iface wlan0 inet static wpa-ssid "Wingspan-Working" wpa-psk "wingspan" address 192.168.11.80 netmask 255.255.255.0 gateway 192.168.11.1allow-hotplug wlan1iface 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 loauto lo wlan0 wlan1iface lo inet loopbackiface eth0 inet dhcpauto wlan0allow-hotplug wlan0iface wlan0 inet dhcpwpa-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 wlan1iface wlan1 inet manual# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
文件2:
/etc/wpa_supplicant/wpa_supplicant.conf
country=GBctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdevupdate_config=1network={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:"mac\xE7\x9A\x84MacBook Pro"
当然,配置的时候,如果有疑问,也可以参考其他的配置文档:
玩转树莓派-Raspberry,无线网配置方法:
树莓派连接WiFi:
树莓派连接WiFi(最稳定的方法):
树莓派 Raspberry Pi 设置无线上网:
---------------补充--------------
树莓派配置无线静态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.confaddress 192.168.21.181netmask 255.255.255.0gateway 192.168.21.1dns-nameservers 61.134.1.4
则需要两个配置文件,分别如下:
/etc/network/interfaces:
auto loiface lo inet loopbackiface eth0 inet manual#pre-up ifconfig eth0 hw ether 00:9a:9b:96:6a:7cauto eth2iface eth2 inet manualauto wlan0allow-hotplug wlan0iface wlan0 inet static wpa-conf /etc/wpa_supplicant/wpa_supplicant.confaddress 192.168.21.181netmask 255.255.255.0gateway 192.168.21.1dns-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.confallow-hotplug wlan1iface wlan1 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
/etc/wpa_supplicant/wpa_supplicant.conf:
country=GBctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdevupdate_config=1network={ ssid="WingSpan-Guest" psk="wingspanwifi"}network={ ssid="tozed-1CA8D5" psk="691065DA"}
修改之后保存退出,然后重启网络:
sudo /etc/init.d/networking restart
即可见结果为静态IP:
待续。。。