How to Bridge wlan0 to eth0 for Network Sharing on Arch Linux


2 views

Bridging wlan0 (wireless interface) to eth0 (Ethernet interface) essentially creates a layer-2 network connection between them, allowing devices connected via Ethernet to share your wireless connection. This is particularly useful when you need to provide internet access to devices that don't have wireless capability or when you want to extend your network.

# Install necessary packages
sudo pacman -S bridge-utils netctl dhcpcd

Ensure both interfaces are up and running. Check with:

ip link show

First, let's create a bridge interface named br0:

sudo brctl addbr br0
sudo brctl addif br0 eth0
sudo brctl addif br0 wlan0

Edit your network configuration files. For netctl:

# /etc/netctl/bridge
Description="Bridge Connection"
Interface=br0
Connection=bridge
BindsToInterfaces=(eth0 wlan0)
IP=dhcp

Enable IP forwarding in the kernel:

echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward

To make this persistent, add to /etc/sysctl.conf:

net.ipv4.ip_forward=1

Set up NAT rules for proper routing:

sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT

For those using systemd-networkd, create these files:

# /etc/systemd/network/br0.netdev
[NetDev]
Name=br0
Kind=bridge
# /etc/systemd/network/br0.network
[Match]
Name=br0

[Network]
DHCP=yes
# /etc/systemd/network/wlan0.network
[Match]
Name=wlan0

[Network]
Bridge=br0

If devices can't get IP addresses:

sudo dhcpcd br0

Check bridge status:

brctl show

Enable and start the services:

sudo systemctl enable systemd-networkd
sudo systemctl start systemd-networkd

Or for netctl:

sudo netctl enable bridge
sudo netctl start bridge

When you need to share a wireless connection (wlan0) with a wired interface (eth0), network bridging becomes essential. This setup is particularly useful when you want to extend your WiFi connection to devices that only support wired Ethernet or when creating a more stable connection for specific devices.

Before proceeding, ensure you have:

  • A working Arch Linux installation with root access
  • Wireless interface (wlan0) connected and functioning
  • Ethernet interface (eth0) properly recognized
  • bridge-utils package installed

First, install the necessary packages:

sudo pacman -S bridge-utils net-tools

Create and configure the bridge interface:

sudo brctl addbr br0
sudo brctl addif br0 eth0
sudo brctl addif br0 wlan0

Assign an IP address to your bridge interface:

sudo ip addr add 192.168.1.100/24 dev br0
sudo ip link set br0 up

For proper routing between interfaces:

echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

To make these changes permanent, create a systemd service:

sudo nano /etc/systemd/system/bridge-setup.service

[Unit]
Description=Network Bridge Setup
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/sbin/brctl addbr br0
ExecStart=/usr/sbin/brctl addif br0 eth0
ExecStart=/usr/sbin/brctl addif br0 wlan0
ExecStart=/usr/sbin/ip link set br0 up
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Verify the bridge is working:

brctl show
ip addr show br0

If devices connected to eth0 can't access the internet:

  • Check firewall rules with sudo iptables -L -n -v
  • Verify IP forwarding is enabled cat /proc/sys/net/ipv4/ip_forward
  • Ensure both interfaces are up ip link show