Because I know that @milo usually uses AI, that he refuses to disclose AI generated text, and because what I saw there looks like AI slop. I’ve stopped wasting my time on slop. If anybody wants my help, they must actually take the time to explain themselves, not feed it through some LLM that will make up half the details.
It’s a hostname that is created for the IP address 192.168.64.201. There will only be an IPv4 record for that hostname. So, when you try to ping it with IPv6, there will be no IPv6 entry to ping.
Mhhm strange thinking, because it’s marked not with AI what is necessary according to the community posts.m..it’s just technical explanation with a lot of examples from the code..
I looked into this because of the GitHub issue (#5944). As far as I can tell from the code: MDNSClientImpl creates JmDNS with JmDNS.create(address, null). JmDNS then takes the host name from a reverse lookup of the interface address, and if that returns the IP itself it builds 192-168-100-100.local. from it. So it is not a name collision (in that case JmDNS appends -1), and there is no setting for it at the moment.
The PR addresses this
@Hape if you want to try it, which openHAB version are you on? I can then build a matching JAR.
I checked this in the source, and it doesn’t work that way. On a real name collision, JmDNS (3.6.5, the version openHAB uses) appends a counter: openhab-1.local., then -2 and so on (NameRegister.incrementNameWithDash). It never falls back to the IP in that case.
True, the services come from the bindings and org.openhab.core.io.rest.mdns. But the host name in the A/AAAA records belongs to the JmDNS instance that this bundle creates per interface address, no matter who registers the service. That is why Hape sees the wrong name disappear when he stops org.openhab.core.io.transport.mdns and come back when he restarts it, and why mdnsName doesn’t change it.
So the cause is the null name in that one call, and the PR passes the system host name there instead.
@milo has repeatedly shown that he doesn’t respect any marking of slop, and he has even suggested that things should be assumed to be slop unless unless marked as “human generated”. When you do things like that, expect others to expect that what you post is slop.
The “solution” gets the problem wrong. As I’ve explained above, using the IP (with . replaced by -) is the most pragmatic solution because getting the actual hostname is difficult (depending on platform) and even if you get the hostname, there’s no way to know which IP address that is the “main one” that you should register it with. It would require further configuration options in OH that let you manually specify this, for very little value.
You don’t need mDNS for name resolution on the local network. Depending on your network setup, there are other mechanisms you can use, like letting DHCP (if yo use that) register it in DNS. If you use a fixed IP, you can make a fixed DNS entry.
There’s a lot more to it. When you pass null for “name”, JmDNS tries to resolve the hostname in this method:
When I debug the code, it actually resolves my actual hostname until it reaches line 103, where it matches aName.equalsIgnoreCase(addr.getHostName()) and thus replaces the hostname with the IP address. I don’t know why JmDNS does this, but I’m sure there’s a reason.
I wrote that before I checked the source. The hostname is “resolved” in newHostInfo() which I linked to above. The IP address comes from this line (that I’ve already linked above):
The .s are then replaces with -s further down in the code, after which .local. is added.
That is not what’s happening when I debug the code (but it can very between platforms). My actual hostname is retrieved, but it is since replaced with the IP address on line 104.
The actual cause why the hostname is being replaced by the IP address seems to stem from:
You’re right that my earlier explanation (name collision) was wrong; the cause is the host name check in HostInfo.newHostInfo() (jmdns #304).
On the IP being pragmatic: #1510 changed the name argument to null so the reverse-lookup name would be used, so the IP-derived name looks like a side effect rather than a design decision. The PR only passes the system host name and keeps the current behaviour if none is found.
The open point is the “main IP” problem you mention (several addresses sharing one name). According to.the description it not tested with avahi on the same host yet. But a jar is available so some need to test it
Regarding @milo if he pings someone he was directly admonished if I don’t or you no one cares I guess it’s more a failure of the moderation and a hunting against him
Thanks for the offer, but since everything in my smart home is running smoothly, and the only thing it’s really bothering is my inner perfectionist, it’s not necessary.
Thanks for the discussion so far. A short update from my side:
To rule out avahi I masked it completely. The result is not better, it’s worse: without avahi, openhabpi does not resolve at all on the FRITZ!Box any more. As soon as I stop the openHAB mDNS bundle (org.openhab.core.io.transport.mdns) and start avahi again, the name is stable. With the bundle running, the A record keeps flapping.
In the bundle’s debug log I see the JmDNS instances registered under IP-derived names such as 192-168-1-50.local. and 192-168-1-50-eth0.local., never under the real host name. My assumption is that the FRITZ!Box takes these names over from mDNS and drops openhabpi. I can’t prove the exact mechanism on the box side, but the correlation is reproducible (A/B/A tests).
Looking at MDNSClientImpl, the cause seems to be JmDNS.create(address, null): with null as name, JmDNS derives the name from the address.
milo built a test version for this (thanks!) that passes the system host name to JmDNS. I looked at the bytecode: besides that change it only has a small queue for service registration in MDNSServiceImpl, no file/process/network access beyond JmDNS itself. The build is for 5.3.0-SNAPSHOT though, I run 5.3.0.M3, so I’ll test as soon as a matching build is available and report back.
I’d like to keep openHAB’s mDNS discovery enabled, so disabling the bundle is not a real option for me.
To me, this looks to be a misunderstanding of how this is supposed to work. The fact that you think that openhabpi should resolve using mDNS is probably the core of the problem. Where does that idea come from?
I assume that this is the hostname that you have assigned to the computer (RPi?) running OH. But, that doesn’t mean that OH will register that hostname using mDNS, and there’s no obvious reason why it should. As I’ve explained before, there’s a couple of reasons for this:
Acquiring the hostname from the OS consistently in a cross platform way isn’t easy. It will often fail, especially on Linux that can’t even agree with itself how the hostname should be registered. As such, you’d really need to create a new configuration option in openHAB itself where you could configure with “hostname” to register.
Even if you find a way to consistently acquire the hostname, there’s no way to know what is the “main IP” to register the hostname to. That means that it could register to an IP “that you didn’t plan for” first, with the result that you’d sometimes have to use openhabpi-1 or openhabpi-2 etc. to reach your host. Not a very elegant solution.
If the desire is name resolution on the local network, it’s much better to do this “the old fashioned way”. There are various ways to achieve it, you can get DHCP to register the name with DNS or create a static DNS entry if you have a static IP, or you can use a different name resolution service. I use WINS for such purposes, because it’s so simple and just works.
I don’t think the idea that the mDNS registration should be used for local name resolution is reasonable, there are too many challenges. It’s there to provide access to “mDNS services”, and it does that as it should. As a side effect, it “has to” register a hostname, and that hostname must be unique. Other than that, the hostname doesn’t matter, which is why it makes sense to let JmDNS figure out which name to use.
It’s not “worse”, OH doesn’t try to register openhabpi. It’s as it should. You’ll never get mDNS to work properly if you run two mDNS services on the same computer, so you need to disable avahi if you want things to function properly (I’m not talking about the hostname resolution, I’m talking about generally).
The reason for this is that since mDNS is based on multicast, both avahi and OH will have to register to listen to the exact same IP/port combination. They don’t know about each other, but they will both get “a copy of” any incoming packets. So, they will both reply to them, but the reply will often be different - if a peer is asking for hostname openhabpi, both “yes” and “no” will be sent in return. If a peer asks for OH’s REST API, the same will happen. They will never agree on anything, and any peers will be severly confused and behavior will be “random”. You simply aren’t supposed to run two such services on the same device!