WIFI AP using Raspberry Pi:
Current experiment is to create a Wi-Fi zone using Raspberry Pi. We will make use of Raspberry Pi and turn it into a router. We can connect to internet on other devices using new WIFI zone. I have done by following the below steps. This is a simple process to follow and in creating a customized WIFI.
Initially I have updated the current version of packages using sudo apt-get update
Now we need to install host access software into Pi. For this I have used "hostap" package in Raspberry Pi.
sudo apt-get install hostapd isc-dhcp-server
Next step is setting DHCP server on Pi. For this we need to modify the existing files. Open the file dhcpd.conf
sudo nano /etc/dhcp/dhcpd.conf
We have 3 things to do here
1) Comment the below lines in file:
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
2) Uncomment the following line of code in file:
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
3) Add the following code at bottom of the page:
subnet 192.168.42.0 netmask 255.255.255.0 {
range 192.168.42.10 192.168.42.50;
option broadcast-address 192.168.42.255;
option routers 192.168.42.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "local";
option domain-name-servers 8.8.8.8, 8.8.4.4;
}
after completeing above 3 steps save the file and return.
Next open the file isc-dhcp-server
Find the following line in file INTERFACES="" and update this to INTERFACES="wlan0"
Save the file and return
Make sure that wlan0 is not active. Make it inactive using command
sudo ifdown wlan0
Next we will set up the wlan0 connection to be static and incoming.
run sudo nano /etc/network/interfaces to edit the file
Find the line "auto wlan0" and comment it, if it is in the file. Comment each line after the current line also.
add the below lines into the file
iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0
Save the file and return.
Assign a static IP address to the wifi adapter by running
sudo ifconfig wlan0 192.168.42.1
Now setting password for the network. For this we need to create a file and write into it. I am setting my password as Bhargav
create file using command
sudo nano /etc/hostapd/hostapd.conf
Write the following code into file :
interface=wlan0
driver=rtl871xdrv
ssid=Pi_AP
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=Bhargav
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
save the file and return
Now we need to setup configuration file for Raspberry Pi.
Run sudo nano /etc/default/hostapd
Find the line #DAEMON_CONF="" and edit it so it says DAEMON_CONF="/etc/hostapd/hostapd.conf"
Save the file and return
Configure Network Address Translation
This will allow multiple clients to connect to the WIFI network. Open the file "sysctl.conf" using the following command sudo nano /etc/sysctl.conf
At bottom of the file add line. This will start IP forwarding on boot up
net.ipv4.ip_forward=1
Save the file and return
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
Run the following commands to create the network translation between the ethernet port eth0 and the wifi port wlan0
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
Now changing the configuration so that WIFI connection is ready on startup. Run the following command
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
Open the file iptables.ipv4.nat using command
sudo nano /etc/network/interfaces
add the below line at end of file
up iptables-restore < /etc/iptables.ipv4.nat
Save the file and return
Updating the software so that the WIFI hardware is supported. Follow the below steps to setup software
To download
wget http://adafruit-download.s3.amazonaws.com/adafruit_hostapd_14128.zip
To install
unzip adafruit_hostapd_14128.zip
sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG
sudo mv hostapd /usr/sbin
Give permission for execution
sudo chmod 755 /usr/sbin/hostapd
WIFI zone on every restart
Now we are all set to set our own WIFI using Raspberry Pi. This can be hosted using following command
sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf
This displays the name of your WIFI on other devises. You can select the newly created WIFI and connect to it using the password.
Here are the images of my WIFI zone.
This images shows the list of available WIFI networks. "BHARGAV-AP" is my WIFI.
This image shows that I have conected to my WIFI on my mobile.
This image is to show that Arduino client is able to access the WIFI created using Raspberry Pi. This is showing the available WIFI which could be accessible.
This images shows that Arduino client is able to connect to the newly created WIFI.
Reference:
https://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point/install-software
No comments:
Post a Comment