英文:
Deliver local webserver over raspap and dnsmasq
问题
我想要以下的设置:
- 一个运行RaspAp和Flask应用的树莓派
- 另一个任意设备,通过WLAN连接到树莓派
- (在连接时,设备应该能够识别这不是用于互联网连接的无线连接,而仅仅是本地网站,如果可能的话)
- 设备上的浏览器可以通过我提供的域名访问Flask应用程序。
目前,几乎可以工作:我可以在我的Windows 10机器上通过http://raspberrypi/访问它,但我不知道如何更改名称。在我的手机上,只能通过http://raspberrypi.local/访问,而在我的老师的手机上则不行(两部手机都是三星安卓手机,我们尝试使用Chrome浏览器)。手机还假定这应该是一个互联网连接,尽管这不是我的意图,RaspAp是否可以告诉手机这是正常行为?
只是像这里所示更改dnsmasq.conf属性:https://www.youtube.com/watch?v=cxaAiBVGf7s&ab_channel=RaspberryTips 完全没有作用。但是,当我输入无效选项并进行语法检查时,它会验证加载了该文件。
我该如何解决这个问题?
英文:
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
得分: 1
在Raspberry Pi OS上,多播DNS由Avahi守护程序支持。Avahi通过mDNS协议在本地网络上进行服务发现。这允许您将Pi连接到您的网络并通过其主机名访问它。可以通过以下方式检查其状态:
$ 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.
在上面的示例中,我们可以看到wlan0
和eth0
接口都已使用默认的raspberrypi
主机名注册了它们的IPv4地址。10.3.141.1
是由RaspAP为无线接口创建的静态IPv4地址。
如果您的设备支持mDNS,您可以通过使用主机名和.local
后缀来访问您的Raspberry Pi。Windows 10内置了mDNS支持,这解释了为什么您可以访问它。它也可以通过安装Apple的iTunes或Bonjour服务来在Windows上使用。Android已经支持Bonjour/mDNS相当长的时间了,但这不一定意味着它在手机上使用浏览器时会起作用。在这种情况下,您需要查找Pi的IP地址并使用它。
您可以通过编辑以下文件来更改默认的raspberrypi
主机名:
sudo nano /etc/hostname
sudo nano /etc/hosts
重新启动设备以使更改生效。
手机还假定这应该是一个互联网连接,尽管这不是我的意图,RaspAP可以告诉手机这是正常行为吗?
移动设备以不同的方式处理这个问题。有些设备会连接到一个无线AP并报告"连接但没有互联网"或类似的情况。但这不应该阻止您访问设备提供的本地网站。对于您的应用程序,一种处理方式是安装一个强制门户(captive portal)。这样,一旦设备连接到AP,您就可以将其重定向到您的Flask应用程序。
请参阅https://docs.raspap.com/captive/以查看如何执行此操作的示例。如果您需要更精细的控制,可以查看openNDS。
来源:RaspAP的开发者
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论