Ubuntu 20.04 with Raspberry Pi 3B plus
Recently I tried connecting wlan0 of RPi 3 with Ubuntu-20.04 using Ethernet cable. This is to avoid using wi-fi adapter in the desktop. There are many elaborate suggestions in Google but simple instructions are needed. Using Google and Github postings the following steps were carried out:
1. Set up RPi 3 B+ with mobile hotspot, using built-in wi-fi adapter.
2. Configure RPi's Ethernet adapter as follows:
$sudo nano /etc/network/interfaces.d/eth0
Enter the code as below:
auto eth0
iface eth0 inet static
address 192.168.1.20
netmask 255.255.255.0
Save the code.
3. We now need to forward the ip from wlan0 to eth0. So we enter:
$sudo sysctl -w net.ipv4.ip_forward=1
4. Next, we allow the traffic through firewall:
$sudo iptables -A FORWARD --in-interface eth0 -j ACCEPT
$sudo iptables --table nat -A POSTROUTING --out-interface wlan0 -j MASQUERADE
5, In the desktop or laptop running Ubuntu we enter the Ethernet address as 192.168.1.50, netmask as 255.255.255.0, gateway as 192.168.1.20 (same as given for RPi). This is also possible from CLI as:
$sudo ifconfig eth0 192.168.1.20 netmask 255.255.255.0
$sudo route add default gw 192.168.1.20
This will work until reboot.For permanent setup, please enter:
$sudo sysctl -p /etc/sysctl.conf
$sudo apt install iptables-persistent
I had to reboot a few times to get this working.
|