DNS lookup

I looked through the documentation but couldn't find the API to do a DNS lookup. Since this is a fundamental capability I presume I'm just missing something.

While on the topic, how do I SSH Into the Hubitat?

You can’t. The hub will resolve a name to an address when necessary, for example to make an http call to another computer.

You don’t. There is no terminal access to the underlying operating system.

5 Likes

I just had to switch hubs and many IP addresses got reassigned. Fortunately, with over 250 devices I can use names rather than addresses so this went smoothly. Except for Hubitat which, for some reason, still doesn't allow the use names rather than IP addresses.

The good news is that I use Hubitat for little beyond Wiz which does give me a way to update the addresses in my app. This problem is a primary reason for my being wary.

Even better would to support multiple name resolution protocols but the DNS is a start.

Also V6 support would be nice too.

Are you referring to when you are trying to call out to a device from an app / driver running on your HE hub, or when accessing your HE hub from another PC or mobile device?

I'm referring to the device drivers in the habitat trying to find devices. Of course when Hubitat does a DHCP request it should also provide a name so, both.

I think there is some confusion somewhere, depending on the device driver/app and how it was built, Hubitat can certainly resolve a DNS entry to an IP when making a connection. It is an implicit action.

1 Like

In that case, we / support may need a few more details on the exact driver you are using @Bob.ma, and the version of the HE software you are running. The router and dhcp setup may be useful, but probably not worth getting to carried away with details too early. BTW - I'm not likely to be the one to help here, just guessing at what may be useful info.

1 Like

Focusing on the devices for now, I'm running
image
(I'll update after I send this)

This is the field for the wiz driver
image

I couldn't find any DSN lookup in the documentation and, in the past, I have tried entering a DNS name but it failed. Can you point me to the documentation for doing a DNS lookup in a driver? I couldn't find it.

I was thinking more the driver itself, so the type drop-down on the device page

I don't understand your question. I've looked at the code for the "Wiz Color Light" driver. I would've added a DNS lookup for the address but can't find any such call in the developer library.

I was meaning it may be relevant for others who can help to know for sure which driver you are using, so the Type drop-down on the Device Edit page for one of your bulbs. The screenshot below shows a virtual device using my Date/Time display driver:

For the purposes of the question, it doesn't matter - what is the API for doing a DNS lookup in Habitat? This is about the APIs and not any particular driver. If I write my own driver how do I do a DNS lookup?

It does matter, I imagine @sburke781 wants to know the driver to look at the underlying code to see what mechanism is used for connecting.

Like I said there is no API for explicit DNS queries (at least as far as I know), the DNS lookup is implicit based on what is provided to particular connection method.

For example, an HTTP request, using a domain for the address. The DNS query for the domain is done implicitly.

def poll() {

Map params = [
uri: "http://checkip.amazonaws.com/",
contentType: "text/plain",
timeout: 10
]

asynchttpGet("httpCallback", params)

}
3 Likes

Actually, that reminds me, are you including a domain when you try to refer to your devices by name, e.g. mybulb.local, or something similar? Networking is not my strong point....

1 Like

The other thought, and may not apply, is that by default the hub uses 8.8.8.8 for its DNS server. Have you tried changing the DNS entry on the hub to a local DNS server (in settings, networking) that may be able to resolve internal names?

I have not tried that, as I have no need for this, but it was a thought. As far as an API call for name resolution, there isn't one that I know of in Hubtat.

4 Likes

@Bob.ma

@sburke781 raised a valuable point. Are you using FQDNs, which I know can be resolved by the hub if the nameserver is configured appropriately, or .local addresses? If it is the latter, I don't think that multicast DNS addresses are resolved by the hub.

2 Likes

Sample code for an NSLookup:

NSLookup
 /*
 *  Nslookup
 */
import groovy.json.JsonSlurper

@SuppressWarnings('unused')
static String version() {return "0.0.1"}

metadata {
    definition (
        name: "Nslookup", 
        namespace: "thebearmay", 
        author: "Jean P. May, Jr.",
        importUrl:"https://raw.githubusercontent.com/thebearmay/hubitat/main/xxxx.groovy"
    ) {
        
      
        capability "Actuator"
        attribute "lookResp","STRING"
        command "nslookup",[[name:"dnsName",type:"STRING",description:"DNS Lookup Name"],[name:"dnsServer",type:"STRING",description:"DNS Server (default: 8.8.8.8)"]]
            
    }   
}

preferences {
}

@SuppressWarnings('unused')
def installed() {

}
void updateAttr(String aKey, aValue, String aUnit = ""){
    sendEvent(name:aKey, value:aValue, unit:aUnit)
}


void nslookup(dnsName, dnsServer="8.8.8.8") {

    Map params = [
        uri: "https://$dnsServer/resolve?name=$dnsName&type=A",
        contentType: "text/plain",
        timeout: 10
    ]

    asynchttpGet("nsCallback", params)

}

void nsCallback(resp, data) {
    
    def jSlurp = new JsonSlurper()
    Map ipData = (Map)jSlurp.parseText((String)resp.data)
    updateAttr("lookupResp", ipData.Answer.data[0])
}
2 Likes

Thanks for the very special case hack for 8.8.8.8. I didn't know Google had provided an https hack - one I may use in other contexts. DNS-over-HTTPS (DoH) | Public DNS | Google Developers

But hack indeed since it doesn't work for other DNS servers and, in particular, the local one provided by my DHCP server. I can't use 8.8.8.8 both because everything has to work locally and because my devices are not the global DNS

So I take it that there is no native DNS support in Hubitat? That's a serious problem.

PS, while it would be nice to support mDNS and other resolution mechanisms, the DNS is still the basic one. So .local is not but FQDN is fundamental.

Hubitat does use DHCP so, I presume, it will use the DNS address provided by DHCP.

You're wrong about this, because I have used FQDNs in devices created using @ogiewon's "HTTP Momentary Switch" driver.

Do you have your Hubitat configured to use your local name server?

It does. I'm wrong - as clarified by @ogiewon below.

I do not believe it does, unless something has changed.

Here is what my C7 using DHCP looks like. As you can see, it is still using 8.8.8.8 for the DNS server.

In your hub’s Network Settings, your should be able to force the DNS server to whatever you’d like (C5/C7 hubs only, IIRC.) If the driver you are using is making http style calls, the you should be able to use a FQDN instead of a local IP address, once the hub is using your own local DNS server.

2 Likes