The need for a new access point arose out of discontent with the Speedport W723V DSL router as provided by T-Online. De device tended to become less stable as more wireless devices got connected. The Wi-Fi connection froze several times a week, among other annoyances. Besides I wanted a highly configurable access point for use with wireless projects in and around the house.
Connect the AWUS036 over a USB power hub to prevent it from draining the Raspberry Pi.
Install the required packages
We need to install some wireless utilities and a package to support the adapter firmware. The hostapd daemon is used for the actual hotspot. The dnsmasq daemon handles DNS and DHCP requests.
sudo apt-get update sudo apt-get upgrade sudo apt-get install rfkill zd1211firmware hostapd hostaputils iw dnsmasq
Verify if your device supports the required interface modes (the AWUS036NH should):
It should list ‘AP’, ‘managed’ and ‘monitor’ among others.
Configure the network interface
Edit /etc/network/interfaces to configure the wireless interface. It needs to be static. In the example below the ethernet interface has a static IP address too, so we can always find the Raspberry Pi at 192.168.2.10 (outside the DHCP pool).
iface eth0 inet static address 192.168.2.10 netmask 255.255.255.0 network 192.168.2.0 broadcast 192.168.2.255 gateway 192.168.2.1 iface wlan0 inet static address 192.168.1.1 netmask 255.255.255.0
Restart the interface after you have made a change:
sudo ifdown wlan0 sudo ifup wlan0
Edit hostapd.conf to look similar to this:
interface=wlan0 driver=nl80211 ssid=<SSID> channel=3
Insert your SSID and pick a channel that is supported by your hardware.
Start hostapd from the command line to test your configuration. Correct any reported errors.
sudo hostapd -d /etc/hostapd/hostapd.conf
To run hostapd as a service first make sure that /etc/default/hostapd contains the absolute path to your configuration file.
Now the daemon can be started and stopped as a service. It will also be started on system startup (ref. /etc/init.d/hostapd).
sudo service hostapd start sudo service hostapd stop sudo service hostapd restart
Restart the daemon after a configuration change. To enable WPA do something like this:
interface=wlan0 driver=nl80211 ssid=<SSID> hw_mode=g channel=3 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=<WPA_PASSPHRASE> wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
Edit /etc/dnsmasq.conf and make sure it contains the following (uncommented) lines:
domain-needed interface=wlan0 dhcp-range=192.168.1.5,192.168.1.254,255.255.255.0,12h
Restart the dnsmasq service with this configuration:
sudo service dnsmasq restart
Activate IP forwarding and NAT
Enable IP forwarding in the proc filesystem:
sudo sh -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'
Append a rule to ‘nat’ in iptables:
iptables -t nat -A POSTROUTING -j MASQUERADE
Run on startup
This has already been configured for hostapd (see above). Now create the following script in /etc/init.d (modified from Pi-Point).
#!/bin/sh # Configure Wifi Access Point. # ### BEGIN INIT INFO # Provides: WifiAP # RequiredStart: $remote_fs $syslog $time # RequiredStop: $remote_fs $syslog $time # ShouldStart: $network $named slapd autofs ypbind nscd nslcd # ShouldStop: $network $named slapd autofs ypbind nscd nslcd # DefaultStart: 2 # DefaultStop: # ShortDescription: Wifi Access Point configuration # Description: Sets forwarding, starts hostap, enables NAT in iptables ### END INIT INFO echo 1 > /proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING -j MASQUERADE service dnsmasq restart
Make sure it’s executable:
Add the script to the startup sequence:
sudo update-rc.d pipoint start 99 2