Raspberry pi wifi热点续
2015-09-13 05:18
585 查看
上一篇介绍了用raspbery pi做wifi热点。但是如果我把raspberry pi做成wifi热点的话无法让raspberry pi无线连接到家里的wifi连接internet了。所以为了让raspberry pi既可以作为wifi热点,也可以在平时连接家里的wifi连接internet,我这里介绍一个我认为比较好用的办法。
思路是用shell脚本,更改一下raspberry pi的网络设定,执行脚本可以更换wifi AP模式和wifi client模式。
首先需要配置/etc/networks/interface文件,
第一个是为普通wifi client模式使用的。
pi@raspberrypi ~ $ cat /etc/network/interfaces.net auto loiface lo inet loopback
auto eth0allow-hotplug eth0iface eth0 inet manual
auto wlan0allow-hotplug wlan0iface wlan0 inet manualwpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
pi@raspberrypi ~ $ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdevupdate_config=1
network={ ssid="SSID" psk="PASSWORD" key_mgmt=WPA-PSK}
再保存一份作为wifi AP模式的配置文件使用
pi@raspberrypi ~ $ cat /etc/network/interfaces.apauto loiface lo inet loopback
auto eth0allow-hotplug eth0iface eth0 inet manual
#auto wlan0#allow-hotplug wlan0#iface wlan0 inet manual#wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
#auto wlan1#allow-hotplug wlan1#iface wlan1 inet manual#wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
allow-hotplug wlan0iface wlan0 inet static address 192.168.20.1 netmask 255.255.255.0
#up iptables-restore < /etc/network/iptables分别做成两个脚本文件,可以执行脚本更换模式:
转换成wifi client模式
pi@raspberrypi ~ $ cat ./net.sh #!/bin/sh#net.shsudo cp /etc/network/interfaces.net /etc/network/interfacessudo /etc/init.d/networking restartecho "network mode set"
转换成wifi AP模式
pi@raspberrypi ~ $ cat ./ap.sh #!/bin/bash#ap.shsudo cp /etc/network/interfaces.ap /etc/network/interfacessudo /etc/init.d/networking restartecho "set to ap mode"在/etc/rc.local文件最后一行exit 0之前加上一行,使之默认启动为AP模式,这样在外面没有显示器的地方也可以通过手机或者电脑登陆raspberry pi实时更换模式了。
#!/bin/sh -e## rc.local## This script is executed at the end of each multiuser runlevel.# Make sure that the script will "exit 0" on success or any other# value on error.## In order to enable or disable this script just change the execution# bits.## By default this script does nothing.
# Print the IP address_IP=$(hostname -I) || trueif [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP"fisudo service hostapd startsudo cp /etc/network/interfaces.ap /etc/network/interfacessh /home/pi/nat.shexit 0
这样,raspberry pi启动的时候就是AP模式,在家里可以用脚本转换为普通wifi client模式。
思路是用shell脚本,更改一下raspberry pi的网络设定,执行脚本可以更换wifi AP模式和wifi client模式。
首先需要配置/etc/networks/interface文件,
第一个是为普通wifi client模式使用的。
pi@raspberrypi ~ $ cat /etc/network/interfaces.net auto loiface lo inet loopback
auto eth0allow-hotplug eth0iface eth0 inet manual
auto wlan0allow-hotplug wlan0iface wlan0 inet manualwpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
pi@raspberrypi ~ $ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdevupdate_config=1
network={ ssid="SSID" psk="PASSWORD" key_mgmt=WPA-PSK}
再保存一份作为wifi AP模式的配置文件使用
pi@raspberrypi ~ $ cat /etc/network/interfaces.apauto loiface lo inet loopback
auto eth0allow-hotplug eth0iface eth0 inet manual
#auto wlan0#allow-hotplug wlan0#iface wlan0 inet manual#wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
#auto wlan1#allow-hotplug wlan1#iface wlan1 inet manual#wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
allow-hotplug wlan0iface wlan0 inet static address 192.168.20.1 netmask 255.255.255.0
#up iptables-restore < /etc/network/iptables分别做成两个脚本文件,可以执行脚本更换模式:
转换成wifi client模式
pi@raspberrypi ~ $ cat ./net.sh #!/bin/sh#net.shsudo cp /etc/network/interfaces.net /etc/network/interfacessudo /etc/init.d/networking restartecho "network mode set"
转换成wifi AP模式
pi@raspberrypi ~ $ cat ./ap.sh #!/bin/bash#ap.shsudo cp /etc/network/interfaces.ap /etc/network/interfacessudo /etc/init.d/networking restartecho "set to ap mode"在/etc/rc.local文件最后一行exit 0之前加上一行,使之默认启动为AP模式,这样在外面没有显示器的地方也可以通过手机或者电脑登陆raspberry pi实时更换模式了。
#!/bin/sh -e## rc.local## This script is executed at the end of each multiuser runlevel.# Make sure that the script will "exit 0" on success or any other# value on error.## In order to enable or disable this script just change the execution# bits.## By default this script does nothing.
# Print the IP address_IP=$(hostname -I) || trueif [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP"fisudo service hostapd startsudo cp /etc/network/interfaces.ap /etc/network/interfacessh /home/pi/nat.shexit 0
这样,raspberry pi启动的时候就是AP模式,在家里可以用脚本转换为普通wifi client模式。
相关文章推荐
- ASP.NET State Server 服务 sessionState
- 关于Metasploit-学习笔记-基础命令以及参数
- Metasploit CVE-2015-5122 Flash漏洞利用检测试验
- ASP.NET MVC 快速开发框架之 SqlSugar+SyntacticSugar+JQWidgetsSugar+jqwidgets(转)
- asp.net页面之间的传值
- asp.net中GridView数据鼠标移入显示提示信息
- ASP连接数据库大全
- asp.net 奇淫技巧
- asp.net缓存使用介绍
- metasploit
- 采用Fiddler建立Asp.net webapi与Android/IOS调试环境
- IIS7配置ASP+Access使用环境
- ASP.NET中的几种弹出框提示基本实现方法
- Asp.net 三种事务处理
- ASP 生成缩略图
- ASP.NET验证控件详解
- Asp.net固定功能位充满了零(解决,演示样本)!
- ASP.NET 协同办公系统
- 非对称认证方式 可以用在 asp.net webapi 的安全机制里面
- asp.net mvc 页面传值的方法总结