Optimizing LAN Traffic Forwarding via Wi-Fi: A Step-by-Step Guide
Introduction
In modern home networking scenarios, it’s common to utilize a main machine as a bridge to share internet connectivity with other devices. This blog post explores a detailed setup where an Arch Linux system acts as a gateway, forwarding internet traffic from a private LAN through its Wi-Fi interface to a connected Ubuntu-based Single Board Computer (SBC). We will examine the configuration process, common pitfalls, and troubleshooting tips to achieve seamless network sharing.
Scenario Overview
– Main Machine: Running Arch Linux, connected to a home LAN (192.168.10.0/24) via Wi-Fi (wlp6s0
).
– Connected Device: An Ubuntu SBC (Ubuntu 22.04), connected via Ethernet (eth0
) to the main machine’s Ethernet interface (enp42s0
).
Objective
Enable the Ubuntu SBC to access the internet through the Arch Linux machine’s Wi-Fi connection, without disrupting the main machine’s existing connectivity.
Configuration Steps
- Enable IP Forwarding
First, ensure that IP forwarding is enabled on the main machine to allow packet routing:
bash
sudo sysctl -w net.ipv4.ip_forward=1
Persist this setting across reboots by checking the /etc/sysctl.conf
file:
bash
net.ipv4.ip_forward=1
- Configure iptables for NAT and Packet Forwarding
Implement NAT (Network Address Translation) using iptables rules to masquerade traffic from the connected device:
“`bash
Allow forwarding between interfaces
sudo iptables -I FORWARD -o enp42s0 -i wlp6s0 -j ACCEPT
sudo iptables -I FORWARD -i enp42s0 -o wlp6s0 -j ACCEPT
Set up NAT on the Wi-Fi interface
sudo iptables -t nat -I POSTROUTING -o wlp6s0 -j MASQUERADE
“`
Verify the iptables rules with:
bash
sudo iptables -L
sudo iptables -t nat -L
- Save iptables Rules for Persistence
To ensure rules persist after reboot, save them:
bash
sudo iptables-save | sudo tee /etc/iptables/iptables.rules
(Ensure your system loads these rules on startup, possibly via a system service or script.)
- Network Configuration
Share this content: