Turn a Linux machine's WiFi card into a hotspot while it's still connected to the same WiFi network — concurrent STA + AP mode on a single wireless adapter, using hostapd + dnsmasq + iptables.
Requires a WiFi chipset/driver that supports the managed + AP interface combination (check with iw phy phy0 info | grep -A5 "valid interface combinations"). Most modern Intel, Atheros, and Realtek chips support this. Some older Broadcom chips do not.
- Linux with root access
- A WiFi adapter / internal wifi adapter already connected to a network
- Python 3
hostapd,dnsmasq,iw,iptables(auto-installed by the script if missing)
git clone https://github.com/warsecurity/linuxhotspot.git
cd linuxhotspotNo build step. Run directly with sudo python3 wifi.py.
sudo python3 wifi.py --startFirst run asks for:
- SSID
- password (8+ characters, WPA2)
- upstream WiFi interface name (defaults to
wlan0)
These are saved to /etc/wifi-hotspot/hotspot.conf. Edit that file directly to change them later, then run --start again.
Stop the hotspot:
sudo python3 wifi.py --stopThis kills hostapd/dnsmasq, removes the iptables rules, and deletes the virtual ap0 interface. It does not uninstall packages or delete your saved config — --start again picks up where you left off.
Check status:
sudo python3 wifi.py --statusHelp:
python3 wifi.py --help- Checks for
hostapd,dnsmasq,iw,iptables; installs anything missing via the system package manager (apt/dnf/yum/pacman/zypper). - Reads or creates
/etc/wifi-hotspot/hotspot.conf. - Detects the WiFi channel your upstream interface is currently on and matches the AP to it — required for concurrent STA+AP to work on one radio.
- Creates a virtual AP interface (
ap0) off your upstream interface. - Writes
hostapdanddnsmasqconfigs. - Starts
hostapd(backgrounded) anddnsmasq. - Opens the needed UFW ports on
ap0if UFW is active, and addsiptablesMASQUERADE/FORWARD rules so hotspot clients route out through your upstream connection.
A single WiFi radio splits airtime between its STA role (talking to your real network) and its AP role (serving hotspot clients). This is not a bug in the script — it's a hardware/driver constraint. Expect noticeably better and more consistent throughput on the hotspot side if you use a second physical WiFi adapter dedicated to the AP role instead of sharing one radio.
ap0 doesn't come up as type AP — your driver likely doesn't support concurrent STA+AP. Check iw phy phy0 info as described above.
hostapd fails with "Failed to set beacon parameters" — almost always a channel mismatch between the AP config and whatever channel your upstream interface is actually on. The script handles this automatically, but if your upstream interface roams to a different channel mid-session, re-run --start.
dnsmasq fails with "Address already in use" — another process (an old manual dnsmasq instance, or a container bridge like lxcbr0) is already bound to the same address/port. --start in the latest version of the script kills anything bound to the hotspot's IP before starting.
Phone connects but shows "sign in to network" / no internet — usually missing NAT rules. Confirm with iptables -t nat -L POSTROUTING -v -n — you should see a MASQUERADE line for your upstream interface. The script adds this automatically; if it's still missing, check that UFW's forwarding policy isn't overriding it.
MIT