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?