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?

3
  • 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. Jun 25, 2013 at 17:27
  • @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
    Jun 25, 2013 at 17:33
  • 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. Jun 25, 2013 at 17:49

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .