[Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)


388 posts   Page 1 of 16   1, 2, 3, 4, 5 ... 16
by hunternet93 » Wed Oct 03, 2012 2:06 pm

The tutorial has now been moved to: http://elinux.org/RPI-Wireless-Hotspot
Last edited by hunternet93 on Sun Feb 09, 2014 8:54 pm, edited 2 times in total.
Posts: 319
Joined: Mon Dec 12, 2011 4:34 pm
by malakai » Wed Oct 03, 2012 2:38 pm
Looks great can't wait to get home and try it out.

What wireless adapter are you using?

Also want to try out with http://www.raspberrypi.org/phpBB3/viewtopic.php?f=41&t=3059 A DIY PoE.
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)
User avatar
Posts: 1383
Joined: Sat Sep 15, 2012 10:35 am
by bredman » Wed Oct 03, 2012 2:53 pm
A warning for all readers...

Most WiFi adaptors cannot support Access Point mode, so be careful if you buy something just for this purpose.

You need a WiFi device which supports "AP mode" or "Master mode".
Posts: 1413
Joined: Tue Jan 17, 2012 2:38 pm
by hunternet93 » Wed Oct 03, 2012 3:56 pm
malakai wrote:Looks great can't wait to get home and try it out.

What wireless adapter are you using?

Also want to try out with http://www.raspberrypi.org/phpBB3/viewtopic.php?f=41&t=3059 A DIY PoE.

I'm currently using a cheap dongle from Amazon using a Ralink chipset, I'm not sure of the exact model. PoE would be cool combined with the Pi, I may try that out.
Posts: 319
Joined: Mon Dec 12, 2011 4:34 pm
by Linus » Wed Oct 03, 2012 4:30 pm
The guy in this http://sirlagz.net/2012/08/09/how-to-use-the-raspberry-pi-as-a-wireless-access-pointrouter-part-1/ tutorial uses
Code: Select all
iw list
to determine if the dongle has Acces Point capabilities.
Posts: 23
Joined: Sat Mar 03, 2012 9:49 am
by hunternet93 » Wed Oct 03, 2012 7:31 pm
Unless I am very mistaken, the wireless dongle does not need to support master mode. HostAPD (host access point daemon) uses low-level WiFi magic to turn any supported wireless card into an access point, hardware master mode not required. I just got a really cheap dongle off Amazon for this, it doesn't support master mode but hostapd works great.
Posts: 319
Joined: Mon Dec 12, 2011 4:34 pm
by malakai » Wed Oct 03, 2012 7:47 pm
When I get home or time I will test on cards I know that have neither supported I believe the software should handle all the issues that would require such adapters.
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)
User avatar
Posts: 1383
Joined: Sat Sep 15, 2012 10:35 am
by poing » Thu Oct 04, 2012 9:08 pm
This does sound interesting and is exactly what I need for my embedded project, so, after a double backup of my precious installation ;) , I tried it, but it doesn't work :( .

Is the line:
"iptables-restore < /etc/iptables.ipv4.nat " correct, or should it be:
"iptables-restore > /etc/iptables.ipv4.nat" ?

Thanks.
Posts: 1099
Joined: Thu Mar 08, 2012 3:32 pm
by hunternet93 » Thu Oct 04, 2012 11:36 pm
poing wrote:This does sound interesting and is exactly what I need for my embedded project, so, after a double backup of my precious installation ;) , I tried it, but it doesn't work :( .

Is the line:
"iptables-restore < /etc/iptables.ipv4.nat " correct, or should it be:
"iptables-restore > /etc/iptables.ipv4.nat" ?

Thanks.


The first line is correct. The "<" symbol send the contents of the iptables.ipv4.nat file to the iptables-restore program. Sorry it doesn't work. What is the problem, exactly?
Posts: 319
Joined: Mon Dec 12, 2011 4:34 pm
by poing » Fri Oct 05, 2012 6:54 am
I have the Edimax nano stick, which worked great with the setup through the icon in the latest Raspian distro. I then worked through your tutorial, where there were two problems.

The first was that I was not allowed to complete one step using sudo, I had to do "sudo bash #" before I went through. Sadly I didn't record the exact step (but I can repeat the process after replacing the backup), I think it was "iptables-save > /etc/iptables.ipv4.nat".

the next problem was that I had to change, I think, "/etc/udhcpd.conf" or "/etc/hostapd/hostapd.conf" where a value had to be changed from "no" to "yes" to allow changes.

After 'firing up' nothing happened. I then restarted the Pi but still no go. Before the Edimax was blinking all the time with a small blue led, but now it's just dead. I guess I'll retry and carefully note the steps above as I really would like this to work. Sadly I'm a newbie, so I have no clue myself :D
Posts: 1099
Joined: Thu Mar 08, 2012 3:32 pm
by hunternet93 » Fri Oct 05, 2012 11:33 am
poing wrote:I have the Edimax nano stick, which worked great with the setup through the icon in the latest Raspian distro. I then worked through your tutorial, where there were two problems.

The first was that I was not allowed to complete one step using sudo, I had to do "sudo bash #" before I went through. Sadly I didn't record the exact step (but I can repeat the process after replacing the backup), I think it was "iptables-save > /etc/iptables.ipv4.nat".

the next problem was that I had to change, I think, "/etc/udhcpd.conf" or "/etc/hostapd/hostapd.conf" where a value had to be changed from "no" to "yes" to allow changes.

After 'firing up' nothing happened. I then restarted the Pi but still no go. Before the Edimax was blinking all the time with a small blue led, but now it's just dead. I guess I'll retry and carefully note the steps above as I really would like this to work. Sadly I'm a newbie, so I have no clue myself :D


Hmm. Try running the following commands and posting the results:
Code: Select all
sudo service hostapd status
sudo service udhcpd status
sudo ifconfig
sudo iwconfig

The first two commands check if HostAPD and uDHPD are running, the second two give some information on your network interfaces. It's very possible I missed a step when writing the instructions, I wrote them during a break a work and haven't had time to verify them on a Pi yet.
Posts: 319
Joined: Mon Dec 12, 2011 4:34 pm
by hunternet93 » Fri Oct 05, 2012 1:56 pm
I found an error in my tutorial. The line
Code: Select all
 iptables-restore < /etc/iptables.ipv4.nat

should be
Code: Select all
 up iptables-restore < /etc/iptables.ipv4.nat

I'll edit my tutorial to fix this.
I'm also having an issue with getting the thing to work on boot, I'll post when I get that worked out.
Posts: 319
Joined: Mon Dec 12, 2011 4:34 pm
by hunternet93 » Fri Oct 05, 2012 2:03 pm
If you have a network management program running (i.e. NetworkManager, wicd) then you should disable or remove it. I had NetworkManger installed and it tried to take control of wlan0, preventing me from connecting.

EDIT: Also, my iptables rules seem to block traffic of any kind. Oops. I'll fix it ASAP. Also, I can't edit my first post for some reason, I reported it so hopefully an admin will take pity on me. :D
Posts: 319
Joined: Mon Dec 12, 2011 4:34 pm
by poing » Fri Oct 05, 2012 2:57 pm
OK, what I'll do is put the backup back and wait for the update of your tutorial (no reason for haste or anything) and then I'll try again step by step.
Posts: 1099
Joined: Thu Mar 08, 2012 3:32 pm
by poing » Sat Oct 06, 2012 7:24 pm
After looking into this a bit further it appears my Edimax is not compatible with hostapd so I decided to order a Ralink RT5370 as is described here:
http://sirlagz.net/2012/08/09/how-to-use-the-raspberry-pi-as-a-wireless-access-pointrouter-part-1/
Posts: 1099
Joined: Thu Mar 08, 2012 3:32 pm
by hunternet93 » Sun Oct 07, 2012 3:52 am
I found my issue -- NetworkManager was taking control of wlan0 and eth0. I thought I had disabled it, but it was still running. I'll rewrite my tutorial when I get a chance. According to http://linuxwireless.org/en/users/Documentation/hostapd, the mac80211 drivers now used by most wireless cards moves master mode to userspace, so most cards should work in master mode. I've only tested a couple Ralink-based adapters, but I think most cards should work ok.
Posts: 319
Joined: Mon Dec 12, 2011 4:34 pm
by e21c » Sun Oct 07, 2012 9:16 pm
Hello,
I would like to make web page, which will be working as splash (welcome) screen for clients who connect to my AP.
Now, I have lighttpd server + webpy (fastCGI) working on RPi. I connect wifi dongle (TL-WN722) to hub and run hostap + dhcp.

But I don't know how to configure net traffic redirecting.
Posts: 4
Joined: Sun Oct 07, 2012 6:37 pm
by hunternet93 » Mon Oct 08, 2012 11:56 pm
I've edited the tutorial and sent it to scep, he offered to edit the post for me since I can't edit it for some reason. I believe I've worked the bugs out, I had typed a command backwards which prevented hostapd and udhcpd from starting at boot.
Posts: 319
Joined: Mon Dec 12, 2011 4:34 pm
by hunternet93 » Tue Oct 09, 2012 12:01 am
e21c wrote:Hello,
I would like to make web page, which will be working as splash (welcome) screen for clients who connect to my AP.
Now, I have lighttpd server + webpy (fastCGI) working on RPi. I connect wifi dongle (TL-WN722) to hub and run hostap + dhcp.

But I don't know how to configure net traffic redirecting.

CoovaChilli (http://coova.org/CoovaChilli) looks like it will do what you want. I've never used it but it appears to be what you're looking for.
Posts: 319
Joined: Mon Dec 12, 2011 4:34 pm
by e21c » Thu Oct 11, 2012 6:10 pm
I solved my problem with command :
sudo iptables -t nat -A PREROUTING -d 0/0 -p tcp –dport 80 -j DNAT –to MyServerIP:80
Thanks hunternet93 for your attempt to solve it.
Posts: 4
Joined: Sun Oct 07, 2012 6:37 pm
by hunternet93 » Thu Oct 11, 2012 6:22 pm
e21c wrote:I solved my problem with command :
sudo iptables -t nat -A PREROUTING -d 0/0 -p tcp –dport 80 -j DNAT –to MyServerIP:80
Thanks hunternet93 for your attempt to solve it.


I'm glad you found a solution. That's a great solution, iptables seems to be able to do anything. I may use that in the future.
Posts: 319
Joined: Mon Dec 12, 2011 4:34 pm
by Wolfram23 » Tue Nov 06, 2012 4:09 am
Hey guys. I made a thread and was pointed here to solve my issue. Basically, I am hooking my Pi up in my car and need to access it to see if it is actually working (communicating over OBD 2 with ECU).

I've got an iPhone and/or iPad to ssh to the Pi already but that's over my home network. Following the instructions did not work for me - my guess being that I'm already connected to a network and using ssh to do all this.

Is there anything I need to do differently to get this working? I can connect to a monitor if required for setup, as long as I'm able to remote into it after without a router (car is in a parkade so no wifi access)
Posts: 73
Joined: Thu Jul 19, 2012 6:50 pm
by hunternet93 » Tue Nov 06, 2012 12:15 pm
If you have a laptop available, you can connect via Ethernet. You might be able to connect and complete the steps through WiFi if you skip the commands
Code: Select all
 sudo service hostapd start
sudo service udhcpd start

and then restart the Pi. After you reboot, the Pi should start broadcasting as a hotspot. If it doesn't you'll need to connect with Ethernet or connect to a monitor to see what went wrong.
Posts: 319
Joined: Mon Dec 12, 2011 4:34 pm
by poing » Tue Nov 06, 2012 3:20 pm
hunternet93 wrote:Hmm. Try running the following commands and posting the results:
Code: Select all
sudo service hostapd status
sudo service udhcpd status
sudo ifconfig
sudo iwconfig

The first two commands check if HostAPD and uDHPD are running, the second two give some information on your network interfaces. It's very possible I missed a step when writing the instructions, I wrote them during a break a work and haven't had time to verify them on a Pi yet.


I have two Ralink dongles now. I tried the sirlagz tutorial and had initial success where I could log into my Pi with my phone and see the webpage on the Pi (that's what I need), but then MySQL went corrupt. So I decided to install everything from scratch but now it won't work anymore :( After five tries I'm a bit disparate.

Anyway I tried this tutorial again. What I had to do was change
Code: Select all
DEAMON_CONF=""
into
Code: Select all
DEAMON_CONF="/etc/hostapd/hostapd.conf"
in the file /etc/init.d/hostapd otherwise hostapd wouldn't start.

Next I had to remove the line
Code: Select all
auth_algs=0

from /etc/hostapd/hostapd.conf for it was not allowed to have arguments.

That's where I am, I can see the Access Point but it refuses to give me an IP address, which is the same status I can reach with the sirlagz tutorial (after likewise editing as above, only then I need to change a "group" line in /etc/hostapd/hostapd.conf)

Here's the output from the requested commands:

Code: Select all
pi@raspberrypi ~ $ sudo service hostapd status
[ ok ] hostapd is running.
pi@raspberrypi ~ $ sudo service udhcpd status
Usage: /etc/init.d/udhcpd {start|stop|restart|force-reload}
pi@raspberrypi ~ $ sudo ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:13:26:2e 
          inet addr:192.168.1.123  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1302 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1086 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1140902 (1.0 MiB)  TX bytes:175176 (171.0 KiB)

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

mon.wlan0 Link encap:UNSPEC  HWaddr 00-0F-54-0A-AC-E2-00-00-00-00-00-00-00-00-00-00 
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:130 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:12684 (12.3 KiB)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr 00:0f:54:0a:ac:e2 
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:18 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:6196 (6.0 KiB)  TX bytes:6520 (6.3 KiB)

pi@raspberrypi ~ $ sudo iwconfig
lo        no wireless extensions.

wlan0     IEEE 802.11bgn  Mode:Master  Frequency:2.427 GHz  Tx-Power=20 dBm   
          Retry  long limit:7   RTS thr:off   Fragment thr:off
          Power Management:on
         
eth0      no wireless extensions.

mon.wlan0  IEEE 802.11bgn  Mode:Monitor  Tx-Power=20 dBm   
          Retry  long limit:7   RTS thr:off   Fragment thr:off
          Power Management:on
         
pi@raspberrypi ~ $


Hope someone can help.
Posts: 1099
Joined: Thu Mar 08, 2012 3:32 pm
by Sonny_Jim » Tue Nov 06, 2012 3:43 pm
Code: Select all
pi@raspberrypi ~ $ sudo service udhcpd status
Usage: /etc/init.d/udhcpd {start|stop|restart|force-reload}


It looks to me udhcpd isn't running, hence why no IP addresses are being given out. Try running udhcpd from the command line to make sure the configuration file is correct.

EDIT: Or just use static addresses if you can't get udhcpd to work. Or use dnsmasq as a dhcpd server.
Posts: 32
Joined: Tue Oct 23, 2012 4:15 pm