Path: blob/master/pkg/cidata/cidata.TEMPLATE.d/boot/06-enable-mdns-on-systemd.sh
2678 views
#!/bin/bash12# SPDX-FileCopyrightText: Copyright The Lima Authors3# SPDX-License-Identifier: Apache-2.045set -eux -o pipefail67# Do nothing on OpenRC systems (e.g., Alpine Linux)8if [[ -f /sbin/openrc-run ]]; then9exit 010fi1112# It depends on systemd-resolved13command -v systemctl >/dev/null 2>&1 || exit 014command -v resolvectl >/dev/null 2>&1 || exit 01516# Configure systemd-resolved to enable mDNS resolution globally17enable_mdns_conf_path=/etc/systemd/resolved.conf.d/00-lima-enable-mdns.conf18enable_mdns_conf_content="[Resolve]19MulticastDNS=yes20"21# Create /etc/systemd/resolved.conf.d/00-lima-enable-mdns.conf if its content is different22if ! diff -q <(echo "${enable_mdns_conf_content}") "${enable_mdns_conf_path}" >/dev/null 2>&1; then23mkdir -p "$(dirname "${enable_mdns_conf_path}")"24echo "${enable_mdns_conf_content}" >"${enable_mdns_conf_path}"25systemctl daemon-reload26systemctl restart systemd-resolved.service27fi2829# On Ubuntu, systemd.network's configuration won't work.30# See: https://unix.stackexchange.com/a/65258231# So we need to enable mDNS per-link using resolvectl.32for iface in $(resolvectl status | sed -n -E 's/^Link +[0-9]+ \(([^)]+)\)/\1/p'); do33# This setting is volatile and will be lost on reboot, so we need to set it every time34resolvectl mdns "${iface}" yes35done363738