Skip to content

Instantly share code, notes, and snippets.

@omushpapa
Last active July 17, 2020 21:34
Show Gist options
  • Save omushpapa/2e0fbd27ef171abaf0fbbc592e4117af to your computer and use it in GitHub Desktop.
Save omushpapa/2e0fbd27ef171abaf0fbbc592e4117af to your computer and use it in GitHub Desktop.
Ethernet to Wifi Bridge (Raspberry Pi - Ubuntu 18.04)
  1. Install wifi-api snap install wifi-ap.
  2. After installation, I had issues with DHCP connections, so I connected every device by assigning static IPs
  3. Ensure the Pi has a static IP address over eth0. wifi-ap assigns it a static IP address at wlan0
  4. Bridge using IP tables, see example:
# eth0 has internet connection
# wlan0 lacks internet connection
# 192.168.0.x subnet for eth0

sudo iptables -A FORWARD -o eth0 -i wlan0 -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -t nat -F POSTROUTING
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  1. Save iptables: sudo iptables-save | sudo tee /etc/iptables.sav
  2. Add iptables-restore < /etc/iptables.sav to /etc/rc.local so that the rules can be loaded on startup. If it does not exist, paste the following into it:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
iptables-restore < /etc/iptables.sav

exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment