Connect to the Internet via Ethernet via WiFi (2023)

In this tutorial, we will show you how to configure an Ethernet router that allows other Ethernet devices to access the Internet through a WiFi bridge. To do this, we'll use a library called DNSMASQ, which acts as both a DHCP server and a DNS proxy (don't worry if you don't know those terms, we'll cover that in a moment).

Unlike our previous blog post where we skipped straight to instructions on how to perform a task, we are going to explain why we need to create a WiFi bridge that shares the Internet with the Ethernet port.

Connect to the Internet via Ethernet via WiFi (1)

Goals of creating WiFi Bridge with Raspberry PI

Providing connected devices with an Internet connection, especially devices that rely on the Internet for data communication or for sending and receiving data to a server, is like administering oxygen to a patient. It is a vital raw material for such devices. If these devices have an Ethernet port, you will need to provide a router or modem with a broadband/fiber connection. This is not always an option if you don't want a permanent network connection or if these service providers are not available in your area.

Nowadays, we all have internet connection on our mobile phones and we can share network connection with other WiFi devices by creating WiFi hotspots. But in devices you need to have WiFi chip to get internet services through hotspot access which you can provide easily. Here comes our solution for pure Ethernet devices. We could receive the internet connection through the Raspberry Pi WiFi and share the internet from the Raspberry Pi WiFi to its own ethernet port, so devices connected to the ethernet port of the Raspberry Pi also get the network connection. In addition, various devices can also be connected via Ethernet switches. Below is a presentation graphic.

Connect to the Internet via Ethernet via WiFi (2)

figure here

Thus, we can summarize the objectives as follows

1 Connect to the Internet for Ethernet-only devices using any WiFi hotspot.

2 Connect multiple Ethernet devices in a cluster to make the devices even smarter.

3 Raspberry Pi, it can act as a data collection terminal that temporarily stores data from devices and sends it to the server when an internet connection is available through your WiFi. (This requires code to run at the RPI as needed.)

You have to keep in mind that the shared internet speed may not be as good as that of a router, as the WiFi bandwidth as well as the processing power of our Raspberry Pi router may be limited.

To follow this tutorial, you will need the following hardware.

Below are all the little things I used for this Raspberry Pi WiFi Bridge tutorial. You need a wireless internet connection to complete this tutorial.

recommended

  • Raspberry Pi 3 or 4
  • micro sd card
  • Cabo Ethernet
  • Raspberry Pi power supply
  • Any Ethernet device (could also be your desktop PC or laptop)

Optional

  • Himbeer-Pi-Box

Connect to the Internet via Ethernet via WiFi (3)

introduction

What is dnsmasq?

DnsmasqNameis a lightweight but efficient library that acts as a DNS server, as a DHCP server with DHCPv6 and PXE support, and as a TFTP server. It is designed to have low disk space and storage overhead and is suitable for resource-constrained routers and firewalls. Dnsmasq can also be configured as a DNS cache to improve DNS lookup speed on previously visited websites. Basically, DNSMasq gives the router some advanced business features: caching DNS records locally so you can browse faster. For starters, reading this verse will be like reading Greek and Roman. For a better understanding, we explain the import terminology below.

Connect to the Internet via Ethernet via WiFi (4)

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 broadcast requests from clients. In other words, since Dnsmasq runs on the RPI, our RPI acts like a DHCP server on the ethernet, leasing IP addresses to devices connected to the ethernet port like any other router. The devices and the RPI form their own LAN, with the RPI acting as a router.

Servidor-DNS: A DNS server is a computer server that contains a database of public IP addresses and their associated hostnames, and in most cases is used to resolve or convert these names to IP addresses as needed. 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 like the RPI. Instead, DNS queries are sent to a really up-to-date DNS server, such as Google DNS, using the Dnsmasq library.

(Video) How To Share Internet Over Wifi From One Computer To Another | Ethernet Cable |

To configure the Raspberry Pi Wifi bridge we will be using the Dnsmasq package, this package will do most of the heavy lifting in this tutorial.

Using the Dnsmasq feature mentioned above, we can configure and run this package on a Raspberry Pi, allowing us to assign IP addresses and handle DNS requests through the Raspberry Pi itself and let our little Raspberry Pi act as a router.

There are alternative libraries that provide similar functionality to Dnsmasq, but one of the advantages of using Dnsmasq is that it's very easy to configure and a bit lightweight compared to the isc-dhcp-server and bind9 packages.

Keep in mind that for this tutorial you will need a Wi-Fi router/Wi-Fi hotspot/active Wi-Fi hotspot that you can connect to and an Ethernet device that you can use to connect to the connection. Desired Wi-Fi connect.

Step 1. Before we start installing and configuring our packages, let's first update the Raspberry Pi by typing the following two commands in the terminal.

sudo apt-get update

sudo apt-get update

step 2. With that done, we can now install the only package we are going to use. Run the following command to install dnsmasq.

sudo apt-get install dnsmasq

stage 3. Before we get too far ahead, we need to configure the wlan0 connection we want to use. If you've already set up your wireless connection, you can skip to step 5.

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

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Level 4. In this file, add the following, making sure to replace the SSID with the name of the network you want to connect to, and replace the psk value with the password for that network.

rot={

ssid="network name"

psk="network password"

}

step 5. With the wireless network now configured for the correct connection, we can proceed to configure our eth0 interface. This basically forces you to use a static IP address. If you do not configure them, various problems can occur.

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

(Video) How to share your WIFI internet connection through your Ethernet port

sudo nano /etc/dhcpcd.conf

Important note: if you are on Raspbian Stretch, you may need to change wlan0 and eth0 if predictable netnames are enabled. Use the ifconfig command to see the new names, they are probably too long and include the MAC address.

Be sure to update them for all commands in this tutorial.

step 6. In this file we need to add the following lines, make sure to replace eth0 with the correct interface of your ethernet.

interface eth0

static IP address = 192.168.220.1/24

Static Router = 192.168.220.0

Now we can save the file and exit by pressing Ctrl+X, then Y, then Enter.

step 7. With our changes to the dhcpcd configuration, we must now restart the service by running the following command:

Restart sudo dhcpcd service

step 8. Before we start changing the dnsmasq configuration, let's first create a backup copy of the original configuration by running the following command.

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

step 9. With the original configuration now backed up and out of the way, we can now go ahead and create our new configuration file by typing the following command in the terminal.

sudo nano /etc/dnsmasq.conf

Step 10. After creating our new file, we want to add the following lines. These lines basically tell the dnsmasq packet how to handle DNS and DHCP traffic.

interface=eth0 # Use a interface eth0

listen-address=192.168.220.1 # Specify the address to listen on

bind-interfaces # Vincular to interface

server=8.8.8.8 # Use Google DNS

(Video) Easy way How to share Internet from laptop to desktop | through Ethernet cable [KH] 2019

domain-required # Do not forward short names

bogus-priv # Remove unrouted address spaces.

dhcp-range=192,168,220,50,192,168,220,150,12h # IP range and lease duration

Now we can save the file and exit by pressing Ctrl+X, then Y, then Enter.

step 11. Now we need to configure the Raspberry Pi's firewall to forward all traffic from our eth0 connection to our wlan0 connection. Before doing that, we first need to enable ipv4p IP forwarding through the sysctl.conf configuration file, so let's start editing with the following command:

sudo nano /etc/sysctl.conf

step 12. In this file you must find the following line and remove the # at the beginning.

Meet:

#net.ipv4.ip_forward=1

Replace with:

net.ipv4.ip_forward=1

Now we can save the file and exit by pressing Ctrl+X, then Y, then Enter.

13th step. Now that we don't want to wait until the next reboot before loading the configuration, we can run the following command to activate it immediately.

sudo sh -c "eco 1 > /proc/sys/net/ipv4/ip_forward"

Step 14. Now that IPv4 forwarding is enabled, we can reconfigure our firewall to forward traffic from our eth0 interface to our wlan0 connection. Basically this means that anyone who connects to the ethernet can use our wlan0 internet connection.

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

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

sudo iptables -A FORWARD -i wlan0 -o eth0 -m status --status RELATED, ESTABLISHED -j OK

sudo iptables -A FORWARD -i eth0 -o wlan0 -j OK

(Video) Fix Ethernet Connected But No Internet Access | LAN Wired

Note: If you get errors typing the lines above, simply reboot the Pi with sudo reboot.

15th step. Of course, the iptables are downloaded every time the Raspberry Pi boots, so we need to save our new rules somewhere so that they are reloaded every time we boot.

Run the following command to save our new ruleset.

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

16th step. Now that our new rules are safely stored somewhere, we need to reload this file on every reboot. The easiest way to deal with this is to modify the rc.local file.

Run the following command to start editing the file.

sudo nano /etc/rc.local

step 17. Now that we are in this file, we need to add the following line. Make sure this line appears above the 0 output. This line basically reads the configuration from our iptables.ipv4.nat file and loads it into iptables.

Meet:

Salida 0

Add above:

restore iptables < /etc/iptables.ipv4.nat

Now we can save the file and exit by pressing Ctrl+X, then Y, then Enter.

18th step. Finally, all we need to do is start our dnsmasq service. All you have to do is run the following command:

sudo dnsmasq-Start service

19th step. You should now finally have a fully functional Raspberry Pi WiFi Bridge. You can make sure it works by plugging any device into its Ethernet port. The bridge must provide an Internet connection for the device you are connecting to.

To make sure everything runs smoothly, it's best to try restarting now. This will ensure that everything is successfully reactivated when the Raspberry Pi backup starts. Run the following command to restart the Raspberry Pi:

restart sudo

Hope you like this tutorial. Have fun hacking...

(Video) How to connect Sky Q via Ethernet Cable - a detailed setup guide

Videos

1. Share your ethernet connection over WiFi
(Isaac's Computer Tips)
2. How to Share Your Internet Connection using Ethernet or LAN Cable
(Sci -Tech et)
3. How to share Internet from Ethernet to WiFi | Share internet from Laptop to Mobile
(TECH NETWORXX)
4. How to Share Wireless Over Ethernet on Windows 10
(Solve Techie)
5. Use PC as WiFi Hotspot with Ethernet!
(Tech4Time)
6. How to Access WiFi using Ethernet Port or LAN Port | WiFi to Wired
(local guy)
Top Articles
Latest Posts
Article information

Author: Carmelo Roob

Last Updated: 04/03/2023

Views: 5655

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Carmelo Roob

Birthday: 1995-01-09

Address: Apt. 915 481 Sipes Cliff, New Gonzalobury, CO 80176

Phone: +6773780339780

Job: Sales Executive

Hobby: Gaming, Jogging, Rugby, Video gaming, Handball, Ice skating, Web surfing

Introduction: My name is Carmelo Roob, I am a modern, handsome, delightful, comfortable, attractive, vast, good person who loves writing and wants to share my knowledge and understanding with you.