博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
树莓派开机自动发射热点
阅读量:7105 次
发布时间:2019-06-28

本文共 3533 字,大约阅读时间需要 11 分钟。

  hot3.png

由于我的是树莓派3, 自带wifi网卡,然后又加了一个usb网卡

现在分配的是, 如果检测到usb无线网卡插入,那么就使用usb无线网卡发射热点

如果eth0或者wlan0任何一个有网的情况下, 做路由转发,使热点能连上网

安装依赖

sudo apt install hostapd dnsmasq

配置hostapd

#/etc/hostapd/hostapd.conf# Basic configuration    interface=wlan1ssid=TestWifiAPchannel=1#bridge=br0# WPA and WPA2 configuratiomacaddr_acl=0auth_algs=1ignore_broadcast_ssid=0wpa=3wpa_passphrase=12345678wpa_key_mgmt=WPA-PSKwpa_pairwise=TKIPrsn_pairwise=CCMP# Hardware configurationdriver=nl80211#driver=rtl871xdrv#ieee80211n=1hw_mode=g#device_name=RTL8192CU#manufacturer=Realtek

配置dnsmasq

# /etc/dnsmasq.conf#interface=wlan1bind-interfacesserver=114.114.114.114server=8.8.8.8domain-neededbogus-privdhcp-range=10.10.10.10,10.10.10.100,12h

配置interfaces

# /etc/network/interfacesauto loiface lo inet loopbackauto wlan0allow-hotplug wlan0iface wlan0 inet manualwpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

如果网卡分配有问题,请配置70-persistent-net.rules文件, mac地址记得改掉

# /etc/udev/rules.d/70-persistent-net.rulesSUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="xx:00:00:00:00:00", KERNEL=="eth*", NAME="eth0"SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="xx:00:00:00:00:00", KERNEL=="wlan*", NAME="wlan0"SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="xx:00:00:00:00:00", KERNEL=="wlan*", NAME="wlan1"

发射热点脚本/usr/local/bin/wifi-ap

#!/bin/bash#===============================================================================##          FILE: wifi-ap# #         USAGE: ./wifi-ap # #   DESCRIPTION: # #       OPTIONS: ---#  REQUIREMENTS: ---#          BUGS: ---#         NOTES: ---#        AUTHOR: Yehun (), yehunhk@163.com#  ORGANIZATION: Yehun#       CREATED: 03/04/2018 01:53:05 AM#      REVISION:  ---#===============================================================================ETH0="eth0"WLAN0="wlan0"WLAN1="wlan1"if ifconfig | grep $WLAN1 > /dev/null ;then    ifconfig $WLAN1 down    ifconfig $WLAN1 10.10.10.1 netmask 255.255.255.0 up    #iwconfig $WLAN1 power off    hostapd -B /etc/hostapd/hostapd.conf    #service hostapd start    if ifconfig | grep $WLAN0 > /dev/null ;then        if [ "down" == `cat /sys/class/net/$WLAN0/operstate` ]; then            wpa_supplicant -B -i $WLAN0 -c /etc/wpa_supplicant/wpa_supplicant.conf        fi        if [ "up" == `cat /sys/class/net/$WLAN0/operstate` ]; then            echo "start setting wlan0 iptables"            sh -c "echo 1 >/proc/sys/net/ipv4/ip_forward"            iptables -t nat -APOSTROUTING -o $WLAN0 -j MASQUERADE            iptables -A FORWARD -i $WLAN0 -o $WLAN1 -m state --state RELATED,ESTABLISHED -j ACCEPT            iptables -A FORWARD -i $WLAN1 -o $WLAN0 -j ACCEPT        elif [ "up" == `cat /sys/class/net/$ETH0/operstate` ]; then            echo "start setting eth0 iptables"            sh -c "echo 1 >/proc/sys/net/ipv4/ip_forward"            iptables -t nat -APOSTROUTING -o $ETH0 -j MASQUERADE            iptables -A FORWARD -i $ETH0 -o $WLAN1 -m state --state RELATED,ESTABLISHED -j ACCEPT            iptables -A FORWARD -i $WLAN1 -o $ETH0 -j ACCEPT        fi    fifi

把wifi-ap加入rc.local开机启动

#!/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"fi/usr/local/bin/wifi-apexit 0

 

转载于:https://my.oschina.net/yehun/blog/1633488

你可能感兴趣的文章
silverlight 不能输入中文问题
查看>>
Vue自带的过滤器
查看>>
微软职位内部推荐-SDEII
查看>>
CocoaPods 安装的第三方删除
查看>>
jsonk可以传递boolean
查看>>
编程常见命名规范
查看>>
windows7系统配置maven环境
查看>>
浅谈第三方电子支付平台测试方法的研究
查看>>
【DOM编程艺术】滑过高亮显示 highLightRows
查看>>
如何设置静态内容缓存时间
查看>>
iOS开发多线程篇—多线程简单介绍
查看>>
使用PHP QR Code生成二维码
查看>>
日志统计 尺取法【蓝桥杯2018 C/C++ B组】
查看>>
移动web开发规范
查看>>
myeclipse操作记录
查看>>
$http设置headers来实现IE不缓存url请求的资源
查看>>
codeforces 381 D Alyona and a tree(倍增)(前缀数组)
查看>>
ISO7220M芯片调试总结
查看>>
系统中纹波大
查看>>
GPS经纬度转换为百度坐标
查看>>