From 15ec3aaef6b98fc83f7a405e2cd0f328d5fe6799 Mon Sep 17 00:00:00 2001 From: pober Date: Mon, 18 May 2026 15:26:18 +0200 Subject: [PATCH] removes host file to make mdns working. --- src/service/10-link-local-mgmt | 54 +++---------------- .../update_and_run_server_and_frontend.sh | 6 +++ 2 files changed, 13 insertions(+), 47 deletions(-) diff --git a/src/service/10-link-local-mgmt b/src/service/10-link-local-mgmt index e4e7b86..324f759 100644 --- a/src/service/10-link-local-mgmt +++ b/src/service/10-link-local-mgmt @@ -5,6 +5,8 @@ # using nmcli device modify (active session only, NOT saved to the profile). # The persistent profile always keeps ipv4.link-local=enabled so that # direct-connect (no DHCP) plug-ins always activate and trigger events. +# Avahi is reloaded on each event — no /etc/avahi/hosts file, avahi uses +# natural per-interface advertisement so each segment gets the right IP. # # Triggers: up, down, dhcp4-change on ethernet interfaces # Install to: /etc/NetworkManager/dispatcher.d/10-link-local-mgmt @@ -12,56 +14,14 @@ INTERFACE="$1" ACTION="$2" -CONNECTION_NAME="${CONNECTION_ID:-}" - # Only handle ethernet interfaces if [[ ! "$INTERFACE" =~ ^eth ]]; then exit 0 fi -# If CONNECTION_ID env var is not set, look up the active connection for this interface -if [ -z "$CONNECTION_NAME" ]; then - CONNECTION_NAME=$(nmcli -t -f NAME,DEVICE connection show --active 2>/dev/null \ - | grep ":${INTERFACE}$" | cut -d: -f1 | head -n1) - [ -z "$CONNECTION_NAME" ] && exit 0 -fi - -# Update /etc/avahi/hosts to point mDNS hostname at the best available DHCP address -# across all ethernet interfaces (so Avahi doesn't advertise a link-local address). -update_avahi() { - local hostname - hostname=$(hostname) - # Find first non-link-local IPv4 across all ethernet interfaces - local dhcp_ip - dhcp_ip=$(ip -4 addr show 2>/dev/null \ - | grep -A5 ': eth' \ - | grep -oP '(?<=inet\s)\d+(\.\d+){3}' \ - | grep -v '^127\.' \ - | grep -v '^169\.254\.' \ - | head -n1) - - local new_content="" - if [ -n "$dhcp_ip" ]; then - new_content="$dhcp_ip $hostname $hostname.local" - fi - - local current_content - current_content=$(cat /etc/avahi/hosts 2>/dev/null || echo "") - - if [ "$new_content" = "$current_content" ]; then - logger -t nm-link-local "Avahi: hosts unchanged, skipping reload" - return - fi - - if [ -n "$dhcp_ip" ]; then - mkdir -p /etc/avahi - echo "$new_content" > /etc/avahi/hosts - logger -t nm-link-local "Avahi: pinned $hostname -> $dhcp_ip" - else - rm -f /etc/avahi/hosts - logger -t nm-link-local "Avahi: removed hosts pin, using all addresses" - fi +reload_avahi() { systemctl reload avahi-daemon 2>/dev/null || systemctl restart avahi-daemon 2>/dev/null + logger -t nm-link-local "[$INTERFACE] $ACTION — avahi reloaded" } case "$ACTION" in @@ -73,7 +33,7 @@ case "$ACTION" in logger -t nm-link-local "[$INTERFACE] Up — ensuring link-local active (clean slate)" (sleep 2 && nmcli device modify "$INTERFACE" ipv4.link-local enabled 2>/dev/null \ && logger -t nm-link-local "[$INTERFACE] Link-local explicitly enabled on up") & - update_avahi + reload_avahi ;; dhcp4-change) @@ -92,13 +52,13 @@ case "$ACTION" in (sleep 2 && nmcli device modify "$INTERFACE" ipv4.link-local disabled 2>/dev/null \ && logger -t nm-link-local "[$INTERFACE] Link-local suppressed for current session") & fi - update_avahi + reload_avahi ;; down) # NOTE: a carrier-change does NOT fully reset session-level 'device modify' state. # The re-enable is therefore handled in the 'up' handler when no DHCP is detected. logger -t nm-link-local "[$INTERFACE] Down — link-local will be re-enabled on next up without DHCP" - update_avahi + reload_avahi ;; esac diff --git a/src/service/update_and_run_server_and_frontend.sh b/src/service/update_and_run_server_and_frontend.sh index f3cbe46..57d2e27 100755 --- a/src/service/update_and_run_server_and_frontend.sh +++ b/src/service/update_and_run_server_and_frontend.sh @@ -24,6 +24,12 @@ while IFS=: read -r name type; do done < <(nmcli -t -f NAME,TYPE connection show) +# Remove stale avahi hosts pin — this file overrides per-interface advertisement +# and causes mDNS to always resolve to eth0's IP regardless of which interface +# the query arrived on, breaking eth1 mDNS entirely. +sudo rm -f /etc/avahi/hosts +sudo systemctl restart avahi-daemon + # Ensure Loopback is loaded with a fixed name and index # Needed for dante # TODO image when we create the next image this should be part of it