Aug 102012
 

QuickLinks
Part 1 – How to create a Wireless Network On Your RPi
Part 3 – How to make your RPi into a Router

In this part, we will turn the Raspberry Pi into a Wireless Access point.
All it will do is forward packets from the WiFi adapter to ethernet and vice versa. It will allow you to access your network via WiFi without needing a WiFi router.

To do this, we need to bridge the ethernet and wifi connections, and tell hostapd that we are now using a bridge connection.
In /etc/hostapd/hostapd.conf, we need to add the following line.

bridge=br0

Add the following lines into /etc/network/interfaces to define the bridge connection.

#auto br0
iface br0 inet dhcp
bridge_ports eth0 wlan0
pre-up ifconfig eth0 0.0.0.0 up
pre-up ifconfig wlan0 0.0.0.0 up
pre-up brctl addbr br0
pre-up brctl addif br0 eth0
post-down ifconfig wlan0 0.0.0.0 down
post-down ifconfig eth0 0.0.0.0 down
post-down brctl delif br0 eth0
post-down brctl delbr br0

Notice the “auto br0” is commented out. This is so the bridge does not come up automatically, as once the bridge is up, you will not be able to remotely access the Raspberry Pi until the bridge is brought down or until the bridge gets an IP address.

Once the lines are in /etc/network/interfaces, you can type in ifup br0 as root to bring up the bridge. If you are ssh’ed into the Pi, this will drop your connection.
Once it’s up, the Raspberry Pi will forward anything from the WiFi to ethernet and vice versa.

This let’s the Raspberry Pi act as a Wireless Access Point without any sort of routing. On a WiFi device, you will be able to connect to RaspAP, and it will act is if it was on the network, i.e. it will get an IP address from your normal router.


If you have found this post useful, please consider donating by pressing on the button below. Donating will help keep this site up and running 🙂




Share
Aug 092012
 

** Quick Tip For The QuickLinks **
If you want a wifi router, ignore Part 2, and go from this part straight to Part 3. Need internet access ? Part 2 or 3 is the go depending on your need 🙂
QuickLinks:
Part 2 – How to make your RPi into a Wireless Access Point
Part 3 – How to make your RPi into a Router

Also if you are using a RTL8188CUS based device check this forum thread
** Update – 2012-11-10 **
Looks like the newest version of the Raspbian distro adds an extra line to /etc/network/interfaces which needs to be removed or commented out.
The line is wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
Thanks to hunternet93

** Update – 2016-11-06 **
As requested, I’ve added some information from the comments – courtesy of Jakimfett
To find out what driver your USB WiFi stick uses, you can use lshw -C network to find out. The driver info is shown under the configuration section. If lshw is not installed, you can install it via apt-get – apt-get install lshw

** Original Post Starts Here **

I recently bought a Wifi dongle for my Raspberry Pi – A Ralink RT5370.
While I was poking around, I noticed that the USB dongle could act as an Access Point.
I haven’t tried with any others, but the way I found out about mine is by using the iw utility.
Running iw list spat out a list of abilities.
This was a part of the list
Supported interface modes:
* IBSS
* managed
* AP
* AP/VLAN
* WDS
* monitor
* mesh point

So I decided to try it out.
I installed hostapd so that I could run an access point off the Raspberry Pi.
apt-get install hostapd

After I installed hostapd, I had to modify a few files before hostapd would run.

Before I go modifying the files though, I need to give my WiFi adapter a static IP address.
In /etc/network/ there is a file called interfaces. This file contains the details for the network adapters.
I have the lines below in order to set a static IP address.

iface wlan0 inet static
address 10.0.0.1
netmask 255.255.255.0

Now, we need to edit some files.
First up, I had to modify /etc/default/hostapd. The DAEMON_CONF variable was not configured, so I pointed it to a configuration file that I was about to create.
DAEMON_CONF="/etc/hostapd/hostapd.conf"

After that, I created the configuration file in the location specified.
In the configuration file, I specified the following parameters

# First we configure the interface we'll be listening on
interface=wlan0 # The interface to listen on
driver=nl80211
# The driver that is being used by the WiFi adapter, this could be different for everyone
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0 # These 2 are just parameters so that the hostap daemon runs.


# Now onto the important WiFi configuration
ssid=RaspAP
# First up, the SSID or Network name. This is what other devices will see when they try to connect.
hw_mode=g
# I'm setting this to Wireless G mode. A, B, and G are available here.
channel=8
# This is setting the channel that the WiFi is on, valid channels are from 1-11, or 1-14 depending on location.

# Wifi Security Settings
wpa=2 # This sets the security settings to WPA2
wpa_psk=928519398acf811e96f5dcac68a11d6aa876140599be3dd49612e760a2aaac0e
# The line above sets the wpa passphrase to "raspiwlan", this is obtained via the wpa_passphrase command.
# However, you can also set a passphrase like the line below.
#wpa_passphrase=raspiwlan

wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP
# I've set these to WPA-PSK to indicate that we are using a Pre-Shared Key with CCMP encryption.
# Otherwise, hostapd also has a built in RADIUS server that we can use for authentcation
# But I'll leave that to another post.

# Other settings
beacon_int=100 # This sets how often the WiFi will send a beacon out.
auth_algs=3
wmm_enabled=1

** Note ** You may need to strip out all the comments when you save your configuration file as hostapd does not have consistent comment handling.

With the above configuration file saved, I downloaded dnsmasq in order to give my Raspberry Pi the ability to hand out IP addresses to clients that connected to the RaspAP.
apt-get install dnsmasq

For now, we’ll only do a base configuration of dnsmasq, just enough for it to hand out IP addresses so we can test out our new RasAP.

interface=wlan0 # To get dnsmasq to listen only on wlan0.
dhcp-range=10.0.0.2,10.0.0.5,255.255.255.0,12h # This sets the available range from 10.0.0.2 to 10.0.0.5
# It also sets the subnet mask to 255.255.255.0 and specifies a lease time of 12 hours.

After the configuration file has been created in /etc/dnsmasq.conf, start up hostapd and restart dnsmasq.
You should now be able to see the WiFi network “RaspAP” and be able to connect to it and get an IP address.

In the next post, we will turn the Raspberry Pi into a bridge so that it can act as a wireless access point.


If you have found this post useful, please consider donating by pressing on the button below. Donating will help keep this site up and running 🙂




Share