화. 8월 12th, 2025

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

  1. Wireless Adapter: Must support “AP mode” (check with iw list | grep "AP").
  2. Admin Access: Run all commands with sudo.
  3. 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)

  1. Create a config file:
    sudo nano /etc/hostapd/hostapd.conf  
  2. Paste this (adjust ssid, wpa_passphrase, and channel):
    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 via iw dev).

Step 3: Configure DNSMasq (DHCP Server)

  1. Backup the default config:
    sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.backup  
  2. Create a new config:
    sudo nano /etc/dnsmasq.conf  
  3. 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.2192.168.100.254.

Step 4: Set Up Routing & NAT

  1. Assign IP to wlan0:
    sudo ip addr add 192.168.100.1/24 dev wlan0  
  2. Enable IP forwarding:
    sudo sysctl net.ipv4.ip_forward=1  
  3. 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

  1. Stop conflicting services:
    sudo systemctl stop systemd-networkd wpa_supplicant  
  2. Start hostapd and dnsmasq:
    sudo systemctl start hostapd dnsmasq  
  3. (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!

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다