- Install hostapd (requires internet connection)
sudo apt install hostapd
- Enable encryption mode for 2.4G hotspot
Enter the following content, using the 11ax wireless standard, encryption method WPA-PSK, ssid as hotspot name, and wpa_passphrase as custom password, all of which can be modified
vi /etc/hostapd.conf
interface=wlan0
driver=nl80211
ctrl_interface_group=0
ctrl_interface=/var/run/hostapd
beacon_int=100
ssid=aic_ax_2.4G
country_code=CN
channel=6
hw_mode=g
ieee80211n=1
ieee80211ac=1
ieee80211ax=1
ht_capab=[HT20][SHORT-GI-20][HT40-][HT40+][SHORT-GI-40]
wmm_enabled=1
he_basic_mcs_nss_set=65534
auth_algs=3
wpa=3
wpa_passphrase=1234567890
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP
vi /etc/dnsmasq.conf
# Only monitor the AP interface
interface=wlan0
bind-interfaces
# DHCP configuration
dhcp-range=192.168.11.2,192.168.11.20,255.255.255.0,24h
dhcp-option=3,192.168.11.1
dhcp-option=6,8.8.8.8,114.114.114.114
resolv-file=/etc/dnsmasq/resolv.conf
- Create /etc/dnsmasq/resol.conf
mkdir -p /etc/dnsmasq
vi /etc/dnsmasq/resolv.conf
Enter the following content
nameserver 8.8.8.8
nameserver 8.8.4.4
- Create script to enable AP mode
vi /usr/bin/start_wifi_ap.sh
Enter the following content
#!/bin/bash
#
## Search for network interfaces starting with wlan
WIFI_IFACE=wlan0
# Configure IP address
ifconfig $WIFI_IFACE 192.168.11.1 up
# Start hostapd
hostapd /etc/hostapd.conf -dd &
# Start dnsmasq
touch /var/lib/misc/udhcp.leases
dnsmasq -i $WIFI_IFACE -C /etc/dnsmasq.conf &
echo "AIC WiFi AP started on interface $WIFI_IFACE"
Modify permissions
chmod a+x /usr/bin/start_wifi_ap.sh
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
- Edit /etc/sysctl.d/10-network-security.conf and add the following line
net.ipv4.ip_forward=1
sudo sysctl -p
- Download Iptables (requires internet connection, can be skipped if installed at the top)
sudo apt update
sudo apt install iptables-persistent
sudo apt install iptables
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
- Afterwards, every time the AP is turned on, it can be started through the startw_ifi_ip.sh script. If you want it to start automatically, please add a service to implement it yourself.
admin@cp2b:~$ sudo start_wifi_ap.sh
[sudo] password for admin:
AIC WiFi AP started on interface wlan0