Soft AP 利用支援 AP 模式的無線網卡,透過 hostapd + dnsmasq 實現熱點分享,成本低、無需額外硬體。本文詳細說明驗證網卡支援、安裝配置 hostapd/dnsmasq、啟動服務、驗證連線的完整流程。

$ iw list | grep -A 10 "Supported interface modes"
* AP
* AP/VLAN
* monitor
...
輸出含 AP 即支援。若無,需更換網卡或驅動(如 ath9k、rtl8812au)。
$ sudo apt-get install hostapd
編輯 /etc/hostapd/hostapd.conf:
interface=wlan0
driver=nl80211
ssid=MySoftAP
hw_mode=g
channel=6
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=StrongPassword123
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
指定配置檔:/etc/default/hostapd 設 DAEMON_CONF="/etc/hostapd/hostapd.conf"。
$ sudo apt-get install dnsmasq
備份原配置,編輯 /etc/dnsmasq.conf:
interface=wlan0
dhcp-range=192.168.10.10,192.168.10.100,12h
dhcp-option=3,192.168.10.1 # Gateway
dhcp-option=6,8.8.8.8,1.1.1.1 # DNS
# /etc/network/interfaces 或 Netplan
auto wlan0
iface wlan0 inet static
address 192.168.10.1
netmask 255.255.255.0
# 啟用 IP 轉發
$ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
$ sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
$ sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
$ sudo systemctl unmask hostapd
$ sudo systemctl enable --now hostapd dnsmasq
$ sudo systemctl status hostapd dnsmasq



MySoftAP 連線,取得 IP、上網正常。journalctl -u hostapd -f 觀察連線日誌。iw dev wlan0 station dump 查看關聯站點。iw dev wlan0 scan | grep channel 選擇乾淨頻道。resolv.conf、dnsmasq 日誌、防火牆 UDP 53。四步驟打造專屬 Wi-Fi 熱點,適合實驗室、會議室、嵌入式裝置測試等場景。