First of all I searched the site for similar topic, and read the RFC 1535 and FQDN wiki, they don't seem to answer the question.
Let me use www.youtube.com
as an example. Python script I used:
import socket
for host in ["www.youtube.com"]:
print(host)
try:
hostname, aliases, addresses = socket.gethostbyname_ex(host)
fqdn = socket.getfqdn(host)
print(" Aliases : ", aliases)
print(" Hostname : ", hostname)
print(" FQDN : ", fqdn)
print("Addresses : ", addresses)
except socket.error as msg:
print("%15s : ERROR: %s" % (host, msg))
Output:
Aliases : www.youtube.com
Hostname : youtube-ui.l.google.com
FQDN : sa-in-f93.1e100.net
Addresses : ['74.125.200.93', '74.125.200.190', '74.125.200.136', '74.125.200.91']
1) What is the relation between hostname and FQDN?
According to the website http://kb.iu.edu/d/aiu (and many other sites): For a mail server "mymail.somecollege.edu", the hostname is "mymail", the domain is "somecollege.edu", and combined together these form the FQDN. But clearly this isn't the case for www.youtube.com
. So, what is FQDN exactly and what is the relation between all these names?
2) When I reverse lookup the IP 74.125.200.93, the hostname become sa-in-f93.1e100.net
. Why does the reverse lookup give me FQDN as a hostname? Are these names interchangeable?
socket.gethostbyaddr('74.125.200.93')
Hostname : sa-in-f93.1e100.net
Aliases : []
Addresses : ['74.125.200.93']
3) Is Aliases : www.youtube.com
also know as CNAME? According to http://support.dnsimple.com/articles/cname-record/ the answer seems to be yes:
For example, if you have a server where you keep all of your documents online, it might normally be accessed through docs.example.com. You may also want to access it through documents.example.com. One way to make this possible is to add a CNAME record that points documents.example.com to docs.example.com. When someone visits documents.example.com they will see the exact same content as docs.example.com.
4) If that is true why I can't use "youtube-ui.l.google.com" or "sa-in-f93.1e100.net" to visit YouTube? This is what I got by visiting hostname and FQDN directly:
Google
404. That’s an error.
The requested URL / was not found on this server. That’s all we know.
EDIT #1
Sorry about the slow reply, I'm still reading those RFC docs, and I have some new questions:
Again using www.youtube.com
as example.
5)How FQDN is generated? Does it query parent domain until root(dynamically generated) each time I call socket.getfqdn()
or host -t PTR
? Or is it just a PTR record?(seems like query FQDN rely on reverse look up) If it is a PTR record, then how can I be sure it is a FQDN, actually it can be FQDN, CNAME, alias, hostname or some other name if zone dns admins want to set it up like that. Just like David and Esa Jokinen pointed out (RFC 1912, 2.1), if these rules are not enforced then how can I be sure what am I getting?
So I'm thinking maybe query parent domain until root IS the most reliable way to get FQDN. But how can I do that? Is it even possible to get FQDN without using PTR
(since it's not relialbe)
6)Is it possible for DNS query go backwards?
Normally query for IP is cache/recursive server ask root then TLD then subdomain until it gets the IP. Is it possible to do this backward? Got the IP then somehow got the subdomain then TLD then root then I got the FQDN?
7)Isn't FQDN and IP should be 1 to 1 mapped?
Here is what I got when I run
host 216.58.193.78
output:
78.193.58.216.in-addr.arpa domain name pointer sea15s07-in-f78.1e100.net.
78.193.58.216.in-addr.arpa domain name pointer sea15s07-in-f14.1e100.net.
How come one IP mapped to two FQDN? One machine two FQDN, how does it work?
Regardless of the semantics of term FQDN we must see what Python's
socket.getfqdn()
does.In other words,
getfqdn()
looks for reversePTR
record first, regardless of whatA
orCNAME
record has pointed to it in the first place. It looks for a fully qualified domain name (FQDN) and simply gives you the first suitable one i.e. the first one that ends with.
, the root.So,
FQDN : sa-in-f93.1e100.net
comes from thePTR
record for IP74.125.200.93
.Here, the FQDN for this hostname
www
having domainyoutube.com
is actually by definitionwww.youtube.com.
, including the dot. Likewise, thesa-in-f93.1e100.net
is not a FQDN, as it should actually besa-in-f93.1e100.net.
:sa-in-f93
as subdomain for1e100
sa-in-f93.1e100
as subdomain fornet
sa-in-f93.1e100.net
as subdomain for the root,.
.Why
sa-in-f93.1e100.net.
is chosen overwww.youtube.com.
simply comes from how thesocket.getfqdn()
is designed to determine the FQDN of a given name.On the other hand, the Canonical Name
CNAME
record SHOULD by design (RFC 1035, 3.2.2) point to the canonical name, but it's commonly used like it was just an alias, because it works like one. Also, thePTR
record SHOULD (RFC 1912, 2.1) give the same result, as it should represent the canonical name for the given IP.If only that was obeyed, the method
socket.getfqdn()
uses would have been completely appropriate. Here, theCNAME youtube-ui.l.google.com.
without the correspondingPTR
record (93.200.125.74.in-addr.arpa. IN PTR youtube-ui.l.google.com.)
made this assumption false.