raspberry pi wifi access point
raspberry pi, tutorial

How turn your raspberry pi into a wifi access point in 2 minutes

0
0 Flares Twitter 0 Facebook 0 Google+ 0 Pin It Share 0 Filament.io 0 Flares ×

 

For many reasons, it can be quite handy to turn your pi into a wifi access point, specially if you power it with a battery, using it in mobile, it allows you to ssh it from your mobile

So here is a quick tutorial about how turn your raspberry pi into a working wifi access point

As OS i am using raspbian on my PI, you can download it and find install guide here:

http://www.raspbian.org/

First you need to install some packages

sudo apt-get install hostapd udhcpd

then configure dhcp, edit  /etc/udhcpd.conf  as follow:

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

then in /etc/default/udhcpd change

DHCPD_ENABLED="no" to
#DHCPD_ENABLED="no"

now gives a static ip to your pi, for example sudo ifconfig wlan0 192.168.2.1
and for have the ip automatic at boot, in /etc/network/interfaces replace the line ifacewlan0 inet dhcp
by:
iface wlan0 inet static
  address 192.168.42.1
  netmask 255.255.255.0
If the line "iface wlan0 inet dhcp" is not present, add the above lines to the bottom of the file
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 dhcp

now configure or create /etc/hostapd/hostapd.conf, Change ssid=, channel=, and wpa_passphrase= to values of your choice
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
/etc/default/hostapd and change the line
#DAEMON_CONF="" to DAEMON_CONF="/etc/hostapd/hostapd.conf"

Now time to configure NAT

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
To set this up automatically on boot, edit the file /etc/sysctl.conf and add the following line:
net.ipv4.ip_forward=1
Second, to enable NAT in the kernel, 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

Your Pi is now NAT-ing. To make this permanent:

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

Now edit the file /etc/network/interfaces and add the following line to the bottom of the file:

up iptables-restore 
                      
sudo service hostapd start

sudo service udhcpd start
Your Pi should now be hosting a wireless hotspot. To get the hotspot to start on boot, run these additional commands:
sudo update-rc.d hostapd enable
sudo update-rc.d udhcpd enable

                      

                      
                    

About the author / 

nocomp

access access point pi point raspberry raspberry pi tutorial wifi

Leave a reply

Your email address will not be published. Required fields are marked *