We are working in a lot of different places, different WIFI, etc. So we configured a Raspberry Pi 4 as a USB Ethernet Gadget and installed Pi-Hole (+ a VPN) to enhance our privacy and block ads wherever we go. This way the wifi of the computer can be switched off, because it gets its its internet connection from the Raspberry Pi. The DHCP server of the Pi-Hole works really well in this setup. Every virtual machine that runs on the Laptop is recognized as an individual client which is exactly what is needed.
Furthermore a USB Wifi-dongle provides the internet connection (because it provides better speed than the built-in wifi of the Pi). Thus our Pi-hole Ethernet Interface is wlan1. This means in this setup the internal wifi card (wlan0) of the Pi is free, which is why we tried to install an additional access point via hostapd. This is where we got stuck. The wifi access point does show up and it is possible to connect to it via ssh. However if a computer or a mobile phone connects to this access point it has no internet connectivity. Is there a way this can work?
This is our dhcpcd-setup:
/etc/dhcpcd.conf
interface usb0
static ip_address=192.168.77.1/24
interface wlan0
static ip_address=192.168.79.1/24
nohook wpa_supplicant
These are the dnsmasq configuration files:
/etc/dnsmasq.d/00-dnsmasq.conf
interface=usb0 # USB interface
address=/access.tardigrade/192.168.77.1
# Alias for this router
# Wifi-AP
interface=wlan0 # Access Point
dhcp-range=192.168.79.2,192.168.79.21,24h
# Pool of IP addresses served via DHCP
AND:
/etc/dnsmasq.d/02-pihole-dhcp.conf
dhcp-authoritative
dhcp-range=192.168.77.2,192.168.77.21,24h
dhcp-option=option:router,192.168.77.1
dhcp-leasefile=/etc/pihole/dhcp.leases
#quiet-dhcp
domain=lan
local=/lan/
dhcp-rapid-commit
And finally the access point configuration:
/etc/hostapd/hostapd.conf
country_code=DE
interface=wlan0
ssid=testnetwork
hw_mode=g
channel=7
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=password-testnetwork
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
IPv4 forwarding is set up:
/etc/sysctl.conf
net.ipv4.ip_forward=1
Also the required iptables rule is in place:
sudo iptables -t nat -A POSTROUTING -o wlan1 -j MASQUERADE
The Pi-hole is set to listen on all interfaces (it also filters the VPN). In the DHCP settings of the admin interface we can define our dhcp server. These point to our usb0 interface. Everything connected via usb0 works flawlessly. The Pi-hole also sees all devices that connect to Raspberry Pi via wlan0 (access point) and it does issue dhcp leases to those devices as well. These devices successfully connect, but have no internet.
What are we missing?