Posted on

Use the Raspberry Pi Zero W to bridge two wireless networks.

  1. Use nmtui to connect the USB WiFi adapter to the WiFi network for the internet connection
  2. Disable auto connect for the preconfigured connection

https://gist.github.com/narate/d3f001c97e1c981a59f94cd76f041140

CONNECTION_NAME=hotspot
SSID=my-ssid
INTERFACE=wlan0 # Interface for hosting the hotspot
PASSWORD=HJbiuAUYvo873bhyaF

# autoconnect is no because it will be started by the `start-hotspot.sh` script
nmcli con add type wifi ifname $INTERFACE con-name $CONNECTION_NAME autoconnect no ssid $SSID
nmcli con modify $CONNECTION_NAME 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared
nmcli con modify $CONNECTION_NAME wifi-sec.key-mgmt wpa-psk
nmcli con modify $CONNECTION_NAME wifi-sec.psk "$PASSWORD"
nmcli con up $CONNECTION_NAME

I had a problem where the hotspot had to be started after the internet interface is up. Solution:

https://askubuntu.com/a/1015291

/etc/NetworkManager/dispatcher.d/start-hotspot.sh

!/bin/bash

interf=$1
state=$2

# TODO: change `my-ethernet-device` and `my-hotspot`
if [ $interf = "my-ethernet-device" -a $state = "up" ]; then
    nmcli connection up 'my-hotspot'
fi

if [ $interf = "my-ethernet-device" -a $state = "down" ]; then
   nmcli connection down 'my-hotspot'
fi