Wifi Hotspot Web Server
Page 1 of 1
Wifi Hotspot Web Server
Using your Raspberry Pi as a Wireless Router and Web Server
Using your Raspberry Pi as a Wireless Router and Web Server
Posted by dconroy on Jul 18, 2013 in How To's, Raspberry Pi | 48 comments | 54,697 views
I got an email earlier in the week from some students at SoonChunHyang University, about 100km from Seoul, Korea. They are working on a project where they are using Raspberry Pi’s as a web server, but also wanted to be able to control the Pi’s via their smart phones and desktops. They ran into issues because they were using the (previously) unsupported WiFi Adapter (RTL8188CUS chipset) that I wrote about in this Raspberry Pi WiFi Hotspot post.
A computer science graduate myself, I offered to write a tutorial for them to help them out. This entire tutorial might not be relevant for everyone, but I cover a lot of issues that people struggle with.
I’ll begin with a fresh image of the Raspbian and just a regular ethernet cable to configure it. I’ve always recommended Raspbian because it is an optimized version of Debian built specifically for Raspberry Pi’s. The last stable downloads can be found here.
To flash your SD Card, you will need to unzip the image and write it your SD card using Win32DiskImager. This tool can also be used to after our initial setup to create an image of our finalized implementation(very useful as a backup).
After the image is flashed, you can boot your device. At this point you can use your HDMI Cable/Mouse/Keyboard for your initial configuration, or you can use an SSH Client like Putty to connect. The default hostname, login, and password are as follows:
host:raspberrypi
Username: pi
Password: raspberry
For this tutorial, I will be using putty. On first boot, you will be prompted with a configuration tool called Raspi-Config. If the raspi-config doesnt load automatically, just enter the following command from the shell to get started.
The settings I recommend you update are
After you finish your changes to the raspi-config, you should reboot your pi using the following command:
At this point we have a fully functional linux server, but we still need to install apache and get the hotspot/routing functions working. The first part is pretty easy. Run the following commands from the shell to install Apache.
The location of the Apache configuration file is
I believe this is what the students at SoonChunHyang already have working. But, they want to be able to access this web server over a WiFi Hotspot running on the same Raspberry Pi. In order to do this, we need to install hostapd.
The following steps are only for people who have WiFi adapters with the RTL8188CUS Chipset, if you don’t, please skip ahead to the section titled configuring Hostapd.
I believe the whole crux of their problem so far is that it is the apt hosted copy of hostapd is not compatible with the RTL8188CUS chipset they are using. But, thanks to the Edimax team, I’ve got a replacement hostapd binary to resolve this issue. I don’t think they will be able to get this working without it.
To download and replace the installed binary version of hostapd we just installed, they need to issue the following commands:
with the following contents:
In previous tutorials, I have used bridge-utils here to help bridge the connection between the interfaces wlan0 and eth0, but in this case we want the wireless card and rPi to handle the routing and dhcp. So , we may be able to connect to the access point, but we won’t get an IP just yet. To do that, we need to define a subnet for our wireless card.
and add the following 3 lines
Then we have to enable dhcp on the pi for this network so that any devices that connect can get an IP addresss
and make sure you have the following contents:
At this point we should reboot to test HostAPD and DHCP.
After the rPi comes back up, start hostapd in the background, then reboot the dhcp server
At this point you should be able to join the wireless network, get an IP, and also hit the local apache web server. If it connects, we will want to start this wireless access point on boot with the following commands
and uncommenting and updating the following line
There is only one problem remaining. The clients who have connected to your access point can not get further than your Raspberry Pi, therefore have no internet access.
To solve this, we need to enable IP forwarding on the rPi. You can not reboot at this point forward or all future changes will be lost. To save time, we are going to run the final commands as root.
Then, update /etc/sysctl.conf and uncomment this line
The final step is to insert an iptables rule to allow NAT. (eth0 being the interface which is connected to the internet)
We also need to save these IP Table settings so they are enabled every time you boot the rPi. To save these settings to a file, use the following command.
To load them at boot, we need to create a script in /etc/network/if-pre-up.d/
with the following contents:
And we are done! When you reboot your Raspberry Pi should be working as an Access Point, a Web Server, a DHCP Server, and an Internet Ready Router!
Originally Found @
http://www.daveconroy.com/using-your-raspberry-pi-as-a-wireless-router-and-web-server
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Another site guide
1. The very first thing to do is to check if the dongle is being detected.Fire up the terminal and type :-
lsusb
If any adapter is detected you should get a message like this:-
Bus 001 Device 005: ID 07d1:3c09 D-Link System DWA-140 RangeBooster N Adapter(rev.B1) [Ralink RT2870]
2.Now you'll need to install the "iw" tool to check which modes are supported by your wireless dongle. Open the terminal and type:-
sudo apt-get install iw
After installation enter iw list. At this point you will see a bunch of specs being printed and some place in the middle you might find something similar to this (the modes beneath are the ones of my dongle that I am utilizing):-
Supported interface modes:
* IBSS
* managed
* AP
* AP/VLAN
* WDS
* monitor
* mesh point
Depending on the support of AP option you can continue going.
3. Next step is to install "hostapd" and "udhcpd" :-
sudo apt-get install hostapd udhcpd
4. Next we need to configure DHCP so that the Raspberry Pi can distribute IP to the clients. Edit the file /etc/udhcpd.conf with following information:-
start 192.168.42.2 # This is the range of IPs that the hostspot will give to client devices.
end 192.168.42.20
interface wlan0 # The device uDHCP listens on.
remaining yes
opt dns 8.8.8.8 4.2.2.2 # The DNS servers client devices will use.
opt subnet 255.255.255.0
opt router 192.168.42.1 # The Pi's IP address on wlan0 which we will set up shortly.
opt lease 864000 # 10 day DHCP lease time in seconds.
5. Next step is to edit the file /etc/default/udchpd and change the line DHCPD_ENABLED="no" to DHCPD_ENABLED="yes"
6. Assign a static IP by entering the following command: sudo ifconfig wlan0 192.168.42.1
To set this up automatically you must edit the file /etc/network/interfaces and replace the line "iface wlan0 inet dhcp" to:
iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0
If the line "iface wlan0 inet dhcp" does not exist, include the below lines at thebottom part of the file. You will additionally need to update the lines-
allow-hotplug wlan0
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet manual
to
allow-hotplug wlan0
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet manual
7. In order to create network we need to configure hostapd. It can be either an open network or a WPA- secured network for authorized access only.You need to create or edit some files accordingly. The first file that needs to be edited/created is "/etc/hostapd/hostapd.conf". For a WPA-secured network make it look like this:-
interface=wlan0
driver=nl80211
ssid=My_AP
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=My_Passphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
To create an open network enter the following text in the file instead:-
interface=wlan0
ssid=My_AP
hw_mode=g
channel=6
auth_algs=1
wmm_enabled=0
8. Next step is to change a variable inside the file /etc/default/hostapd so that it points to the file that has been just created/edited. Change this line: DAEMON_CONF="" to DAEMON_CONF="/etc/hostapd/hostapd.conf"
9. The next thing to do is to configure NAT (Network Address Translation) which is a technique that allows several devices to use a single connection to the internet. Edit the file /etc/sysctl.conf and add the following line to the end of the file:
net.ipv4.ip_forward=1
It will enable NAT in the kernel. Now, run the following commands:
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 this concludes the NAT configuration. To make it permanent so you don't have to run the commands after each reboot, run the command
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
and edit the file /etc/network/interfaces and add the following lines to the end of the file:
up iptables-restore < /etc/iptables.ipv4.nat
10. Almost done! Run the following commands to start the Access Point:-
sudo service hostapd start
sudo service udhcpd start
And your Pi should finally be hosting a wireless hotspot! To get it to start on boot everytime, run these two last commands:
sudo update-rc.d hostapd enable
sudo update-rc.d udhcpd enable
And you're done! If you followed every step correctly everything should be working as expected :-)
http://www.rpiblog.com/2012/12/turn-raspberry-pi-into-wireless-access.html
Using your Raspberry Pi as a Wireless Router and Web Server
Posted by dconroy on Jul 18, 2013 in How To's, Raspberry Pi | 48 comments | 54,697 views
I got an email earlier in the week from some students at SoonChunHyang University, about 100km from Seoul, Korea. They are working on a project where they are using Raspberry Pi’s as a web server, but also wanted to be able to control the Pi’s via their smart phones and desktops. They ran into issues because they were using the (previously) unsupported WiFi Adapter (RTL8188CUS chipset) that I wrote about in this Raspberry Pi WiFi Hotspot post.
A computer science graduate myself, I offered to write a tutorial for them to help them out. This entire tutorial might not be relevant for everyone, but I cover a lot of issues that people struggle with.
- -Setting up a DHCP Server
- -Setting up a Wireless Access Point
- -Setting up an rPi as a Router
- -Enabling IP Forwarding
I’ll begin with a fresh image of the Raspbian and just a regular ethernet cable to configure it. I’ve always recommended Raspbian because it is an optimized version of Debian built specifically for Raspberry Pi’s. The last stable downloads can be found here.
To flash your SD Card, you will need to unzip the image and write it your SD card using Win32DiskImager. This tool can also be used to after our initial setup to create an image of our finalized implementation(very useful as a backup).
After the image is flashed, you can boot your device. At this point you can use your HDMI Cable/Mouse/Keyboard for your initial configuration, or you can use an SSH Client like Putty to connect. The default hostname, login, and password are as follows:
host:raspberrypi
Username: pi
Password: raspberry
For this tutorial, I will be using putty. On first boot, you will be prompted with a configuration tool called Raspi-Config. If the raspi-config doesnt load automatically, just enter the following command from the shell to get started.
sudo raspi-config |
The usual distribution images are 2 GB. When you copy the image to a larger SD card you have a portion of that card unused. expand_rootfs expands the initial image to expand to fill the rest of the SD card, giving you more space. By default, 64mb is reserved for the Graphical UI. Since we plan on using this as a web server, I reduce this to 32mb with the memory_split command.
- Code:
update
expand_rootfs
change_pass
change_timezone
memory_split
After you finish your changes to the raspi-config, you should reboot your pi using the following command:
sudo shutdown -r now |
sudo apt-get update sudo apt-get install apache2 |
After this is completed, give it a try! Navigate to the IP or Hostname of your Rasberry Pi in your browser, and you should see the Apache Splash “It works!” Screen.
- Code:
/etc/apache2/apache2.conf
I believe this is what the students at SoonChunHyang already have working. But, they want to be able to access this web server over a WiFi Hotspot running on the same Raspberry Pi. In order to do this, we need to install hostapd.
sudo apt-get install hostapd |
I believe the whole crux of their problem so far is that it is the apt hosted copy of hostapd is not compatible with the RTL8188CUS chipset they are using. But, thanks to the Edimax team, I’ve got a replacement hostapd binary to resolve this issue. I don’t think they will be able to get this working without it.
To download and replace the installed binary version of hostapd we just installed, they need to issue the following commands:
wget http://www.daveconroy.com/wp3/wp-content/uploads/2013/07/hostapd.zip unzip hostapd.zip sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.bak sudo mv hostapd /usr/sbin/hostapd.edimax sudo ln -sf /usr/sbin/hostapd.edimax /usr/sbin/hostapd sudo chown root.root /usr/sbin/hostapd sudo chmod 755 /usr/sbin/hostapd |
Configuring Hostapd
Now that we’ve updated the binary copy of hostapd, we need to configure it. To do so, create the following filesudo nano /etc/hostapd/hostapd.conf |
- Code:
interface=wlan0
driver=rtl871xdrv
ssid=DaveConroyPi
channel=6
wmm_enabled=1
wpa=1
wpa_passphrase=0000000000
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
auth_algs=1
macaddr_acl=0
In previous tutorials, I have used bridge-utils here to help bridge the connection between the interfaces wlan0 and eth0, but in this case we want the wireless card and rPi to handle the routing and dhcp. So , we may be able to connect to the access point, but we won’t get an IP just yet. To do that, we need to define a subnet for our wireless card.
sudo nano /etc/network/interfaces |
iface wlan0 inet static
address 10.10.0.1
netmask 255.255.255.0
Then we have to enable dhcp on the pi for this network so that any devices that connect can get an IP addresss
sudo apt-get install isc-dhcp-server |
sudo nano /etc/dhcp/dhcpd.conf |
- Code:
authoritative; #be careful with this setting
ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
- Code:
#for the wireless network on wlan0
subnet 10.10.0.0 netmask 255.255.255.0 {
range 10.10.0.25 10.10.0.50;
option domain-name-servers 8.8.8.8, 8.8.4.4;
option routers 10.10.0.1;
interface wlan0;
}
At this point we should reboot to test HostAPD and DHCP.
sudo reboot |
sudo hostapd -B /etc/hostapd/hostapd.conf sudo /etc/init.d/isc-dhcp-server restart |
sudo nano /etc/default/hostapd |
So, if you have followed these steps correctly, you can now provide DHCP servers to any clients, and also allow serve those clients your Apache web pages.
- Code:
DAEMON_CONF="/etc/hostapd/hostapd.conf"
There is only one problem remaining. The clients who have connected to your access point can not get further than your Raspberry Pi, therefore have no internet access.
To solve this, we need to enable IP forwarding on the rPi. You can not reboot at this point forward or all future changes will be lost. To save time, we are going to run the final commands as root.
sudo su echo 1 > /proc/sys/net/ipv4/ip_forward |
nano /etc/sysctl.conf |
Save the file.
- Code:
net.ipv4.ip_forward=1
The final step is to insert an iptables rule to allow NAT. (eth0 being the interface which is connected to the internet)
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE |
iptables-save > /etc/iptables.up.rules |
nano /etc/network/if-pre-up.d/iptables |
Then, verify the permissions so that it will start on boot.iptables-restore < /etc/iptables.up.rules exit 0
- Code:
#!/bin/sh
#This script restores iptables upon reboot
chown root:root /etc/network/if-pre-up.d/iptables chmod +x /etc/network/if-pre-up.d/iptables chmod 755 /etc/network/if-pre-up.d/iptables |
Originally Found @
http://www.daveconroy.com/using-your-raspberry-pi-as-a-wireless-router-and-web-server
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Another site guide
1. The very first thing to do is to check if the dongle is being detected.Fire up the terminal and type :-
lsusb
If any adapter is detected you should get a message like this:-
Bus 001 Device 005: ID 07d1:3c09 D-Link System DWA-140 RangeBooster N Adapter(rev.B1) [Ralink RT2870]
2.Now you'll need to install the "iw" tool to check which modes are supported by your wireless dongle. Open the terminal and type:-
sudo apt-get install iw
After installation enter iw list. At this point you will see a bunch of specs being printed and some place in the middle you might find something similar to this (the modes beneath are the ones of my dongle that I am utilizing):-
Supported interface modes:
* IBSS
* managed
* AP
* AP/VLAN
* WDS
* monitor
* mesh point
Depending on the support of AP option you can continue going.
3. Next step is to install "hostapd" and "udhcpd" :-
sudo apt-get install hostapd udhcpd
4. Next we need to configure DHCP so that the Raspberry Pi can distribute IP to the clients. Edit the file /etc/udhcpd.conf with following information:-
start 192.168.42.2 # This is the range of IPs that the hostspot will give to client devices.
end 192.168.42.20
interface wlan0 # The device uDHCP listens on.
remaining yes
opt dns 8.8.8.8 4.2.2.2 # The DNS servers client devices will use.
opt subnet 255.255.255.0
opt router 192.168.42.1 # The Pi's IP address on wlan0 which we will set up shortly.
opt lease 864000 # 10 day DHCP lease time in seconds.
5. Next step is to edit the file /etc/default/udchpd and change the line DHCPD_ENABLED="no" to DHCPD_ENABLED="yes"
6. Assign a static IP by entering the following command: sudo ifconfig wlan0 192.168.42.1
To set this up automatically you must edit the file /etc/network/interfaces and replace the line "iface wlan0 inet dhcp" to:
iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0
If the line "iface wlan0 inet dhcp" does not exist, include the below lines at thebottom part of the file. You will additionally need to update the lines-
allow-hotplug wlan0
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet manual
to
allow-hotplug wlan0
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet manual
7. In order to create network we need to configure hostapd. It can be either an open network or a WPA- secured network for authorized access only.You need to create or edit some files accordingly. The first file that needs to be edited/created is "/etc/hostapd/hostapd.conf". For a WPA-secured network make it look like this:-
interface=wlan0
driver=nl80211
ssid=My_AP
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=My_Passphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
To create an open network enter the following text in the file instead:-
interface=wlan0
ssid=My_AP
hw_mode=g
channel=6
auth_algs=1
wmm_enabled=0
8. Next step is to change a variable inside the file /etc/default/hostapd so that it points to the file that has been just created/edited. Change this line: DAEMON_CONF="" to DAEMON_CONF="/etc/hostapd/hostapd.conf"
9. The next thing to do is to configure NAT (Network Address Translation) which is a technique that allows several devices to use a single connection to the internet. Edit the file /etc/sysctl.conf and add the following line to the end of the file:
net.ipv4.ip_forward=1
It will enable NAT in the kernel. Now, run the following commands:
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 this concludes the NAT configuration. To make it permanent so you don't have to run the commands after each reboot, run the command
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
and edit the file /etc/network/interfaces and add the following lines to the end of the file:
up iptables-restore < /etc/iptables.ipv4.nat
10. Almost done! Run the following commands to start the Access Point:-
sudo service hostapd start
sudo service udhcpd start
And your Pi should finally be hosting a wireless hotspot! To get it to start on boot everytime, run these two last commands:
sudo update-rc.d hostapd enable
sudo update-rc.d udhcpd enable
And you're done! If you followed every step correctly everything should be working as expected :-)
http://www.rpiblog.com/2012/12/turn-raspberry-pi-into-wireless-access.html
Similar topics
» HT WPS WIFI HACKING
» Wifi Hackinh Tuts
» Your Raspberry Captive Portal For WIFI
» Kali Wifi Cracking & Hacking Example
» WIFI USB cards alternative to Airpcap
» Wifi Hackinh Tuts
» Your Raspberry Captive Portal For WIFI
» Kali Wifi Cracking & Hacking Example
» WIFI USB cards alternative to Airpcap
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum