Hacker News new | ask | show | jobs
by mahboi 20 days ago
I have a completely default single router setup at home. I know .50 is my desktop and .1 is my router. How do I reach that via mDNS instead? Pretty sure this is broken.

  ~ $ arp -a
  ? (192.168.50.1) at e8:9c:25:52:83:10 on en0 ifscope [ethernet]
  ? (192.168.50.9) at 64:9a:63:eb:ed:f1 on en0 ifscope [ethernet]
  ? (192.168.50.50) at 14:98:77:70:17:a7 on en0 ifscope [ethernet]
2 comments

On a Mac, run `dns-sd -B _ssh._tcp` to find all machines advertising SSH on your local network. From there, you can either use the advertised `.local` hostname directly, or you can pass the advertised friendly name to `dns-sd -G v4` to resolve it to an IPv4 address.

AFAIK you must always specify a service like `_ssh._tcp` or `_http._tcp`; you can’t ask dns-sd to just dump all the advertised mDNS services on your network. That might be possible with the underlying `nw_browser_t` APIs, though.

Thanks, so this one works for my Mac (.50) in particular but not my RPi on the same network with an SSH server, because turns out it doesn't advertise that by default.

"you can’t ask dns-sd to just dump all the advertised mDNS services on your network": I ran into this too. So besides the defaults and maybe network itself standing in the way, the tooling around mDNS is user-unfriendly.

Yes, thanks, I do not want even any SSH server to be advertised on mDNS.
Me neither really, I just want to reliably know the hostname<->ipaddr mapping on a network.
Run a classic DNS then.

Or hosts.

You are arguing what mDNS doesn't work the exact way you want therefore mDNS is not working for everyone else.

mDNS doesn't work for the average user. They're also not going to set up regular DNS unless they're trying to cope with IPv6. They memorize IP addresses as needed. It's not just me.

There must be like 3 end users who actually use mDNS knowingly, which is why the tooling feels like an unhappy path. Like there's no way to list all hosts, even though the OS presumably knows that somewhere. Supposedly this is in the spec. The best you can do is list hosts that advertise services.

This is to discover services, which you really shouldn't need to do by hand outside of troubleshooting, your apps should be doing it themselves.

For address discovery which is what we're really talking about here it's just "<hostname>.local"

I was answering the question of “how do I discover another host’s mDNS hostname?” It turns out that is a per-service question.
> I was answering the question of “how do I discover another host’s mDNS hostname?” It turns out that is a per-service question.

No, it's not. That is a service address, not the host's hostname.

The host's hostname is whatever the computer is named, which if you are in a position where you're wanting to give someone else its IPv4 address or access your own thing via its IPv4 address you definitely can also know it's hostname because it's either shown in the same parts of the GUI or one command away. On a lot of CLI systems it's literally in the prompt.

Either way it's not advertised unless that host is configured to advertise itself, you have to query for it and the host will then respond.

Not every host lets you SSH into it to run commands. The mDNS hostname is not always the same as your system hostname since it can change due to conflicts. Some Linux distros don't even have a built-in util to show your own mDNS name.
> Not every host lets you SSH into it to run commands.

Not sure how this is relevant. The context we're talking about here is someone wanting to communicate to another person how to connect to their laptop. We can assume that this person has sufficient access to the device to get this information.

You're not trying to work backwards from an unknown device here, if you're doing that you presumably have the ability to copy/paste the full address from whatever tool you used to identify the device's existence on the network.

> The mDNS hostname is not always the same as your system hostname since it can change due to conflicts.

And it changes in predictable ways, with the mainstream desktop OSes presenting a notification to the user in case of conflicts. If yours doesn't, consider that a flaw in your OS.

Also, if this is a real issue you run in to more than once in a blue moon it's probably worth picking a more unique name.

> Some Linux distros don't even have a built-in util to show your own mDNS name.

systemctl status avahi-daemon

should do the trick on any mainstream Linux distro, and if you're one of the anti-systemd crowd you presumably know your equivalent.

<hostname>.local

Here's me pinging my laptop (macOS 27) from my file server (Ubuntu 24.04)

  ~ ping persephone.local
 PING persephone.local (fd82:74ca:1cef:385a:1897:2e4b:a726:18b6%3) 56 data bytes
 64 bytes from fd82:74ca:1cef:385a:1897:2e4b:a726:18b6: icmp_seq=1 ttl=64 time=0.496 ms
 64 bytes from fd82:74ca:1cef:385a:1897:2e4b:a726:18b6: icmp_seq=2 ttl=64 time=0.515 ms
 ^C
 --- persephone.local ping statistics ---
 2 packets transmitted, 2 received, 0% packet loss, time 1001ms
 rtt min/avg/max/mdev = 0.496/0.505/0.515/0.009 ms
Only if you know the name already and no two hosts took the same name, assuming it works at all. Shouldn't those question marks be the hostnames on arp -a? On some networks it shows them, on others it doesn't.
> Only if you know the name already and no two hosts took the same name, assuming it works at all.

We're talking about somebody who knows how to get the IPv4 address of their computer, the hostname is available in basically the same exact place on every single system, and easier to remember, and remains the same on every network unless there's a conflict.

It works as long as the network operator of system admin hasn't gone out of their way to break it.

> Shouldn't those question marks be the hostnames on arp -a? On some networks it shows them, on others it doesn't.

Those question marks will fill in if there is a reverse dns entry in the local DNS server, which is set in IPv4 networks based on the device putting its hostname in the DHCP request. Most consumer combo gateway devices will do this by default as does Windows DHCP, but a lot of business firewall devices don't do it at all or don't do it by default.

Either way, that's not relevant to IPv6, mDNS is the way.

"Most consumer combo gateway devices will do this by default as does Windows DHCP, but a lot of business firewall devices don't do it at all or don't do it by default.": Guess that explains it. I have a home router, but maybe its defaults are more business-like.

I'm pretty frequently in a scenario where I know local v4 addrs but not hostnames, usually on a network that's not my own. But even on my own network cause there's no simple way to discover the names, so not everything is a Linux box I can SSH into to ask the hostname. I'd use mDNS if I could reliably type something in to show all the DNS entries on the LAN, never having to diagnose any issues with this.