Share internet using USB to Ethernet adapter

I got it working!

Goal:
Share the internet/network connection from a Raspberry Pi running Ubuntu Server 22.04 via a USB-To-Ethernet adapter to a nearby laptop running Manjaro.

What I did:
First of all I turned off “Predictable network interface names” in my Ubuntu Server 22.04. I didn’t really need to but I just wanted to! Because I was running it on a Pi 4 I had to do this by adding net.ifnames=0 to the beginning of the line in /boot/firmware/cmdline.txt

My Ubuntu Pi is connected to the router (via a powerline adapter) using the Pis ethernet adapter. I now connected the USB-To-Ethernet adapter to a spare USB 3 port on the Pi and used a regular ethernet cable to connect it to my laptops ethernet adapter. It did not need to use a crossover cable.

In my case the Pis onboard ethernet was now eth0 and the adapter was eth1.

I then followed the instructions from this archlinux wiki.

Assign a static IPv4 address to eth1:

ubuntu@ubuntu:~$ sudo ip link set up dev eth1 
ubuntu@ubuntu:~$ sudo ip addr add 192.168.123.100/24 dev eth1

Enable Packet forwarding in Ubuntu Pi:

ubuntu@ubuntu:~$ sudo sysctl net.ipv4.ip_forward=1

Enable NAT (Network Address Translation) in Ubuntu Pi

ubuntu@ubuntu:~$ sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
ubuntu@ubuntu:~$ sudo iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
ubuntu@ubuntu:~$ sudo iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT

Give the ethernet interface of the laptop (client) a static IP address and a default route via eth1
• I was able to do these steps using “System Settings” in Manjaro.
• I gave my laptops ethernet interface an ip (192.168.123.15) in the same subnet as the ethernet interface of eth1 on Ubuntu Pi (192.168.123.100).
• Then I told the laptops ethernet interface to use the Ubuntu Pi eth1 interfaces ip address (192.168.123.100) as its default gateway.
• I also assigned DNS servers (8.8.8.8 , 8.8.4.4 for Google DNS)
• Now the USB-To-Ethernet adapter should light up and you should be able to turn off Wifi on the laptop and continue with network/internet access!
• Note: This will all be lost if you reboot the Pi but you could run a script to configure the iptables rules on boot up.

Cheers,

Flex