Is there a DNS query to obtain the DNS suffix of a PC on my network?

1

1

I'm trying to programmatically obtain the IP address of a remote PC on my network from the PC's hostname. The PC is running as an Apache server. It is my understanding that in the DNS query used to obtain the IP address from the hostname, the DNS suffix needs to be appended to the hostname. Can I query the DNS server to get the DNS suffix used for this PC?

Kevin

Posted 2013-06-25T17:04:20.113

Reputation: 21

No, but you can look at the DNS suffix that's configured in the DHCP server on the router, which is where these hostnames get registered. This assumes a standard consumer-grade router operating as a DNS forwarder and DHCP server. – Darth Android – 2013-06-25T17:27:36.737

@DarthAndroid I'm programming at a low level so what I'm looking for is some kind of network request packet where I can get the DNS suffix as a response. – Kevin – 2013-06-25T17:33:07.483

I don't think that information is available. You might be able to grab it from the DHCP offer, but I'm not sure if that is sent out to the clients. – Darth Android – 2013-06-25T17:49:59.587

Answers

1

Normally, DHCP and your host's DNS resolver will take care of this:

  1. DHCP returns the domain name (what you need to append to a simple (non-dotted) hostname to make it a fully qualified domain name (FQDN))
  2. Your system's DHCP client will store this somewhere (on Unix/Linux machines in /etc/resolv.conf, together with the DNS server addresses also obtained in the DHCP offer)
  3. When you ask your operating system (e.g., POSIX gethostbyname()) for a host's IP address, it will turn the hostname into an FQDN (if it already looks like an FQDN, i.e., contains dots, it won't do anything, otherwise append the domain name)

So, if you only use your OS's "official" functions, you do not need to know the full name. If you send out DNS packets manually, you will need to obtain that information from the configuration files (or, in Windows, the registry).

If this is an internal network (e.g., a private network behind a NAT box), the "FQDN" address returned will not be valid outside that network.

Marcel Waldvogel

Posted 2013-06-25T17:04:20.113

Reputation: 401