#!/bin/bash # ------------------------------------------------------------------ # Separate Subnet # https://willhaley.com/blog/raspberry-pi-wifi-ethernet-bridge/ # Step 1: Add network conf - sudo nano bridge.sh # copy this script to the file # Step 2: Execute the script on your Pi like so. # sudo bash bridge.sh # Step 3: Reboot. # sudo reboot # ------------------------------------------------------------------ set -e [ $EUID -ne 0 ] && echo "run as root" >&2 && exit 1 apt update && \ DEBIAN_FRONTEND=noninteractive apt install -y \ dnsmasq netfilter-persistent iptables-persistent # Create and persist iptables rule. iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE netfilter-persistent save # Enable ipv4 forwarding. sed -i'' s/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/ /etc/sysctl.conf # The Ethernet adapter will use a static IP of 10.1.1.1 on this new subnet. cat <<'EOF' >/etc/network/interfaces.d/eth0 auto eth0 allow-hotplug eth0 iface eth0 inet static address 10.1.2.1 netmask 255.255.255.0 gateway 10.1.2.1 EOF # Create a dnsmasq DHCP config at /etc/dnsmasq.d/bridge.conf. The Raspberry Pi # will act as a DHCP server to the client connected over ethernet. cat <<'EOF' >/etc/dnsmasq.d/bridge.conf interface=eth0 bind-interfaces server=8.8.8.8 domain-needed bogus-priv dhcp-range=10.1.2.2,10.1.2.254,12h EOF systemctl mask networking.service