Feb 102013
 

So, I figured out why wlan0 doesn’t get an IP address when hostapd starts up.
ifplugd messes about with the interfaces when they go up and down, so the simplest solution is to disable ifplugd for wlan0 !
in /etc/default/ifplugd, the default configuration is this

INTERFACES="auto"
HOTPLUG_INTERFACES="all"
ARGS="-q -f -u0 -d10 -w -I"
SUSPEND_ACTION="stop"

Simply changing it to this

INTERFACES="eth0"
HOTPLUG_INTERFACES="eth0"
ARGS="-q -f -u0 -d10 -w -I"
SUSPEND_ACTION="stop"

will ensure that wlan0 will not lose it’s static IP address that’s configured in /etc/network/interfaces when wlan0 goes up.

Share
Feb 082013
 

As a continuation this post, I have completed the first version of the RaspAP WebGUI. I have yet to decide on a good name for it though.
Continue reading »

Share
Jan 102013
 

So a few people have tried to follow Part 3 of this series of posts, and had issues with the connections once everything is setup.
The main cause for that, was that hostapd would take away the IP address of wlan0 for some reason.
I worked around it by modifying the /etc/init.d/hostapd startup file.

In that file, there is a switch case statement which controls what the file does depending on how you run the file.

The example below is what you will see part way down the file. What we need to do is add in some commands into that block of code.

case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
start-stop-daemon --start --oknodo --quiet --exec "$DAEMON_SBIN" \
--pidfile "$PIDFILE" -- $DAEMON_OPTS >/dev/null
log_end_msg "$?"
;;
stop)

The command we will need to add are :
ifup wlan0

Which brings up wlan0 with the specified IP address. The IP address should have been setup in Part 3 of this series.

So the above block of code will now become –

case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
start-stop-daemon --start --oknodo --quiet --exec "$DAEMON_SBIN" \
--pidfile "$PIDFILE" -- $DAEMON_OPTS >/dev/null
log_end_msg "$?"
ifup wlan0
;;
stop)

This will force wlan0 to come up after hostapd is started.

Alternatively to force wlan0 to use an ip.address, replace ifup wlan0 with this
ifconfig wlan0 10.0.0.1 netmask 255.255.255.0 up
Hopefully this helps everyone when they come to making their Pi a WiFi Router ! 😀

Share
Jan 102013
 

A while ago, I was having an issue with one of my computer’s WiFi connection not connecting correctly on startup.
Maybe the signal was too weak on startup or the WiFi adapter just wasn’t fast enough when the computer wanted it to connect, for some reason it would never connect and I would have to manually run an ifup command to make it connect.

I ended up making this script to check whether the WiFi had an IP address, and if it didn’t it would take down the WiFi adapter and bring it back up again.
Now, I never need to worry about that computer’s WiFi connection !
I was also going to use this for one of my Raspberry Pi projects but never got around to putting the script onto the Pi, so anyone who has the issue where hostapd breaks the IP address, this script is perfect for it !


#!/bin/bash

wlan=`/sbin/ifconfig wlan0 | grep inet\ addr | wc -l`
if [ $wlan -eq 0 ]; then
/sbin/ifdown wlan0 && /sbin/ifup wlan0
else
echo interface is up
fi

I’ve setup this script to run as a cronjob every 5 minutes to make sure the WiFi stays up.

Share
Aug 112012
 

QuickLinks
Part 1 – How to create a wireless network on your RPi
Part 2 – How to make your RPi into a Wireless Access Point
Part 3A – Issues with HostAPD ? Click here
Part 3B – Issues with HostAPD ? Click here!

In Part 3, we will turn the Raspberry Pi into a router. The Pi will use the ethernet port as the “WAN” port, and the wireless adapter as the “LAN” side of things.
First thing we need to do is to enable packet forwarding.
In the file /etc/sysctl.conf, we need to uncomment the following line (should be line 28).

#net.ipv4.ip_forward=1

After changing that, run this command to re-read the sysctl.conf file

sysctl -p

We will also need to install the iptables utilities if they are not already installed, and alter the dnsmasq.conf file so that dnsmasq will assign a gateway to the computers.

Firstly we install iptables.

apt-get install iptables

Then we will add this line to dnsmasq.conf.
The IP address is the same one we gave to the WiFi adapter back in Part 1

dhcp-option=3,10.0.0.1

We will need to create an iptables script to tell the Raspberry Pi to forward packets from the WiFi interface to the LAN interface. This script will need to run at startup in order for it to be a router.
I have created the following file in /etc/network/if-up.d/ called router. By placing the script in that directory, it will be run every time the Raspberry Pi comes online.
This file contains the following lines

iptables -F
iptables -X

iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -i wlan0 -j ACCEPT
iptables -A OUTPUT -o wlan0 -j ACCEPT

iptables -A POSTROUTING -t nat -o eth0 -j MASQUERADE
iptables -A FORWARD -i wlan0 -j ACCEPT

After creating this file, make it executable by using this command

chmod +x /etc/network/if-up.d/router

Once that router.sh file has been run, it should start forwarding traffic from the WiFi Interface to the LAN interface !

** UPDATE **
As a few people have found out, the IP address of the Pi does not get set correctly until you take down wlan0 and bring it back up after hostapd starts.
I have not found out why yet, but the workaround I am currently using consists of editing /etc/init.d/hostapd, and modifying the start case statement to include ifdown wlan0 && ifup wlan0 at the end of it.
I failed to copy the statement I am talking about, but if you’re familiar with scripting it shouldn’t be too hard to figure out. Otherwise I’ll get the code I modified up here soon.

** UPDATE 2 **
Looks like a Pi user has successfully gotten hostapd running on the realtek devices.
Info can be found here


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