Hotspot - WiFi Access Point

Pi few months ago, I was also about to buy 3G router/AP. When I learned what RPi is, and I saw people trying to make AP out of it, I knew where to place my money :) I know I’ve chosen right… RPi as AP gives you enormous number of possibilities: wireless streaming of cartoons to your tablet when you’re in the car. Your wife (if you have one already ;) ) in the same time can watch Desperate Housewives… and you can focus on pleasure from driving. I hope you’re interested already so let’s do it.

Note: this tutorial assumes that your RPi already detects your WiFi dongle. If you need to install it, please check our other tutorial.
Please make sure your WiFi dongle supports AP mode. This tutorial and script was tested with TP-LINK WN725N based on RTL8188CUS chipset.

I know there have been many tutorials on how to do this, but I believe there is none that would be a complete guide for total newbie. I had to compile information from few tutorials to set everything right. Let’s go step by step and I will try to explain what and why you need to set up. There will be surprise at the end of article so so not miss anything :)

Before we’ll go to WHAT, I will try to explain WHY.

What AP needs to be capable of to be AP :) :

  • 1. Inform devices about AP existence (Broadcast SSID) or at least allow clients to connect
  • 2. Authenticate client
  • 3. Assign IP to the client devices
  • 4. Route packages to the “output” network and the other way around

In order to handle all of this, RPi needs the following tools:

  • hostapd – Host AccessPoint Daemon – will take care of 1.
  • wpa-supplicant – tool responsible for WPA authorization for 2.(most likely you have it installed already)
  • isc-dhcp-server – will take care of 3.
  • ip-tables – will take care of 4. (most likely you’ll have this installed already)

Let’s install these tools:

sudo apt-get -y install hostapd isc-dhcp-server iptables wpa_supplicant

First we’ll take care of configuration of AP daemon and it’s security – we do it in /etc/hostapd/hostapd.conf .

interface=wlan0 #wlan0 will be working in AP mode ssid=Your_AP_SSID #your AP SSID

channel=1 #WiFi channel used by AP

# WPA and WPA2 configuration macaddr_acl=0 #indicates that you do not use MAC address allow/deny list auth_algs=1 #indicates algorithm specified by IEEE 802.11

ignore_broadcast_ssid=0 #AP will broadcast SSID

#WPA settings wpa=2 #WPA algorithm used (WPA2 in this case)

wpa_passphrase=my_secret_pass #AP password wpa_key_mgmt=WPA-PSK #WPA key mangement type wpa_pairwise=TKIP #encription algorithm rsn_pairwise=CCMP #encription algorithm

#Hardware configuration driver=rtl871xdrv #type of driver to be used (in may be different depending on your WiFi dongle chipset)

#in majority of cases it will be driver=nl80211

ieee80211n=1 #Whether IEEE 802.11n (HT) is enabled device_name=RTL8192CU #User-friendly description of device (optional)

manufacturer=Realtek #Manufacturer name (optional)

hw_mode=g #WPS RF Bands (a = 5G, b = 2.4G, g = 2.4G, ag = dual band)

Now we need to set up /etc/hostapd/hostapd.conf as the configuration file. We do it in /etc/default/hostapd. Put the following line there:

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

OK, perfect. Now let’s configure the network settings for clients connecting to AP. We do it in /etc/dhcp/dhcpd.conf

ddns-update-style none; #DDNS disabled default-lease-time 84600; #IP lease time valid for a day max-lease-time 84600; #IP lease time valid for a day subnet 192.134.3.0 netmask 255.255.255.0 { #AP Subnet defintion

range 192.134.3.2 192.134.3.9 ; #Range of IP addresses available for clients

option domain-name-servers 192.168.1.1 ; #your DNS IP (in my case, my router is workign as DNS)

option domain-name "home"; #optional domain name

option routers 192.134.3.1 ; #your client's gateway / router IP

Again we need to make sure that DHCP server uses this configuration. In /etc/default/isc-dhcp-server put the following lines:

DHCPD_CONF="/etc/dhcp/dhcpd.conf"

INTERFACES="wlan0"

The last line indicates network interface that will be serving DHCP requests.

We’re almost done. Let’s configure wlan0 for static IP adress (the same as router IP in dhcpd.conf file.
We do it in /etc/network/interfaces:

auto wlan0

allow-hotplug wlan0

iface wlan0 inet static

address 192.134.3.1

netmask 255.255.255.0

up iptables-restore < /etc/iptables.ipv4.nat

The last line will set routing rules after restart.
Let’s turn on packet forwarding in /etc/sysctl.conf by making sure that line

net.ipv4.ip_forward=1

is un-commented or added.

We will configure routing now by executing (assuming eth0 is your WAN interface):

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT

sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

and lets save these setting in a file:

sh -c "iptables-save > /etc/iptables.ipv4.nat"

Because I had bloody RTL8188CUS chipset I had to replace original hostapd with the one prepared for my chipset.

wget "http://raspberry-at-home.com/files/hostapd.gz"

sudo gzip -d hostapd.gz sudo chmod 755 hostapd sudo cp hostapd /usr/sbin/

In order to start AP on boot run the following commands:

sudo update-rc.d hostapd enable sudo update-rc.d isc-dhcp-server enable

We are done! Now restart your RPi:

sudo shutdown -r now

There is much easier way to do all of this :) Use our configuration script and have AP set up in 2 minutes!

wget "http://raspberry-at-home.com/files/ap_setup.sh"

chmod +x ap_setup.sh sudo ./ap_setup.sh

Let me know if something does not work! just comment on the article.

Great articles that helped a lot:

http://www.jenssegers.be/

http://www.raspberrypi.org/phpBB3/viewtopic.php?t=31227

Continue reading here: Hyperion on OpenELEC. It works!

Was this article helpful?

+5 -3