DNS pre-resolve at server

445 Views Asked by At

Is there a way to resolve DNS at server (using PHP), then include that pre-resolved IP address with domain name in html? So client's browser fetches directly from that IP without having a need to resolve DNS first?

Here is a bit more clarification. My PHP generated page has many external links to js, css and image files from different domains. It takes much time when DNS is resolved on clients' browsers. It can be done very fast on server but I don't want to links those resources directly from IP address. Instead I want something that tells browser that the domain example.com is hosted at 1.1.1.1 for example and no need to perform a DNS lookup.

Is it possible? or can there be a workaround?

Some thing like dns-prefetch with a value or attribute?

<link rel="dns-prefetch" href="http://example.com" value="1.1.1.1" />

Thanks in advance.

1

There are 1 best solutions below

5
On

Well, you can resolve dns-name to IP.

  1. While PHP can't do this, you can create a test file on your server. After that you fetch request for his file. According OSI model, DNS client will resolve DNS name->IP, after that you will have IP in your HTTP headers, because your real query depend on IP of server.
  2. Low level. Windows and Linux both have an API for resolving DNS name -> IP. So you can use their functions in C++ to get IP without test file.
  3. Or you can construct DNS message: DNS-message => UDP-datagram => IP-package. After you send it to DNS-server and wait for answer.

Your DNS-server IP you can find in your config.