Wifi to ethernet

Hello everybody. I would like to know if there is the possibility of configuring bpr1 in such a way as to convert the wifi signal to ethernet. I would need to connect a device that only has an ethernet port. I don’t want to use powerlines.

Thank you

First: Welcome to this forum! Second to answer your question: Yes! That’s possible! But how? You can do this by using iptables (it’s now being replaced by nftables) and dnsmasq. Important to know before we begin: you need to run this commands as root (sudo -s “or” su -) First you need to configure your ethernet port to be static. If you’re running Buster (Debian 10) or later, then run this commands:

update-alternatives --set iptables /usr/sbin/iptables-legacy
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
update-alternatives --set arptables /usr/sbin/arptables-legacy
update-alternatives --set ebtables /usr/sbin/ebtables-legacy

Add/Change the following in /etc/network/interfaces (sudo nano /etc/network/interfaces):

  auto wlan0
        iface wlan0 inet dhcp
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

  auto eth0
         iface eth0 inet static
         address 192.168.1.1/24

The whole file now looks like:

source /etc/network/interfaces.d/*

auto lo 
    iface lo inet loopback

auto wlan0
    iface wlan0 inet dhcp
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

auto eth0
    iface eth0 inet static
    address 192.168.1.1/24

You can change 192.168.1.1 to anything you like. By the way, take a look at the interfaces (eth0 and wlan0 in this example). Replace the interfaces names with the correct interface names (you can check it by running ip addr “or” sudo ifconfig. The last one only if you installed it. /24 stands for prefix 24 and means that it has a subnetmask of 255.255.255.0. This are usually the home networks. You can’t give your Pi the same network address (192.168.1.0) as your router, which I assume you’re connecting, because they’re behind NAT. So be careful, otherwise it don’t work!

I suggest you to install the following package (the comment below is for Debian-/Ubuntu-based distro’s.

apt update && apt install dnsmasq resolvconf wpasupplicant -y

If you did all the steps, open the following file (sudo nano /etc/resolvconf/resolv.conf.d/head). Then add the following (ignore warning about changing the config file):

nameserver 8.8.8.8
nameserver 8.8.4.4

This are Google Public DNS servers. The first one is the primary DNS controller en the other one the second DNS controller. DNS translates the domain names and ip address (e.g. www.google.com corresponds with 123.123.123.123), just an example.

You can just replace it by your own if you wish.

Run the below comments to update DNS servers (only for the host itself, not for the DHCP-clients, DHCP=Dynamic Host Client Protocol, the one that gives your device an IP-address). You may get a warning that /path/to/file is not a symbolic link to /etc/resolvconf (after running resolvconf --enable-updates “or” resolvconf -u. All you need to do is the following:

rm /etc/resolv.conf
ln -s /path/to/file /etc/resolv.conf

The run (again if you did steps above):

resolvconf --enable-updates
resolvconf -u

Then you need to configure DNSMasq (officially not a DHCP server, but more DNS translation I believe):

First make backup of current file:

mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak

Then:

nano /etc/dnsmasq.conf add the following lines:

interface=eth0
dhcp-range=eth0,192.168.1.2,192.168.1.200,255.255.255.0,5d
dhcp-option=eth0,3,192.168.1.1
dhcp-option=eth0,6,192.168.1.1,8.8.8.8,8.8.4.4

domain=mydomain
local=/mydomain/

server=8.8.8.8
server=8.8.4.4

Now we need to configure wpasupplicant:

Run nano /etc/wpa_supplicant/wpa_supplicant.conf and add the following lines:

network={
    ssid="MyWiFiNetworkHere"
    psk="MyWiFiPasswordHere"
    scan_ssid=1
}

Now we enable ipv4-forward in /etc/sysctl.conf (nano /etc/sysctl.conf and then uncomment line below):

net.ipv4.ip_forward=1

The last one: We need to configure IPtables:

# Flush IPtables rules
iptables -X
iptables -F
iptables -F -t nat

# Add new rules
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT

iptables-save > /etc/iptables.nat

Now we need to add this one to /etc/network/interfaces (end of the file):

up iptables-restore < /etc/iptables.nat

Now reboot (reboot) and that’s it! Now it must be working or you’ve done something wrong. You can verify your internet connection by using ping (e.g. ping google.com). If it returns a reply, then it’s working.

By the way, sorry if my English is bad.

Have fun with your project!

mhog

By the way. To make it simpler, just use OpenWRT (linux-based router os).

Nice i am also looking for the same information.