Deliver local webserver over raspap and dnsmasq

222 Views Asked by At

I would like to have the following setup:

  • A raspberry running RaspAp and a flask application
  • Another arbitrary device, connected to the raspberry via WLAN
  • (When connecting, the device should recognize that this is not a wireless connection for internet but rather only this local website, if possible)
  • A Browser on said device that can reach the flask app via a domain name given by me.

At the moment, it almost works: I can reach it on my win 10 machine under http://raspberrypi/ but i don't know how to change the name. On my Phone it only works via http://raspberrypi.local/ and on the phone of my teacher, neither. (Both phones are samsung android and we tried it via chrome). The Phones also assume that this should be an internet connection, even though that's not my intent, can RaspAp "tell" the phone that this is normal behaviour?

Just changing the dnsmasq.conf properties like shown here: https://www.youtube.com/watch?v=cxaAiBVGf7s&ab_channel=RaspberryTips does absolutly nothing. When i put invalid options in though and syntax check, it verifies that it loads the file.

How would I approach this problem?

1

There are 1 best solutions below

2
billz On

On Raspberry Pi OS, multicast DNS is supported by the Avahi daemon. Avahi facilitates service discovery on a local network via the mDNS protocol. This lets you connect a Pi to your network and access it by its hostname. Check its status like so:

$ sudo systemctl status avahi-daemon
● avahi-daemon.service - Avahi mDNS/DNS-SD Stack
     Loaded: loaded (/lib/systemd/system/avahi-daemon.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2023-06-30 09:27:20 CEST; 1min 29s ago
TriggeredBy: ● avahi-daemon.socket
   Main PID: 391 (avahi-daemon)
     Status: "avahi-daemon 0.8 starting up."
      Tasks: 2 (limit: 2057)
        CPU: 117ms
     CGroup: /system.slice/avahi-daemon.service
             ├─391 avahi-daemon: running [raspberrypi.local]
             └─415 avahi-daemon: chroot helper

Jun 30 09:27:26 raspberrypi avahi-daemon[391]: Registering new address record for 10.3.141.1 on wlan0.IPv4.
Jun 30 09:27:27 raspberrypi avahi-daemon[391]: Joining mDNS multicast group on interface eth0.IPv4 with address 192.168.1.49.
Jun 30 09:27:27 raspberrypi avahi-daemon[391]: New relevant interface eth0.IPv4 for mDNS.
Jun 30 09:27:27 raspberrypi avahi-daemon[391]: Registering new address record for 192.168.1.49 on eth0.IPv4.

Above we see that both the wlan0 and eth0 interfaces have their IPv4 addresses registered with the default raspberrypi hostname. 10.3.141.1 is the static IPv4 address created by RaspAP for the wireless interface.

If your device supports mDNS, you can reach your Raspberry Pi by using its hostname and the .local suffix. Windows 10 has mDNS support built in, which explains why you're able to access it. It's also available for Windows by installing Apple's iTunes or the Bonjour service. Android has had support for Bonjour/mDNS for quite awhile, but this doesn't necessarily mean that it will work with a browser on your phone. In this case, you'll need to discover your Pi's IP address and use that.

You can change the default raspberrypi hostname by editing these files:

sudo nano /etc/hostname
sudo nano /etc/hosts

Reboot your device for the changes to take effect.

The Phones also assume that this should be an internet connection, even though that's not my intent, can RaspAP "tell" the phone that this is normal behaviour?

Mobile devices handle this in various ways. Some will connect to a wireless AP and report "Connected without internet" or similar. This shouldn't prevent you from accessing a local website served by the device, though. For your application, one way to handle this would be to install a captive portal. This way, the moment a device connects to the AP you can redirect it to your Flask app.

See https://docs.raspap.com/captive/ for an example of how to do this. If you need more granular control take a look at openNDS.

Source: developer of RaspAP