A wireless access point with Raspberry Pi and the AWUS036NH USB adapter

Introduction

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.

Note that the procedure described here works for the AWUS036NH but not for the AWUS036H.

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 zd1211­firmware hostapd hostap­utils iw dnsmasq

Verify if your device supports the required interface modes (the AWUS036NH should):

iw list

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).

/etc/network.interfaces

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

Configure hostapd

Edit hostapd.conf to look similar to this:

/etc/hostapd/hostapd.conf

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.

DAEMON_CONF="/etc/hostapd/hostapd.conf"

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:

/etc/hostapd/hostapd.conf

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

Configure dnsmasq

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).

/etc/init.d/pipoint:

#!/bin/sh
# Configure Wifi Access Point. 

### BEGIN INIT INFO 
# Provides:          WifiAP 
# Required­Start:    $remote_fs $syslog $time 
# Required­Stop:     $remote_fs $syslog $time 
# Should­Start:      $network $named slapd autofs ypbind nscd nslcd 
# Should­Stop:       $network $named slapd autofs ypbind nscd nslcd 
# Default­Start:     2 
# Default­Stop: 
# Short­Description: 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:

chmod+x /etc/init.d/pipoint

Add the script to the startup sequence:

sudo update-rc.d pipoint start 99 2

2 thoughts on “A wireless access point with Raspberry Pi and the AWUS036NH USB adapter

  1. Thanks for this walk through. I just followed it with pretty good success. But..

    My Cable modem needs to give the network router an address via DHCP, so your static eth0 address setup won’t work for me.

    The strange thing is, the pi will get a DHCP address from a 4-port router/wifi that the pi is supposed to replace. But it won’t get an address from the cable modem I want it to interface to.

    I tried running “dhcpcd eth0” and get this output. First, with the router in between the pi and the cable modem:

    dhcpcd[2971]: version 6.7.1 starting
    dhcpcd[2971]: all: IPv6 kernel autoconf disabled
    dhcpcd[2971]: eth0: adding address fe80::86d5:a0b1:bbc0:ade2
    dhcpcd[2971]: if_addaddress6: Operation not supported
    dhcpcd[2971]: DUID 00:01:00:01:1c:dd:60:61:b8:27:eb:6f:bc:21
    dhcpcd[2971]: eth0: IAID eb:6f:bc:21
    dhcpcd[2971]: eth0: rebinding lease of 192.168.0.6
    dhcpcd[2971]: eth0: changing route to 192.168.0.0/24
    dhcpcd[2971]: eth0: changing default route via 192.168.0.1
    dhcpcd[2976]: eth0: MTU set to 1492
    dhcpcd[2971]: forked to background, child pid 2989

    Now, with the pi connected to the cable modem:

    dhcpcd[2744]: version 6.7.1 starting
    dhcpcd[2744]: all: IPv6 kernel autoconf disabled
    dhcpcd[2744]: eth0: adding address fe80::86d5:a0b1:bbc0:ade2
    dhcpcd[2744]: if_addaddress6: Operation not supported
    dhcpcd[2744]: DUID 00:01:00:01:1c:dd:60:61:b8:27:eb:6f:bc:21
    dhcpcd[2744]: eth0: IAID eb:6f:bc:21
    dhcpcd[2744]: eth0: soliciting a DHCP lease
    dhcpcd[2744]: eth0: using IPv4LL address 169.254.98.169
    dhcpcd[2744]: eth0: adding route to 169.254.0.0/16
    dhcpcd[2744]: forked to background, child pid 2791

    Any ideas on how to debug this?

    Minor edit to your process: your “apt-get install install ..” you’ve duplicated “install.” Also, the hyphens you’re using don’t cut and paste correctly for some strange reason…

    Thanks for doing this! 🙂

  2. Thanks for your comments. The Pi gets an IP address from the router because the router responds to the DCHP request first. A static IP address shouldn’t be a problem as long as it is on the same subnet and outside the DHCP pool (192.168.0.i when connected to the router).

Leave a Reply