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)
Steps
The script does the following to activate the access point:
- Activate wireless chip: rfkill unblock wlan
- Start hostapd as daemon: hostapd -B -P PID_FILE hostapd.conf
- Add IP address to wireless interface: ip address add IP_ADDRESS brd + dev WIFI_INTERFACE
- Add rule for network address translation: iptables -t nat -A POSTROUTING -o WAN_INTERFACE -j MASQUERADE
- Enable IP forwarding (routing): sysctl -q -w net.ipv4.ip_forward=1
- 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