2024年11月24日星期日 上午4:03:16

为树莓派配置mDNS服务 Avahi

8 个月 前
#29700 引用
https://blog.csdn.net/weixin_46084533/article/details/135488050
https://blog.csdn.net/ken2232/article/details/133823521

安装 Avahi

sudo apt-get install avahi-daemon


一旦配置完成,你的树莓派就可以通过 raspberrypi.local 这样的地址被网络中的其他设备发现.其中 hostname 是你的树莓派的实际主机名。这样,你的 ESP8266 就可以使用 mDNS 协议发现树莓派的 IP 地址了

安装 avahi-tools

安装之后,才能使用 avahi-browse 命令。

可以查看局域网内所有的mdns服务,命令如下:

# Ubuntu / Debian
$ sudo apt install avahi-daemon avahi-utils


查看局域网内所有的mdns服务
avahi-browse -a


output

debian:~# avahi-browse -a
+  ens33 IPv6 _workstation                                  _tcp                 local
+  ens33 IPv6 _services                                     _dns-sd._udp         local
+  ens33 IPv4 _miot-central                                 _tcp                 local
+  ens33 IPv4 _workstation                                  _tcp                 local
+  ens33 IPv4 _services                                     _dns-sd._udp         local
+  ens33 IPv4 _home-assistant                               _tcp                 local
+  ens33 IPv6 _home-assistant                               _tcp                 local
+  ens33 IPv4 _aqara-setup                                  _tcp                 local
+  ens33 IPv4 _aqara                                        _tcp                 local
+  ens33 IPv4 _hap                                          _tcp                 local
+  ens33 IPv6 _aqara-setup                                  _tcp                 local
+  ens33 IPv6 _aqara                                        _tcp                 local
+  ens33 IPv6 _hap                                          _tcp                 local
+  ens33 IPv6 _________-2                                   _home-assistant._tcp local
+  ens33 IPv6 Home                                          _home-assistant._tcp local
+  ens33 IPv6 _________                                     _home-assistant._tcp local
+  ens33 IPv4 _________-2                                   _home-assistant._tcp local
+  ens33 IPv4 Home                                          _home-assistant._tcp local
+  ens33 IPv4 _________                                     _home-assistant._tcp local
+  ens33 IPv6 YLCeilingLight-EF4F                           _hap._tcp            local
+  ens33 IPv6 YLBulbColor1s-303B                            _hap._tcp            local
+  ens33 IPv6 Aqara-Hub-M1S-EDB6                            _hap._tcp            local
+  ens33 IPv6 MiSmartLEDLivingRoomCeilingLight-5F74         _hap._tcp            local
+  ens33 IPv4 Aqara-Hub-M1S-EDB6                            _hap._tcp            local
+  ens33 IPv4 MiSmartLEDLivingRoomCeilingLight-5F74         _hap._tcp            local
+  ens33 IPv6 homeassistant [7c2cec2a209d48e4b16a072380eb732c] Workstation          local
+  ens33 IPv4 homeassistant [7c2cec2a209d48e4b16a072380eb732c] Workstation          local
+  ens33 IPv4 _mi-connect                                   _udp                 local
+  ens33 IPv4 xiaomi-gateway-hub1-5604                      _miot-central._tcp   local
+  ens33 IPv4 ____________-6318                             _mi-connect._udp     local
+  ens33 IPv4 YLCeilingLight-EF4F                           _hap._tcp            local
+  ens33 IPv6 Aqara-Hub-M1S-EDB6                            _aqara-setup._tcp    local
+  ens33 IPv6 Aqara-Hub-M1S-EDB6                            _aqara._tcp          local
+  ens33 IPv4 Aqara-Hub-M1S-EDB6                            _aqara-setup._tcp    local
+  ens33 IPv4 Aqara-Hub-M1S-EDB6                            _aqara._tcp          local
+  ens33 IPv4 _miio                                         _udp                 local
+  ens33 IPv4 lumi-gateway-mihk01_miio73110144              _miio._udp           local






[code]

@debian:~# avahi-browse -r _aqara._tcp
+  ens33 IPv6 Aqara-Hub-M1S-EDB6                            _aqara._tcp          local
+  ens33 IPv4 Aqara-Hub-M1
0
8 个月 前
#29701 引用
ping raspberrypi.local

Avahi 是一个免费的零配置网络 (zeroconf) 实现,包括一个用于组播 DNS/DNS-SD 服务发现的系统。它允许程序发布和发现在本地网络上运行的服务和主机,而无需特定配置。比如,traefik.local、homepage.local就可以轻松实现。

苹果的Bonjour服务(mDNS)通过使用.local后缀,实现了多址广播域名的设备识别。
0
8 个月 前
#29702 引用


sudo systemctl status avahi-daemon
● avahi-daemon.service - Avahi mDNS/DNS-SD Stack
     Loaded: loaded (/lib/systemd/system/avahi-daemon.service; enabled; preset: enabled)
     Active: active (running) since Sat 2024-03-09 01:24:29 GMT; 6 days ago
TriggeredBy: ● avahi-daemon.socket
   Main PID: 482 (avahi-daemon)
     Status: "avahi-daemon 0.8 starting up."
      Tasks: 2 (limit: 765)
        CPU: 9.432s
     CGroup: /system.slice/avahi-daemon.service
             ├─482 "avahi-daemon: running [raspberrypi.local]"
             └─509 "avahi-daemon: chroot helper"

Mar 09 01:24:55 raspberrypi avahi-daemon[482]: New relevant interface eth0.IPv4 for mDNS.
Mar 09 01:24:55 raspberrypi avahi-daemon[482]: Registering new address record for 192.168.2.50 on eth0.IPv4.
Mar 09 01:25:01 raspberrypi avahi-daemon[482]: Joining mDNS multicast group on interface docker0.IPv4 with address 172.17.0.1.
Mar 09 01:25:01 raspberrypi avahi-daemon[482]: New relevant interface docker0.IPv4 for mDNS.
Mar 09 01:25:01 raspberrypi avahi-daemon[482]: Registering new address record for 172.17.0.1 on docker0.IPv4.
Mar 09 01:25:19 raspberrypi avahi-daemon[482]: Leaving mDNS multicast group on interface eth0.IPv6 with address fe80::4ea1:966a:621f:86e6.
Mar 09 01:25:19 raspberrypi avahi-daemon[482]: Joining mDNS multicast group on interface eth0.IPv6 with address fd18:f22c:7814:d900:6bbe:f03a>
Mar 09 01:25:19 raspberrypi avahi-daemon[482]: Registering new address record for fd18:f22c:7814:d900:6bbe:f03a:674b:8ace on eth0.*.
Mar 09 01:25:19 raspberrypi avahi-daemon[482]: Withdrawing address record for fe80::4ea1:966a:621f:86e6 on eth0.


0
8 个月 前
#29774 引用
avahi-tools 软件包包括许多方便的实用程序,可用于检查系统上的 mDNS 服务的工作情况。比如:

# 查看局域网内所有已注册的 mDNS 服务
  
  $ avahi-browse -a -r

    
    # 发现某个类型的服务的返回包
  
  $ avahi-browse -r "xxx"

    -xxx 是指服务类型,如_http._tcp



@debian:~# avahi-browse -r _aqara._tcp
+  ens33 IPv6 Aqara-Hub-M1S-EDB6                            _aqara._tcp          local
+  ens33 IPv4 Aqara-Hub-M1S-EDB6                            _aqara._tcp          local
=  ens33 IPv4 Aqara-Hub-M1S-EDB6                            _aqara._tcp          local
   hostname = [Aqara-Hub-M1S-EDB6.local]
   address = [192.168.2.106]
   port = [49094]
   txt = ["pw=true" "mt=false" "hp=true" "pv=true" "ln=false" "le=false" "ls=false" "ws=true" "cl=aiot" "id=lumi1.546666666666" "md=lumi.gateway.acn01" "fw=4.1.0" "ver=1"]
=  ens33 IPv6 Aqara-Hub-M1S-EDB6                            _aqara._tcp          local
   hostname = [Aqara-Hub-M1S-EDB6.local]
   address = [192.168.2.106]
   port = [49094]
   txt = ["pw=true" "mt=false" "hp=true" "pv=true" "ln=false" "le=false" "ls=false" "ws=true" "cl=aiot" "id=lumi1.546666666666" "md=lumi.gateway.acn01" "fw=4.1.0" "ver=1"]


0