By the end of this tutorial you will be able to access your Raspberry Pi 3 as Wi-Fi Hotpot. Before getting started please make sure that your module is ppp Internet connected. If not please follow the steps from tutorial 3.
Here we go;
1. Install required packages:
sudo apt-get install dnsmasq hostapd
2. You need to configure wlan0 with a static IP.
3. If your Raspberry Pi 3 is connected via Wi-Fi, connect it via Ethernet first.
4. Ignore wlan0. For this type
sudo nano /etc/dhcpcd.conf
which opens up dhcpcd configuration file, then add
at the end of it.
5. This step includes configuration of Static IP. Type
sudo nano /etc/network/interfaces
and add/edit wlan0 section to following configuration
iface wlan0 inet static
Next, we need to configure hostapd.
6. Create a new configuration file with
sudo nano /etc/hostapd/hostapd.conf
and add the following contents:
interface=wlan0 # This is the name of the WiFi interface we configured above
driver=nl80211 # Use the nl80211 driver with the brcmfmac driver
ssid=SIXFAB # This is the name of the network
hw_mode=g # Use the 2.4GHz band
channel=6 # Use channel 6
ieee80211n=1 # Enable 802.11n
wmm_enabled=1 # Enable WMM
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] # Enable 40MHz channels with 20ns guard interval
macaddr_acl=0 # Accept all MAC addresses
auth_algs=1 # Use WPA authentication
ignore_broadcast_ssid=0 # Require clients to know the network name
wpa=2 # Use WPA2
wpa_key_mgmt=WPA-PSK # Use a pre-shared key
wpa_passphrase=mypassword # The network passphrase
rsn_pairwise=CCMP # Use AES, instead of TKIP
7. Now open up the default configuration file typing
sudo nano /etc/default/hostapd
find the line
replace the line with
8. Present dnsmasq config file contains a bunch of informations about how to use it, but it’s majority is useless for us here. It is advised to not delete rather create a new configuration file.
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo nano /etc/dnsmasq.conf
Paste the following lines into the new file you have just created:
interface=wlan0 # Use interface wlan0
listen-address=172.24.1.1 # Explicitly specify the address to listen on
bind-interfaces # Bind to the interface to make sure we aren't sending things elsewhere
server=220.127.116.11 # Forward DNS requests to Google DNS
domain-needed # Don't forward short names
bogus-priv # Never forward addresses in the non-routed address spaces.
dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time
9. Now you will enable packet forwarding. For this, type
sudo nano /etc/sysctl.conf
to open sysctl.conf. Here find the line
And remove # sign from the beginning of the line.
10. Now reboot your Raspberry Pi
11. Now we will share our Raspberry Pi’s Internet Connection to the devices connected over the wifi. This needs configuration of NAT between wlan0 and ppp0 interfaces.
This step needs to be repeated every time you reboot the Raspberry Pi. To avoid it, run
sudo sh -c “iptables-save > /etc/iptables.ipv4.nat”
which saves the rules to a file /etc/iptables.ipv4.nat
As you will need to run this after each reboot, open the rc.local file typing
sudo nano /etc/rc.local
and just above the line exit 0,
add the following line:
iptables-restore < /etc/iptables.ipv4.nat
12. Start the services:
sudo service hostapd start
sudo service dnsmasq start
Now you will be able to connect to the Internet via Wi-Fi
I would like to thank Phil Martin for his tutorial using your new Raspberry Pi 3 as a WIFI access point with hostapd.[/vc_column_text][/vc_column][/vc_row]