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:

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