hostapd) setup WiFi access point with Raspberry-Pi OS
install the required packages
apt install -y hostapd
create the hostapd settings
interface = wlan0 ...
unblock the WiFi interface with rfkill
we need unblocking the WiFi interface before run hostapd. there are several ways to unblock the WiFi interface. I choose the unblock script for 8812au.
there is a sample script to unblock,
save it into /root/unblock-rtl8812au.sh
::
#! /bin/bash find_tgt=/sys/class/net/wlan* find_opt="-q 8812au" function find_8812au_dev() { for i in $find_tgt; do if udevadm info -a --path=$i | grep $find_opt; then udevadm info -a --path=$i | sed -n 's/[ \t]*KERNEL=="\(.*\)"/\1/p' return 0 fi done return 1 } function find_phy_name() { n="$(iw dev $1 info | sed -n 's/[ \t]\+wiphy[ \t]\+\([0-9]\+\)/\1/p')" wiphy="Wiphy phy$n" iw list | grep -e '^\S' | while read l; do #cho "$l - $n - $wiphy" if [[ "$l" = $wiphy ]]; then echo "phy$n" return 0 fi done return 1 } function find_rfkill_id() { tmp=$(rfkill list | grep $1 | cut -d " " -f 1) echo ${tmp%%:} } function unblock() { sleep 10 dev=$(find_8812au_dev) echo "got device: $dev" phy=$(find_phy_name $dev) echo "got phy: $phy" id=$(find_rfkill_id $phy) rfkill unblock $id } unblock
modify the systemd settings
to enable the unblock interface, I use the systemd service settings ExecStartPre
.
edit the hostapd.conf
directly,
copy to the new service,
or make the override settings by systemctl edit hostapd.service
.
[Service] ... ExecStartPre=/root/unblock-rtl8812au.sh
start and check the service
after modify the settings for systemd, run and confirm the access point service.
systemctl daemon-reload systemctl start hostapd systemctl status hostapd
then enable the service:
systemctl enable hostapd