Creating a WiFi hotspot on Linux transforms your computer into a wireless access point, perfect for sharing internet or creating a local network. Here’s how to do it using hostapd
(Host Access Point Daemon) and dnsmasq
(DHCP/DNS server).
Prerequisites
- Wireless Adapter: Must support “AP mode” (check with
iw list | grep "AP"
). - Admin Access: Run all commands with
sudo
. - Internet Connection: For sharing via Ethernet (e.g.,
eth0
) or another interface.
Step 1: Install Tools
Open a terminal and install:
sudo apt update && sudo apt install hostapd dnsmasq
Step 2: Configure HostAPD (Access Point)
- Create a config file:
sudo nano /etc/hostapd/hostapd.conf
- Paste this (adjust
ssid
,wpa_passphrase
, andchannel
):interface=wlan0 driver=nl80211 ssid=MyLinuxHotspot hw_mode=g channel=6 wmm_enabled=0 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=SecurePassword123 wpa_key_mgmt=WPA-PSK rsn_pairwise=CCMP
- Replace
wlan0
with your wireless interface (find viaiw dev
).
- Replace
Step 3: Configure DNSMasq (DHCP Server)
- Backup the default config:
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.backup
- Create a new config:
sudo nano /etc/dnsmasq.conf
- Paste:
interface=wlan0 dhcp-range=192.168.100.2,192.168.100.254,255.255.255.0,24h dhcp-option=3,192.168.100.1 server=8.8.8.8
- This assigns IPs between
192.168.100.2
–192.168.100.254
.
- This assigns IPs between
Step 4: Set Up Routing & NAT
- Assign IP to
wlan0
:sudo ip addr add 192.168.100.1/24 dev wlan0
- Enable IP forwarding:
sudo sysctl net.ipv4.ip_forward=1
- Configure NAT (replace
eth0
with your internet source):sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
Step 5: Start the Hotspot
- Stop conflicting services:
sudo systemctl stop systemd-networkd wpa_supplicant
- Start
hostapd
anddnsmasq
:sudo systemctl start hostapd dnsmasq
- (Optional) Enable auto-start on boot:
sudo systemctl enable hostapd dnsmasq
Step 6: Connect Devices
Scan for WiFi networks on your phone/laptop and connect to:
- SSID:
MyLinuxHotspot
- Password:
SecurePassword123
Stopping the Hotspot
sudo systemctl stop hostapd dnsmasq
sudo sysctl net.ipv4.ip_forward=0
sudo iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE # Remove NAT rule
Troubleshooting
- No Internet? Verify NAT rules (
sudo iptables -t nat -L
) and internet source interface. - AP Not Visible? Check
hostapd
logs:journalctl -u hostapd
. - Conflict with Network Manager? Disable it:
sudo systemctl stop NetworkManager
Conclusion
You’ve created a secure WiFi hotspot on Linux! This setup works on Ubuntu/Debian. For Fedora/Arch, use firewalld
instead of iptables
. Customize the SSID, password, and IP range as needed. Share your experience in the comments!