From 4584ef857f3b074b7de3d7af7c2194fd00311668 Mon Sep 17 00:00:00 2001 From: Norio Nomura Date: Sat, 1 Nov 2025 15:45:12 +0900 Subject: [PATCH 1/3] pkg/driver/vz: Enable mDNS in guest using `systemd` on macOS host This change allows resolving `.local` to guest ip by mDNS on macOS host. e.g. ```console $ limactl start --name shared-and-vznat --tty=false --network=lima:shared,vzNAT --containerd=none --log-level error ... $ dns-sd -q lima-shared-and-vznat.local DATE: ---Sat 01 Nov 2025--- 15:31:14.555 ...STARTING... Timestamp A/R Flags IF Name Type Class Rdata 15:31:14.555 Add 40000003 27 lima-shared-and-vznat.local. Addr IN 192.168.64.2 15:31:14.555 Add 40000002 31 lima-shared-and-vznat.local. Addr IN 192.168.105.3 ^C $ ping -c 1 lima-shared-and-vznat.local PING lima-shared-and-vznat.local (192.168.64.2): 56 data bytes 64 bytes from 192.168.64.2: icmp_seq=0 ttl=64 time=0.568 ms --- lima-shared-and-vznat.local ping statistics --- 1 packets transmitted, 1 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 0.568/0.568/0.568/0.000 ms ``` Signed-off-by: Norio Nomura --- .../vz/boot/06-enable-mdns-on-systemd.sh | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 pkg/driver/vz/boot/06-enable-mdns-on-systemd.sh diff --git a/pkg/driver/vz/boot/06-enable-mdns-on-systemd.sh b/pkg/driver/vz/boot/06-enable-mdns-on-systemd.sh new file mode 100644 index 00000000000..da5c0e9f62f --- /dev/null +++ b/pkg/driver/vz/boot/06-enable-mdns-on-systemd.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# SPDX-FileCopyrightText: Copyright The Lima Authors +# SPDX-License-Identifier: Apache-2.0 + +set -eux -o pipefail + +# Do nothing on OpenRC systems (e.g., Alpine Linux) +if [[ -f /sbin/openrc-run ]]; then + exit 0 +fi + +# It depends on systemd-resolved +command -v systemctl >/dev/null 2>&1 || exit 0 +command -v resolvectl >/dev/null 2>&1 || exit 0 + +# Configure systemd-resolved to enable mDNS resolution globally +enable_mdns_conf_path=/etc/systemd/resolved.conf.d/00-lima-enable-mdns.conf +enable_mdns_conf_content="[Resolve] +MulticastDNS=yes +" +# Create /etc/systemd/resolved.conf.d/00-lima-enable-mdns.conf if its content is different +if ! diff -q <(echo "${enable_mdns_conf_content}") "${enable_mdns_conf_path}" >/dev/null 2>&1; then + mkdir -p "$(dirname "${enable_mdns_conf_path}")" + echo "${enable_mdns_conf_content}" >"${enable_mdns_conf_path}" + systemctl daemon-reload + systemctl restart systemd-resolved.service +fi + +# On Ubuntu, systemd.network's configuration won't work. +# See: https://unix.stackexchange.com/a/652582 +# So we need to enable mDNS per-link using resolvectl. +for iface in $(resolvectl status | sed -n -E 's/^Link +[0-9]+ \(([^)]+)\)/\1/p'); do + # This setting is volatile and will be lost on reboot, so we need to set it every time + resolvectl mdns "${iface}" yes +done From ab0d64c82240d3614d2d5c579fa0983073307cf2 Mon Sep 17 00:00:00 2001 From: Norio Nomura Date: Sat, 1 Nov 2025 18:11:17 +0900 Subject: [PATCH 2/3] 06-enable-mdns-on-systemd.sh: Add checking `systemd-resolved.service` is enabled Signed-off-by: Norio Nomura --- pkg/driver/vz/boot/06-enable-mdns-on-systemd.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/driver/vz/boot/06-enable-mdns-on-systemd.sh b/pkg/driver/vz/boot/06-enable-mdns-on-systemd.sh index da5c0e9f62f..78b77ffc94a 100644 --- a/pkg/driver/vz/boot/06-enable-mdns-on-systemd.sh +++ b/pkg/driver/vz/boot/06-enable-mdns-on-systemd.sh @@ -12,6 +12,7 @@ fi # It depends on systemd-resolved command -v systemctl >/dev/null 2>&1 || exit 0 +systemctl is-enabled -q systemd-resolved.service || exit 0 command -v resolvectl >/dev/null 2>&1 || exit 0 # Configure systemd-resolved to enable mDNS resolution globally From a59ced406fed74ec7d31cbbe393d5f35d43b7679 Mon Sep 17 00:00:00 2001 From: Norio Nomura Date: Sun, 2 Nov 2025 09:57:10 +0900 Subject: [PATCH 3/3] Move `06-enable-mdns-on-systemd.sh` from `pkg/driver/vz` to `pkg/cidata` Signed-off-by: Norio Nomura --- .../cidata.TEMPLATE.d}/boot/06-enable-mdns-on-systemd.sh | 1 - 1 file changed, 1 deletion(-) rename pkg/{driver/vz => cidata/cidata.TEMPLATE.d}/boot/06-enable-mdns-on-systemd.sh (95%) diff --git a/pkg/driver/vz/boot/06-enable-mdns-on-systemd.sh b/pkg/cidata/cidata.TEMPLATE.d/boot/06-enable-mdns-on-systemd.sh similarity index 95% rename from pkg/driver/vz/boot/06-enable-mdns-on-systemd.sh rename to pkg/cidata/cidata.TEMPLATE.d/boot/06-enable-mdns-on-systemd.sh index 78b77ffc94a..da5c0e9f62f 100644 --- a/pkg/driver/vz/boot/06-enable-mdns-on-systemd.sh +++ b/pkg/cidata/cidata.TEMPLATE.d/boot/06-enable-mdns-on-systemd.sh @@ -12,7 +12,6 @@ fi # It depends on systemd-resolved command -v systemctl >/dev/null 2>&1 || exit 0 -systemctl is-enabled -q systemd-resolved.service || exit 0 command -v resolvectl >/dev/null 2>&1 || exit 0 # Configure systemd-resolved to enable mDNS resolution globally