In this tutorial, we will show y'all how to gear up upwardly make an ethernet router that provides internet access to other ethernet devices using WiFi bridge,For this purpose we will be using a library called DNSMASQ which acts every bit both a DHCP server and DNS proxy(Don't worry if you don't know what these terms are. We volition discuss this before long).

Unlike our previous blog mail where nosotros jump straight to the instructions on how to do a job, we will explain why nosotros accept to make a WiFi Bridge which shares internet to the ethernet port

Objectives of creating WiFi Bridge using Raspberry PI

Giving internet connexion to connected devices, especially the devices which rely on the Cyberspace for data communication, or to send and receive information to a server is like giving oxygen to a patient. It's a life-sustaining raw material for such devices. If such devices are having an ethernet port, and so you take to provide a router or modem with Broadband/Optical Fibre connectivity. This is not always an pick in case you don't desire a permanent network connexion, or such service providers are not available in your expanse.

Too, nowadays we all have an net connection available in our mobile phones and tin can share the network connectivity to other wifi devices by creating wifi hotspots. But in the devices must have WiFi chip for receiving the net service through the hotspot access which you tin can provide easily. Hither comes our solution for the ethernet only devices. We could receive the internet connectedness using Raspberry Pi WiFi and share the internet from Raspberry Pi WiFi to its ain ethernet port so that the devices connected to the ethernet port of Raspberry Pi too get the network connection. Also, multiple devices can also exist connected using Ethernet switches. A representational diagram tin be constitute beneath.

Figure here

So nosotros can summarise the objectives as beneath

i Become an net connectedness to ethernet only devices, using any WiFi admission point.

two Interconnect various ethernet devices to make a cluster, for making devices even smarter.

three Raspberry Pi, can act as a data collection last which stores the data temporarily from the devices and push button that to the server when an cyberspace connection is attainable through its wifi.(This requires some code running in RPI as per the requirement)

You will need to keep in listen that the speed of the shared net may not be equally skillful as that of a router, as at that place can be bandwidth limitation of WiFi, as well as the processing adequacy of our Raspberry Pi router.

To follow along with this tutorial you would need the following hardware with you.

Equipment List

Beneath are all the bits and pieces that I used for this Raspberry Pi WiFI bridge tutorial, you will need A Wireless internet connection to be able to complete this tutorial.

Recommended

  • Raspberry Pi iii or 4
  • Micro SD Card
  • Ethernet Cable
  • Raspberry Pi Ability supply
  • Whatsoever ethernet device (It tin exist your desktop PC or Laptop besides)

Optional

  • Raspberry Pi Case

Introduction

What is Dnsmasq

Dnsmasq is a lightweight, just efficient library which acts as a DNS server, a DHCP server with support for DHCPv6 and PXE, and a TFTP server. It is designed to accept a small footprint and retentivity overhead, suitable for resource-express routers and firewalls. Dnsmasq tin likewise be configured as a DNS cache for improved DNS lookup speeds to previously visited sites. Basically, DNSMasq gives the router some advanced enterprise functionality - caching DNS records locally so yous have a faster browsing experience. For beginners, reading this stanza will be like seeing greek and roman. We will explicate the import terminology below for amend understanding.

DHCP server : A DHCP Server is a network server that automatically provides and assigns IP addresses, default gateways and other network parameters to client devices. It relies on the standard protocol known as Dynamic Host Configuration Protocol or DHCP to respond to circulate queries by clients. In other words, since the Dnsmasq is running in RPI, our RPI will be acting as a DHCP server over the ethernet, which leases IP addresses to the connected devices in the ethernet port just like any other router. Thus the devices and RPI forms a LAN network of its ain with RPI acting as the router.

DNS server : A DNS server is a computer server that contains a database of public IP addresses and their associated hostnames, and in near cases serves to resolve, or translate, those names to IP addresses as requested. DNS servers run special software and communicate with each other using special protocols. Storing all address resolution rules(ip and domain mapping) is impossible for a small device similar RPI. Instead of that, the DNS queries will be proxied to a true updated DNS server such as Google DNS using the Dnsmasq library.

Setting upward WiFi Bridge

To fix the Raspberry Pi Wifi bridge we will be utilizing the Dnsmasq packet, this package handles most of the grunt work for this tutorial.

With the capability of Dnsmasq as discussed above, nosotros tin can configure and run this package in a Raspberry Pi so that we can assign IP addresses and process DNS requests through the Raspberry Pi itself and brand our little Raspberry Pi human action equally a router.

There are any alternative libraries which provide the similar functionality of Dnsmasq, only one of the bonuses to utilizing Dnsmasq is that it is very like shooting fish in a barrel to configure while being somewhat lightweight in comparison to the isc-dhcp-server and bind9 packages.

Remember for this tutorial y'all volition need to accept an active WiFi router/ WiFi hotspot/WiFi admission betoken to connect to and an ethernet device you intend on bridging the Wi-Fi connectedness.

Step 1 . Before we go started with installing and setting up our packages, we volition starting time run an update on the Raspberry Pi past entering the following two commands into the terminal.

sudo apt-get update

sudo apt-get upgrade

Step two . With that done nosotros can now install the one and only parcel we will be utilizing, run the post-obit command to install dnsmasq.

sudo apt-become install dnsmasq

Pace three . Earlier nosotros go too far alee of ourselves, nosotros should fix the wlan0 connexion that we plan on using. If you have already set upwardly your wireless connection so y'all can skip ahead to step 5.

Otherwise open up the wpa_supplicant file by running the following command:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Pace 4 . Inside this file add the post-obit, making sure you supplant the SSID with the name of the network you desire to connect to and replace the psk value with the password for that network.

network={

        ssid="networkname"

        psk="networkpassword"

}

Footstep 5 . With the wireless network now setup to correctly connect nosotros can proceed with setting upwards our eth0 interface. This will basically strength it to use a static IP accost, not setting this up can cause several issues.

To practise this we need to modify the dhcpcd.conf file by running the following command:

sudo nano /etc/dhcpcd.conf

 Important Note: If you're on Raspbian stretch then wlan0 and eth0 may need to be changed if predictable network names is turned on. Use the ifconfig control to see the new names, they're probable quite long and will contain the MAC address.

Make sure you lot update these for all the commands in this tutorial.

Footstep 6 . Within this file we demand to add together the following lines, make certain you replace eth0 with the correct interface of your ethernet.

interface eth0

static ip_address=192.168.220.1/24

static routers=192.168.220.0

Now we can salve and quit out of the file past pressing Ctrl+X then pressing Y and and then Enter.

Footstep 7 . With our changes made to dhcpcd configuration we should now restart the service by running the post-obit command:

sudo service dhcpcd restart

Step 8 . Before we go started with modifying dnsmasq's configuration we will first brand a backup of the original configuration by running the following command.

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig

Step 9 . With the original configuration at present backed up and moved out of the mode, we can now move on and create our new configuration file by typing the command beneath into the concluding.

sudo nano /etc/dnsmasq.conf

Step 10. Now that we have our new file created we want to add together the lines below, these lines basically tell the dnsmasq parcel how to handle DNS and DHCP traffic.

interface=eth0                            # Use interface eth0

listen-address=192.168.220.one   # Specify the address to heed on

bind-interfaces                           # Bind to the interface

server=8.8.8.8                           # Use Google DNS

domain-needed                         # Don't forward brusk names

bogus-priv                                 # Drib the non-routed address spaces.

dhcp-range=192.168.220.l,192.168.220.150,12h # IP range and lease fourth dimension

Now we tin can salve and quit out of the file by pressing Ctrl+Xthen pressing Y and so Enter.

Step eleven . We now need to configure the Raspberry Pi's firewall so that it will forward all traffic from our eth0 connection over to our wlan0 connectedness. Before we do this we must kickoff enable ipv4p IP Forwarding through the sysctl.conf configuration file, so permit's begin editing it with the following control:

sudo nano /etc/sysctl.conf

Step 12 . Within this file you need to find the post-obit line, and remove the # from the beginning of information technology.

Find:

#net.ipv4.ip_forward=ane

Replace with:

net.ipv4.ip_forward=ane

Now nosotros can salvage and quit out of the file by pressing Ctrl+Ten so pressing Y and then Enter.

Stride 13 . Now since nosotros don't want to have to wait until the next reboot before the configuration is loaded in, we tin run the following command to enable information technology immediately.

sudo sh -c "echo one > /proc/sys/net/ipv4/ip_forward"

Step 14. Now that IPv4 Forwarding is enabled we can reconfigure our firewall so that traffic is forwarded from our eth0 interface over to our wlan0 connectedness. Basically this ways that anyone connecting to the ethernet will exist able to utilize our wlan0 internet connexion.

Run the following commands to add our new rules to the iptable:

sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

sudo iptables -A FORWARD -i wlan0 -o eth0 -k country --state RELATED,ESTABLISHED -j Accept

sudo iptables -A Forrad -i eth0 -o wlan0 -j Accept

Note: If you lot become errors when entering the above lines simply reboot the Pi using sudo reboot.

Step 15 . Of course iptables are flushed on every boot of the Raspberry Pi so we will need to save our new rules somewhere so they are loaded back in on every boot.

To save our new ready of rules run the following control.

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

Stride 16 . Now with our new rules safely saved somewhere nosotros need to brand this file be loaded back in on every reboot. The most unproblematic way to handle this is to modify the rc.local file.

Run the following command to begin editing the file.

sudo nano /etc/rc.local

Step 17 . Now nosotros are in this file, we need to add the line beneath. Make sure this line appears higher up exit 0. This line basically reads the settings out of our iptables.ipv4.nat file and loads them into the iptables.

Find:

go out 0

Add Higher up:

iptables-restore < /etc/iptables.ipv4.nat

Now we can save and quit out of the file by pressing Ctrl+X and then pressing Y and then Enter.

Step 18 . Finally all nosotros need to do is start our dnsmasq service. To do this, all yous demand to practice is run the following command:

sudo service dnsmasq start

Stride 19 . Now y'all should finally have a fully operational Raspberry Pi WiFi Span, y'all can ensure this is working by plugging whatever device into its Ethernet port, the bridge should provide an net connection to the device you plug it into.

To ensure everything volition run smoothly, it'southward best to endeavour rebooting now. This volition ensure that everything will successfully re-enable when the Raspberry Pi is started support. Run the following command to reboot the Raspberry Pi:

sudo reboot

Hope yous savor this tutorial. Happy hacking...