树莓派一键变身无线路由器

最后

1----PI可以ping 百度

2---可以PC接入公司WIFI(PI也是的)使用PUTTY 

3--可以PC接入PI发出的WIFI 然后PUTTY

4--PI

操作完成以后

1---需要如下文件 放在如下位置

 cp /home/pi/hostapd.ini /etc/raspap/hostapd.ini

LogEnable = 1
WifiAPEnable = 1
BridgedEnable = 0
WifiManaged = wlan0

看上去上面的意义不大 它只是手机PC进到WEB的时候 看到按键的状态

2--cat /etc/hostapd/hostapd.conf
cp /home/pi/hostapd.conf /etc/hostapd/hostapd.conf

driver=nl80211
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
beacon_int=100
auth_algs=1
wpa_key_mgmt=WPA-PSK
ssid=raspi-webgui
channel=1
hw_mode=g
wpa_passphrase=ChangeMe
interface=uap0
wpa=2
wpa_pairwise=CCMP
country_code=
## Rapberry Pi 3 specific to on board WLAN/WiFi
#ieee80211n=1 # 802.11n support (Raspberry Pi 3)
#wmm_enabled=1 # QoS support (Raspberry Pi 3)
#ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] # (Raspberry Pi 3)

## RaspAP wireless client AP mode
#interface=uap0

## RaspAP bridge AP mode (disabled by default)
#bridge=br0

只是修改interface放弃wlan0  修改为uap0  

因为原来的默认计划是ETH0来入网 WLAN0来做路由器的  

现在我们是WLAN0来入网 虚拟一个uap0来做路由

3-- cat /etc/dhcpcd.conf
cp /home/pi/dhcpcd.conf  /etc/dhcpcd.conf

# RaspAP default configuration
hostname
clientid
persistent
option rapid_commit
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
option ntp_servers
require dhcp_server_identifier
slaac private
nohook lookup-hostname

# RaspAP wlan0 configuration
interface uap0
static ip_address=192.168.50.1/24
nohook wpa_supplicant

只是最后 把wlan0的设置下架 我自己做的的uap0  注意这里我范围是自己写的 源码那个也可以的

4--把网卡加上去

iw dev wlan0 interface add uap0 type __ap
ifconfig uap0 up

主要是前面的文件修改以后 会把系统毁掉 下面的指令会error 加上上面命令以后好了

【第一次装了以后 最后直接reoot的 无法拯救的 因为下面的指令已经不能用了 被raspad接管了

执行到SSD断开 就复位 继续做下去】

 systemctl status hostapd.service  
 systemctl restart hostapd.service  
 systemctl restart raspapd.service
 systemctl status raspapd.service

5---修改最后一个文件  cat /etc/dnsmasq.conf

 cp /home/pi/dnsmasq.conf /etc/dnsmasq.conf
 

这个文件 里面全部是注释 不要管 在最后追加
 

interface=lo,uap0
bind-interfaces
domain-needed
bogus-priv


 

关键指令 看到下面的 其实有问题!!报错了!!

systemctl status dnsmasq.service

systemctl restart dnsmasq.service

此时看到手机能看到WIFI 但是就是接不进去!就是上面的问题

因为这个git项目 接管了系统的配置

从这里看出端倪


这个文件 cat /etc/dnsmasq.d/090_wlan0.conf

 sudo cp /home/pi/090_wlan0.conf /etc/dnsmasq.d/090_wlan0.conf

以前是wlan0 我全部修改

# RaspAP wlan0 configuration for wired (ethernet) AP mode
interface=uap0
domain-needed
dhcp-range=192.168.50.2,192.168.50.255,255.255.255.0,12h

此时手机可以接入了  一切正常

最后效果 看文章开头

复位

回到最初了 见鬼

  172  reboot
  173  iw dev wlan0 interface add uap0 type __ap
  174  ifconfig uap0 up
  181  systemctl restart dnsmasq.servic

好了

再看开机的LOG 启动服务走到后面是我们自己的问题

怎么看?root@raspberrypi:/home/pi# cat /etc/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) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

exit 0

这里没有问题 那是怎么做到开机启动的呢?

树莓派程序开机自启动方法总结_大存的博客-CSDN博客_树莓派开机自启动程序

 看上文

也就是 我只知道第一种办法  它可能是办法2  放在文件夹

 我现在的主义 是 在开机的时候 就把UAP0加上去

自己测试一次


root@raspberrypi:/home/pi# cat testboot.sh

#!/bin/sh

touch /home/pi/testboot.txt

chmod 777 /home/pi/testboot.txt

echo "hello pi~" >> /home/pi/testboot.txt

echo "KOSON WORING"


./ testboot.sh   OK

采用方法一:向rc.local文件添加启动代码

修改rc.local文件,在终端输入并回车:

pi@raspberry:~ $ sudo nano /etc/rc.local

在打开的文本中找到exit 0,在此之前添加的代码在启动时都会被执行,在exit 0 之前添加一行代码:

su pi -c "exec /home/pi/testboot.sh"   ---这是切换到PI用户下去执行 本来开机是ROOT的

reboot 看到txt修改 有LOG显示 



root@raspberrypi:/home/pi# cat testboot.sh

#!/bin/sh
iw dev wlan0 interface add uap0 type __ap
ifconfig uap0 up
systemctl restart dnsmasq
echo "KOSON ADDED UAP0"


重启看到LOG出来 需要权限 怎么办

也就是开机 跑一个脚本 这个脚本是需要root权限的

su root -c "exec /home/pi/testboot.sh"   

目前看好了 

+++++++++++补充早期探索+++++++++++

curl -sL https://install.raspap.com | bash -s -- --yes


sudo passwd root
su
raspi-config
cp sources.list  /etc/apt/sources.list
cp raspi.list /etc/apt/sources.list.d/raspi.list
apt-get update
apt-get full-upgrade

网线+UI是WLAN0+桥模式--不能上网  改为eth0 则没有WIFI了 【重启 在安装一次 比较快 因为前面搞过来】最后Y自动重启 因为有网线】

看看默认的效果 
1--PI可以上网 ifconfig有3项目
因为有网线 它发热点 它是10.3.141.1 它在内部做的管理 
2--手机接入可以上网刷抖音的
手机看到路由器是10.3.141.1 IP是10.3.141.230
3--PC接入不可以上网开网页
PC是 10.60.32.31 可以通过中文的方式开管理页面和putty
PC是 10.3.141.182和手机一样正常上网
4--管理界面是wlan0
图a
此时移除网线 reboot
没有网线正常开机启动 
开机以后 手机接入和上面一样 但是不能上网 可以数字访问管理页面
插入网线 自动好了

修改为桥模式试试
1--PI可以上网 ifconfig有4项目
因为有网线 
2--手机接入可以上网刷抖音的
手机看到路由器是10.60.32.1 IP是10.60.32.27
3--PC接入可以上网
PC是 10.60.32.31 可以通过中文的方式开管理页面和putty
4--管理界面只修改一个地方依然是wlan0 因为eth负责上网 wlan0负责路由器呀
图b

此时移除网线 reboot
没有网线异常开机启动 中间卡住 2MIN左右
开机以后彻底失联了 WIFI手机PC无法接入 PUTTY进不来
插入网线 自动好了

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值