Turn your RaspberryPi into a WiFi Router!
How to set up a RASPBERRY PI as a wireless access Point.
I will be showing how to turn the Raspberry Pi into a wireless access point to which other devices can connect basically, we are turning the raspberry pi into a wireless “router”. I will also show us how to set up the wireless access point created to provide (share) internet access to(with) connected devices.
Here’s how I have done
Go to this link here to set up your raspberry pi. Once setup is done let’s begin creating Wi-Fi Hotspot with Raspberry Pi.
STEP-1:
Raspberry Pi OS Update
As usual, we update the raspberry pi to ensure we have the latest version of everything
sudo apt-get update
sudo apt-get upgrade
STEP-2:
Install Access Point Management Software Packages
To work as an access point, the Raspberry Pi needs to have some of the software packages to act as an access point.
Below commands will install the software that makes it possible to set up the pi as a wireless access point and also the software that helps assign a network address to devices that connect to the AP.
sudo apt install hostapd
sudo apt install dnsmasq
Finally, install netfilter-persistent
and its plugin iptables-persistent
. This utility helps by saving firewall rules and restoring them when the Raspberry Pi boots.
sudo DEBIAN_FRONTEND=noninteractive apt install -y netfilter-persistent iptables-persistent
Before going to the next step reboot raspberry pi.
sudo reboot
STEP-3:
Set up the Network Router
The Raspberry Pi will run and manage a standalone wireless network. It will also route between the wireless and Ethernet networks, providing internet access to wireless clients. Setting up the Raspberry Pi to act as a server requires us to assign a static IP address to the wireless port. This can be done by editing the dhcpcd
config file. To edit dhcpcd.conf
file gives the below command.
sudo nano /etc/dhcpcd.conf
Go to the end of the dhcpcd.conf
file and add the following lines
interface wlan0
static ip_address=192.168.4.1/24
nohook wpa_supplicant
STEP-4:
Enable Routing and IP Masquerading
To allow traffic to flow from one network to the other in the Raspberry Pi, create a file using the following command, with the contents below:
sudo nano /etc/sysctl.d/routed-ap.conf
File contents:
# Enable IPv4 routing
net.ipv4.ip_forward=1
Enabling routing will allow hosts from network 192.168.4.0/24
to reach the LAN and the main router towards the internet.
This process is configured by adding a single firewall rule in the Raspberry Pi
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Now save the current firewall rules for IPv4 (including the rule above) and IPv6 to be loaded at boot by the netfilter-persistent
service using the below command
sudo netfilter-persistent save
STEP-5:
Configure the DHCP and DNS services for the wireless network
The DHCP and DNS services are provided by dnsmasq
. The default configuration file serves as a template for all possible configuration options.
Rename the default configuration file and edit a new one
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo nano /etc/dnsmasq.conf
Add the following to the file and save it,
interface=wlan0
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
domain=wlan
address=/gw.wlan/192.168.4.1
dnsmasq.conf
To ensure WiFi radio is not blocked on your Raspberry Pi, execute the following command:
sudo rfkill unblock wlan
This setting will be automatically restored at boot time. We will define an appropriate country code in the access point software configuration.
STEP-6:
Configure the AP Software
Create the hostapd
configuration file, located at /etc/hostapd/hostapd.conf
, to add the various parameters for your new wireless network.
country_code=IN
interface=wlan0
ssid=NameOfNetwork
hw_mode=g
channel=7
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=PWD
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
NOTE :country_code
it configures the computer to use the correct wireless frequencies. See Wikipedia for a list of two-letter ISO 3166-1 country codes.
*SSID : Your SSID (my Case NameOfNetwork)
*PWD: Your Password (my Case PWD)
To effect the changes made to the Raspberry Pi, reboot the system.
sudo systemctl reboot
Once it comes back up, you should now be able to access the internet by connecting to the Wireless access point created by the Raspberry Pi.
Thanks for taking the time to read. Feedback and comments are always welcome.
Thank You for reading
Please give 👏🏻 Claps if you like the blog.
GEEKY BAWA
just a silly Geek who love to seek out new technologies and experience cool stuff.
Do Checkout My other Blogs
Do Checkout My Youtube channel
If you want to get in touch and by the way, you know a good joke you can connect with me on Twitter or LinkedIn.
Thanks for reading!😄 🙌
Connect with me on Twitter and LinkedIn
Do find time check out my other articles and further readings in the reference section. Kindly remember to follow me so as to get notified of my publications.
Made with ❤️by Vaibhav Hariramani
- If you enjoyed this, follow me on Medium for more
- Follow me on Kaggle for more content!
- Let’s connect on LinkedIn
- Interested in collaborating?
- Check out my website.
- Check out my other website.
Don’t forget to tag us
if you find this blog beneficial for you don’t forget to share it with your friends and mention us as well. And Don’t forget to share us on Linkedin, instagram, facebook , twitter, Github
More Resources
To learn more about these Resources you can Refer to some of these articles written by Me:-