如果想实现web控制地无线的话,你可以使用RaspAP 将树莓派轻松部署成无线 AP,它具有一套响应式的 WebUI 来控制 WiFi,可以作为openwrt的替代方案。RaspAP 可以运行在 Raspberry Pi OS (32-bit) 上,这里推荐使用Raspberry Pi OS (32-bit) Lite。
RaspAP的官网地址为:https://raspap.com/,项目地址:https://github.com/billz/raspap-webgui
建议使用全新安装的Raspberry Pi OS (32-bit),然后更新系统
sudo apt-get update
sudo apt-get dist-upgrade
sudo reboot
运行 sudo raspi-config 命令,在设置 Localisation Options 菜单中设置 WiFi 地区。
然后进行快速安装:
官方提供的快速安装命令为:
curl -sL https://install.raspap.com | bash
安装完成之后重启树莓派,无线网卡默认会被配置为热点:
IP 地址: 10.3.141.1
登录用户名: admin
登录密码: secret
DHCP 范围: 10.3.141.50 至 10.3.141.255
SSID: raspi-webgui
WiFi 密码: ChangeMe
但是我在使用一键安装命令时貌似出了一点问题,可能是因为网络问题,所以这里在介绍一下官方提供的手动安装方法(原帖:https://github.com/billz/raspap-webgui/wiki/Manual-installation):
安装所需软件包:
sudo apt-get install lighttpd git hostapd dnsmasq iptables-persistent vnstat qrencode php7.3-cgi
启用lighttpd的php功能:
sudo lighttpd-enable-mod fastcgi-php
sudo service lighttpd force-reload
sudo systemctl restart lighttpd.service
清空网页根目录并克隆文件:
sudo rm -rf /var/www/html
sudo git clone https://github.com/billz/raspap-webgui /var/www/html
为 www-data 用户添加对 sudoers 文件的访问权限:
cd /var/www/html
sudo cp installers/raspap.sudoers /etc/sudoers.d/090_raspap
创建配置目录和配置文件:
sudo mkdir /etc/raspap/
sudo mkdir /etc/raspap/backups
sudo mkdir /etc/raspap/networking
sudo mkdir /etc/raspap/hostapd
sudo mkdir /etc/raspap/lighttpd
cat /etc/dhcpcd.conf | sudo tee -a /etc/raspap/networking/defaults > /dev/null
将 RaspAP 的配置文件移动到正确的位置:
sudo cp raspap.php /etc/raspap
修改网页根目录和配置文件的读写执行权限:
sudo chown -R www-data:www-data /var/www/html
sudo chown -R www-data:www-data /etc/raspap
将 HostAPD 日志和服务控制脚本移动到正确的位置:
sudo mv installers/*log.sh /etc/raspap/hostapd
sudo mv installers/service*.sh /etc/raspap/hostapd
修改日志和服务控制脚本的拥有者和读写执行权限
sudo chown -c root:www-data /etc/raspap/hostapd/*.sh
sudo chmod 750 /etc/raspap/hostapd/*.sh
将控制 RaspAP 的可执行文件移动到正确的位置:
sudo cp installers/configport.sh /etc/raspap/lighttpd
sudo chown -c root:www-data /etc/raspap/lighttpd/*.sh
将控制 RaspAP 的守护程序移动到正确的位置:
sudo mv installers/raspapd.service /lib/systemd/system
sudo systemctl daemon-reload
sudo systemctl enable raspapd.service
复制dhcpcd, dnsmasq, 和 hostapd的配置文件:
sudo mv /etc/default/hostapd ~/default_hostapd.old
sudo cp /etc/hostapd/hostapd.conf ~/hostapd.conf.old
sudo cp config/default_hostapd /etc/default/hostapd
sudo cp config/hostapd.conf /etc/hostapd/hostapd.conf
sudo cp config/dnsmasq.conf /etc/dnsmasq.d/090_raspap.conf
sudo cp config/dhcpcd.conf /etc/dhcpcd.conf
sudo cp config/config.php /var/www/html/includes/
禁用 systemd-networkd
和复制桥接配置:
sudo systemctl stop systemd-networkd
sudo systemctl disable systemd-networkd
sudo cp config/raspap-bridge-br0.netdev /etc/systemd/network/raspap-bridge-br0.netdev
sudo cp config/raspap-br0-member-eth0.network /etc/systemd/network/raspap-br0-member-eth0.network
(可选)将php7.3-cgi替换为你安装的版本:
sudo sed -i -E 's/^session\.cookie_httponly\s*=\s*(0|([O|o]ff)|([F|f]alse)|([N|n]o))\s*$/session.cookie_httponly = 1/' /etc/php/7.3/cgi/php.ini
sudo sed -i -E 's/^;?opcache\.enable\s*=\s*(0|([O|o]ff)|([F|f]alse)|([N|n]o))\s*$/opcache.enable = 1/' /etc/php/7.3/cgi/php.ini
sudo phpenmod opcache
开启ipv4流量转发:
echo "net.ipv4.ip_forward=1" | sudo tee /etc/sysctl.d/90_raspap.conf > /dev/null
sudo sysctl -p /etc/sysctl.d/90_raspap.conf
sudo /etc/init.d/procps restart
创建iptables的NAT规则:
sudo iptables -t nat -A POSTROUTING -j MASQUERADE
sudo iptables -t nat -A POSTROUTING -s 192.168.50.0/24 ! -d 192.168.50.0/24 -j MASQUERADE
sudo iptables-save | sudo tee /etc/iptables/rules.v4
取消标记并启用hostapd.service
sudo systemctl unmask hostapd.service
sudo systemctl enable hostapd.service
到这里RaspAP就手动安装完了,但是官方还提供了一些可选功能;
1,openvpn
#Install OpenVPN, enabling the option in RaspAP's config and enable the openvpn-client service.
sudo apt-get install openvpn
sudo sed -i "s/\('RASPI_OPENVPN_ENABLED', \)false/\1true/g" /var/www/html/includes/config.php
sudo systemctl enable openvpn-client@client
#Create OpenVPN auth control scripts, set ownership and permissions.
sudo mkdir /etc/raspap/openvpn/
sudo cp installers/configauth.sh /etc/raspap/openvpn/
sudo chown -c root:www-data /etc/raspap/openvpn/*.sh
sudo chmod 750 /etc/raspap/openvpn/*.sh
2,Ad blocking
#Install Ad blocking, enabling the option in RaspAP's config.
sudo mkdir /etc/raspap/adblock
wget https://raw.githubusercontent.com/notracking/hosts-blocklists/master/hostnames.txt -O /tmp/hostnames.txt
wget https://raw.githubusercontent.com/notracking/hosts-blocklists/master/domains.txt -O /tmp/domains.txt
sudo cp /tmp/hostnames.txt /etc/raspap/adblock
sudo cp /tmp/domains.txt /etc/raspap/adblock
sudo cp installers/update_blocklist.sh /etc/raspap/adblock/
sudo chown -c root:www-data /etc/raspap/adblock/*.*
sudo chmod 750 /etc/raspap/adblock/*.sh
sudo touch /etc/dnsmasq.d/090_adblock.conf
echo "conf-file=/etc/raspap/adblock/domains.txt" | sudo tee -a /etc/dnsmasq.d/090_adblock.conf > /dev/null
echo "addn-hosts=/etc/raspap/adblock/hostnames.txt" | sudo tee -a /etc/dnsmasq.d/090_adblock.conf > /dev/null
sudo sed -i '/dhcp-option=6/d' /etc/dnsmasq.d/090_raspap.conf
sudo sed -i "s/\('RASPI_ADBLOCK_ENABLED', \)false/\1true/g" includes/config.php
然后重启就行了,你应该可以看到一个名为raspi-webgui的ap。
也可以轻松实现用手机的控制: