-
Notifications
You must be signed in to change notification settings - Fork 746
pkg/cidata: Enable mDNS in guest using systemd
#4272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AkihiroSuda
merged 3 commits into
lima-vm:master
from
norio-nomura:enable-mDNS-in-guest-using-systemd-on-macOS-host
Nov 2, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
4584ef8
pkg/driver/vz: Enable mDNS in guest using `systemd` on macOS host
norio-nomura ab0d64c
06-enable-mdns-on-systemd.sh: Add checking `systemd-resolved.service`…
norio-nomura a59ced4
Move `06-enable-mdns-on-systemd.sh` from `pkg/driver/vz` to `pkg/cidata`
norio-nomura File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
pkg/cidata/cidata.TEMPLATE.d/boot/06-enable-mdns-on-systemd.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this work with other drivers with lima:shared ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work with QEMU, krunkit, and other potential drivers too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, PR's title was not correct. Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll test with other drivers on macOS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works with qemu and krunkit.
Is there already a way to limit the execution of the boot script by the host OS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script shouldn't care about the host OS. There should be a CIDATA variable that indicates the existence of IP-reachable network.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first, I tried to enable mDNS on the corresponding interface when Direct IP was detected, not as a boot script.
However, if there is no mDNS environment on the host OS side, I thought it would be meaningless to enable it, so I wanted to limit it to macOS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved
06-enable-mdns-on-systemd.shfrompkg/driver/vztopkg/cidata.