26.02.2017: Howto tested & working š
Today, we will look at howto create AP hotspot on Raspberry Pi usingĀ Ralink RT5370 chipset (see previous article).
First step should be update your repositories and update system to lastest:
sudo aptitude update; sudo aptitude -y upgrade
Then, reboot will be good thing to do..
sudo shutdown -r now
After boot, login, run sudo su – and lsusb command and you should see something like this:
pi@raspberrypi ~ $ sudo su - root@raspberrypi:~# lsusb Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. Bus 001 Device 004: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter
Install hostapd and dnsmasq:
aptitude install hostapd dnsmasq
Edit file with network settings to some static IP of wlan0:
nano /etc/network/interfaces
And wlan0 section should like:
allow-hotplug wlan0 iface wlan0 inet static address 192.168.100.1 netmask 255.255.255.0 #wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf iface default inet manual
(close nano with Ctrl+X, then Y and Enter)
After that, get down and up wlan0 interface and check, if you have your IP set it up on interface
ifdown wlan0; ifup wlan0 ifconfig wlan0 # this command should wrote these informations # as you can see, there is right IP wlan0 Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx inet addr:192.168.100.1 Bcast:192.168.100.255 Mask:255.255.255.0 UP BROADCAST MULTICAST MTU:1500 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:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Create new configuration for hostapd in /etc/hostapd/hostapd.conf and put there this info:
# you can create it with command nano /etc/hostapd/hostapd.conf #write info below into file interface=wlan0 driver=nl80211 ssid=RaspberryPi_AP hw_mode=g channel=6 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=Your_fav_super_password wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
Edit files /etc/default/hostapd and uncomment DAEMON_CONF, and add path to config. So line will looks like this:
DAEMON_CONF="/etc/hostapd/hostapd.conf"
Then, you can finally restart hostapd, and you have your hotspot up and running.
/etc/init.d/hostapd restart # allow hostapd after boot update-rc.d hostapd enable
Your hotspot is running, but you need to run some DHCP client for your clients which will use your hotspot. Edit and change these parameters in dnsmasq (and restart it):
#edit dnsmasq by following command nano /etc/dnsmasq.conf #find and change following parameters.. (or you can add these on end of the file interface=wlan0Ā except-interface=eth0 dhcp-range=192.168.100.2,192.168.100.150,255.255.255.0,12h # restart dnsmasq /etc/init.d/dnsmasq restart # allow dnsmasq after boot update-rc.d dnsmasq enable
Then, you need to do NAT.. so..
#edit file /etc/sysctl.conf and uncomment this line net.ipv4.ip_forward=1 # run this command to load it sysctl -p #run these command for allow forwarding.. iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT # save iptables to file which will load after start iptables-save > /etc/iptables.nat # create file with forwarding in /etc/network/if-up.d echo '#!/bin/bash' > /etc/network/if-up.d/forwarding; echo 'iptables-restore < /etc/iptables.nat' >> /etc/network/if-up.d/forwarding; chmod +x /etc/network/if-up.d/forwarding
I found problem after reboot (and hostapd start) that wlan0 doesnt have IP assigned. You can solve it by chage fileĀ /etc/default/ifplugd and change it like this:
INTERFACES="eth0" HOTPLUG_INTERFACES="eth0" ARGS="-q -f -u0 -d10 -w -I" SUSPEND_ACTION="stop"
Source:Ā http://elinux.org/RPI-Wireless-Hotspot
Help with hostapd and IP:Ā http://sirlagz.net/2013/02/10/how-to-use-the-raspberry-pi-as-a-wireless-access-pointrouter-part-3b/