christianix.de

-> Main -> Access Point Tutorial

Linux as wireless access point
I frequently use a script that turns my laptop into an access point. I thought this script might be useful for others, too. Below I also describe what the script does and how to use it.
Requirements
You need the following Debian or Ubuntu packages to run the script:
  • hostapd
  • dnsmasq-base
  • rfkill
  • iptables
  • procps (for sysctl)
For other distribution, you might find similar packages. But you might also need to adjust paths in the script.
Steps
The script does the following to activate the access point:
  1. Activate wireless chip: rfkill unblock wlan
  2. Start hostapd as daemon: hostapd -B -P PID_FILE hostapd.conf
  3. Add IP address to wireless interface: ip address add IP_ADDRESS brd + dev WIFI_INTERFACE
  4. Add rule for network address translation: iptables -t nat -A POSTROUTING -o WAN_INTERFACE -j MASQUERADE
  5. Enable IP forwarding (routing): sysctl -q -w net.ipv4.ip_forward=1
  6. Start DHCP service: dnsmasq --interface=WIFI_INTERFACE --dhcp-range=IP_RANGE
Running the script
Download accesspoint.sh and hostapd.conf. But before you run the script, you need to
  • set parameters in accesspoint.sh:
    • waniface: Interface to the outside world (eg. eth0)
    • wlaniface: Wireless interface (usually wlan0)
    • wlanaddr: IP address of wireless network
    • DHCP pool parameter of dnsmasq command
  • set parameters in hostapd.conf:
    • interface: Same wireless interface as in accesspoint.sh
    • ssid: Name of wireless network
    • channel: Integer value (available values depend on country)
    • wpa_passphrase: Key (password) to access the wireless network
Verantwortlich/Responsible: Martin Christian (martin at christianix dot de)