Set-up the Raspberry Pi as an access point

I’ve had a successful time getting the Pi set-up as a Wifi access point. The end result is an access point running on one wifi dongle, bridged to a second wifi dongle for an internet connection. This means that I can connect a phone to the Pi using an adhoc wireless network connection.

For the access point dongle,  I am using an old AzureWave AW-NU221 dongle. It’s an ugly white plastic thing that’s definitely NOT a ‘nano’ dongle. This dongle is known on my system as wlan3.
For the bridged wifi dongle, I’m using the good old reliable Edimax. This is known as wlan0.

Be aware that all my scripts are stored in /boot/redwing-pi and that I am logged in as root when I run it!

 

Here is a script to install everything you need and to walk you through the set-up.

#!/bin/bash
clear

echo "Redwing Access Point installer"
echo "(c) Michael Horne 2012 / Recantha"
echo "Please note all responses requested are Case Sensitive"
echo ""
echo "SPECIFY WIRELESS DEVICE"
# DEBUGGING MODE - set to something other than hostapd.conf
HOSTAPDFILE=hostapd.conf
# List devices
iwconfig 2>/dev/null | grep wlan
echo "Please type in the name of the wlan device to use as the access point"
read WLAN

echo "Type in the name of the wifi driver. This is normally nl80211 but may vary. You can always change this later by modifying the hostapd.conf file"
read DRIVER

echo "Type in the name of the access point you wish to create"
read SSID

echo "Type in the passphrase for the access point"
read PASSPHRASE

echo "PACKAGE INSTALLATION"
echo "There are a fair few packages that need to be installed. Some of these may require you to confirm their installation"
echo "Press any key"
read -n1 -s IGNORE

apt-get update
apt-get install hostapd
apt-get install dnsmasq
apt-get install dhcpd
apt-get install wireless-tools hostapd bridge-utils

echo ""
echo "Using $WLAN for the access point"
echo ""

# HOSTAPD SECTION
echo "Generating the hostapd.conf file"

# Create the hostapd.conf file
echo "" > $HOSTAPDFILE
echo "interface=$WLAN" >> $HOSTAPDFILE
echo "driver=$DRIVER" >> $HOSTAPDFILE
echo "ctrl_interface=/var/run/hostapd" >> $HOSTAPDFILE
echo "ctrl_interface_group=0" >> $HOSTAPDFILE
echo "ssid=$SSID" >> $HOSTAPDFILE
echo "hw_mode=g" >> $HOSTAPDFILE
echo "channel=10" >> $HOSTAPDFILE
echo "wpa=3" >> $HOSTAPDFILE
echo "wpa_passphrase=$PASSPHRASE" >> $HOSTAPDFILE
echo "wpa_key_mgmt=WPA-PSK" >> $HOSTAPDFILE
echo "wpa_pairwise=TKIP" >> $HOSTAPDFILE
echo "rsn_pairwise=CCMP" >> $HOSTAPDFILE
echo "beacon_int=100" >> $HOSTAPDFILE
echo "auth_algs=3" >> $HOSTAPDFILE
echo "wmm_enabled=1" >> $HOSTAPDFILE
echo "" >> $HOSTAPDFILE

echo ""
echo "Do you want to change the system so it uses the hostpad.conf file just generated? (Do this ONCE and ONCE only)"
read -n1 -s CONFIRM
if [ "$CONFIRM" == "Y" ];then
echo "DAEMON_CONF="/boot/redwing-pi/access_point/hostapd.conf"" >> /etc/default/hostapd
fi

echo "Do you want to route the IP tables for network forwarding? [Y to do it]"
read -n1 -s CONFIRM
if [ "$CONFIRM" == "Y" ];then
iptables -A FORWARD -i $WLAN -o wlan0 -s 10.0.0.0/24 -m state --state NEW -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -j MASQUERADE
sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
fi

echo "Do you want to set /etc/network/interfaces for the access point (wlan3)? (Do this ONCE and only ONCE) [Y to do it]"
read -n1 -s CONFIRM
if [ "$CONFIRM" == "Y" ];then
echo "" >> /etc/network/interfaces
echo "auto $WLAN" >> /etc/network/interfaces
echo "iface $WLAN inet static" >> /etc/network/interfaces
echo " address 10.0.0.1" >> /etc/network/interfaces
echo " netmask 255.255.255.0" >> /etc/network/interfaces
echo " wireless-channel 10" >> /etc/network/interfaces
echo " wireless-ssid "$SSID"" >> /etc/network/interfaces
echo " wireless-mode ad-hoc" >> /etc/network/interfaces
echo "" >> /etc/network/interfaces

echo ""
echo "NB: If you have run this twice, you will need to remove the duplicate text"
echo "NB: If your wifi dongle for the access point is NOT on wlan3, edit /etc/network/interfaces to suit"
fi

# Sets dhcp range and length of lease
echo "MANUAL PROCESSES REQUIRED"
echo "Edit /etc/dnsmasq.conf"
echo "Find and change interface setting to : interface=$WLAN"
echo "dhcp-range=10.0.0.2,10.0.0.5,255.255.255.0,12h"
echo ""

You then need another script to actually run the access point:

#!/bin/bash
killall hostapd
clear

USAGE="Usage: start_access_point   "
if [ "$1" == "" ];then
	echo $USAGE
	exit 0
fi

if [ "$2" == "" ];then
	echo $USAGE
	exit 0
fi

if [ "$3" == "" ];then
	echo $USAGE
	exit 0
fi

WLAN=$1
ESSID=$2
BRIDGETO=$3

ifconfig $WLAN down
iwconfig $WLAN mode ad-hoc
ifconfig $WLAN up
iwconfig $WLAN essid "$ESSID"
ifconfig $WLAN inet 10.0.0.1

ifconfig $WLAN up 10.0.0.1 netmask 255.255.255.0
udhcpd $WLAN &

iptables --flush
iptables --table nat --flush
iptables --delete-chain
iptables --table nat --delete-chain
iptables --table nat --append POSTROUTING --out-interface $BRIDGETO -j MASQUERADE
iptables --append FORWARD --in-interface $WLAN -j ACCEPT
sysctl -w net.ipv4.ip_forward=1

# Now actually start hostapd
hostapd /boot/redwing-pi/access_point/hostapd.conf
#hostapd /boot/redwing-pi/access_point/hostapd.conf 1> /dev/null &

Now, I can’t guarantee that’ll all work, but it did for me!

 

Setting up LCD via GPIO on RasPi

I found these while reading my RSS feeds (If you click this link you’ll be able to subscribe to my feed that merges together over 100 different feeds into one).

These are great step-by-step articles from TechFruits, with circuit diagrams on how to get an LED breakout board working with the Pi. Wish I’d had these to work from when I did mine!

Read the articles here:

Setting up LCD via GPIO on RasPi – Part 2

Setting up LCD via GPIO on RasPi – Part 3.

Quick guide to getting on the Raspberry Pi IRC channel

IRC may be considered a bit ‘old hat’ now. It was launched 1988 and at the time was considered one of the best things since sliced bread. A text-only chat where you could meet untold millions of people talking about common interests… Or more sordid subjects if you liked that kind of thing.

Raspberry Pi is being discussed on it’s own channel – #raspberrypi. If you know how to get on IRC already, get over there – looks like it’s normally populated. You may even catch me on there sometimes.

For those of you without a clue, here’s a quick guide. You might have to find some menu options here and there, but this should give you a good idea of what’s involved.

I’m using a chat client called Pidgin in it’s portable format. So if you don’t like it or don’t use it, you just delete the folder and that’s it.

  1. Download and install Pidgin portable
  2. Start it up.
  3. Add an account for IRC (use the dropdown).
  4. Set a username and a password here. (The username is your irc ‘nickname’ that you’d like to use).
  5. Join a chat and specify the #portableapps channel. This will get you into the IRC system as you need to set-up additional security for the RPi channel.
  6. Type in:
    /msg NickServ REGISTER <password> <email address>
  7. This will register you and get a verification email sent to you.
  8. Go to your email and wait for the IRC one to come through.
  9. Follow the instructions to verify.
  10. Leave any of the channels/rooms you’re in.
  11. From Pidgin, join a chat and enter as the channel name: #raspberrypi.

You should then be into the chatroom and away you go – type type type!