我花了两天时间尝试让 Avahi 工作。我想使用 Debian 10.13(内核 5.10.77)在 SBC 上发布我的 Web 应用程序,但这样做时avahi-browse -a -r -t
总是出现以下情况:
+ eth1 IPv4 My application Web Site local
Failed to resolve service 'My application' of type '_http._tcp' in domain 'local': Timeout reached
Failed to resolve service 'My application' of type '_http._tcp' in domain 'local': Timeout reached
否则,我会在网络中看到其他 mDNS 设备(例如打印机)。Avahi
版本:0.7
我的安装步骤如下:
sudo apt install avahi-daemon avahi-autoipd libnss-mdns
sudo nano /etc/avahi/services/web.service
web.service的内容:
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<!-- See avahi.service(5) for more information about this configuration file -->
<service-group>
<name>My application</name>
<service protocol="ipv4">
<type>_http._tcp</type>
<domain-name>local</domain-name>
<host-name>myapp.local</host-name>
<port>80</port>
</service>
</service-group>
我尝试/检查的内容:
avahi-daemon 的 journalctl:
May 15 08:34:50 G100-sn1112 systemd[1]: Starting Avahi mDNS/DNS-SD Stack...
May 15 08:34:50 G100-sn1112 avahi-daemon[826]: Process 391 died: No such process; trying to remove PID file. (/run/avahi-daemon//pid)
May 15 08:34:50 G100-sn1112 avahi-daemon[826]: Found user 'avahi' (UID 106) and group 'avahi' (GID 112).
May 15 08:34:50 G100-sn1112 avahi-daemon[826]: Successfully dropped root privileges.
May 15 08:34:50 G100-sn1112 avahi-daemon[826]: avahi-daemon 0.7 starting up.
May 15 08:34:50 G100-sn1112 systemd[1]: Started Avahi mDNS/DNS-SD Stack.
May 15 08:34:50 G100-sn1112 avahi-daemon[826]: Successfully called chroot().
May 15 08:34:50 G100-sn1112 avahi-daemon[826]: Successfully dropped remaining capabilities.
May 15 08:34:50 G100-sn1112 avahi-daemon[826]: Loading service file /services/web.service.
May 15 08:34:50 G100-sn1112 avahi-daemon[826]: Joining mDNS multicast group on interface eth1.IPv4 with address 169.254.5.245.
May 15 08:34:50 G100-sn1112 avahi-daemon[826]: New relevant interface eth1.IPv4 for mDNS.
May 15 08:34:50 G100-sn1112 avahi-daemon[826]: Joining mDNS multicast group on interface eth0.IPv6 with address fe80::c8ea:18ff:fe7d:364e.
May 15 08:34:50 G100-sn1112 avahi-daemon[826]: New relevant interface eth0.IPv6 for mDNS.
May 15 08:34:50 G100-sn1112 avahi-daemon[826]: Joining mDNS multicast group on interface eth0.IPv4 with address 172.20.100.113.
May 15 08:34:50 G100-sn1112 avahi-daemon[826]: New relevant interface eth0.IPv4 for mDNS.
May 15 08:34:50 G100-sn1112 avahi-daemon[826]: Network interface enumeration completed.
May 15 08:34:50 G100-sn1112 avahi-daemon[826]: Registering new address record for 169.254.5.245 on eth1.IPv4.
May 15 08:34:50 G100-sn1112 avahi-daemon[826]: Registering new address record for fe80::c8ea:18ff:fe7d:364e on eth0.*.
May 15 08:34:50 G100-sn1112 avahi-daemon[826]: Registering new address record for 172.20.100.113 on eth0.IPv4.
May 15 08:34:51 G100-sn1112 avahi-daemon[826]: Server startup complete. Host name is G100-sn1112.local. Local service cookie is 2396255796.
May 15 08:34:52 G100-sn1112 avahi-daemon[826]: Service "My application" (/services/web.service) successfully established.
在 /etc/avahi/avahi-daemon.conf 中
use-ipv6=no
publish-resolv-conf-dns-servers=yes
在 /etc/systemd/resolved.conf 中
MulticastDNS=no
systemd-resolved 已被禁用。
在 /etc/dnsmasq.conf 中
local=/local/
domain=local
expand-hosts
server=/local/
我也尝试禁用 dnsmasq 服务
检查 /etc/nsswitch.conf
files mdns4_minimal [NOTFOUND=return] dns
我也尝试安装libnss-resolve
我尝试在 nsswitch.conf 中使用 mdns(不是最小)并使用创建 /etc/mdns.allow
.local.
.local
host -t SOA local
返回:
Host local not found: 3(NXDOMAIN)
输出ps aux | grep [a]vahi
avahi-a+ 704 0.0 0.2 2176 1356 ? S 08:33 0:00 avahi-autoipd: [eth1] bound 169.254.5.245
root 705 0.0 0.0 2036 88 ? S 08:33 0:00 avahi-autoipd: [eth1] callout dispatcher
avahi 826 0.0 0.6 6132 3412 ? Ss 08:34 0:00 avahi-daemon: running [G100-sn1112.local]
avahi 827 0.0 0.3 5868 1552 ? S 08:34 0:00 avahi-daemon: chroot helper
SBC 有两个以太网端口。它配置为带 NAT 的“路由器”(eth0 是 DHCP 客户端,eth1 是静态的。我确实从 eth1 伪装到 eth0)。avahi 仅在端口 eth1 上自动配置,但我需要在端口 eth0 上配置它...
ifconfig 的输出:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.20.100.113 netmask 255.255.255.0 broadcast 172.20.100.255
inet6 fe80::c8ea:18ff:fe7d:364e prefixlen 64 scopeid 0x20<link>
ether ca:ea:18:7d:36:4e txqueuelen 1000 (Ethernet)
RX packets 22948 bytes 4738293 (4.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 15524 bytes 6667160 (6.3 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 39
eth1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether ca:ea:18:7d:36:4f txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 38
eth1:avahi: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 169.254.5.245 netmask 255.255.0.0 broadcast 169.254.255.255
ether ca:ea:18:7d:36:4f txqueuelen 1000 (Ethernet)
device interrupt 38
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 22539 bytes 1328129 (1.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 22539 bytes 1328129 (1.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
由于某种原因,avahi-autoipd 首先为 eth1 绑定 LL IP。之后,eth0 的绑定失败(autoipd 处于睡眠状态),因为“可路由地址已分配,正在睡眠。”。运行avahi-autoipd eth0 --force-bind -D
还会在 eth0 上创建 LL IP,但解析仍然不起作用。
我还发现,hostname.local 的解析(在我的情况下是 g100-sn1112.local)有效。但 myapp.local 无效。
答案1
看来我终于找到问题了。对于使用 mDNS 主机名而不是计算机主机名,在服务文件中配置它是不够的。设置后,host-name=myapp
我/etc/avahi/avahi-daemon.conf
终于可以在本地解析 myapp.local。
但我仍然没有在网络上看到这个 mDNS 名称(从笔记本)。更新:这个问题看起来像是网络本身的问题。直接连接到 SBC 后,mDNS 工作正常。
PS:avahi-autoipd 确实没有必要。