title: differences between hostname and fully qualified domain name(FQDN)
body: <p>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.</p>
  
  <p>Let me use <code>www.youtube.com</code> as an example. Python script I used:</p>
  
  <pre class="lang-python prettyprint-override"><code>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))
  </code></pre>
  
  <p>Output:</p>
  
  <pre class="lang-none prettyprint-override"><code>  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']
  </code></pre>
  
  <p><strong>1) What is the relation between hostname and FQDN?</strong></p>
  
  <p>According to the website <a href="http://kb.iu.edu/d/aiu" rel="nofollow noreferrer">http://kb.iu.edu/d/aiu</a> (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 <code>www.youtube.com</code>. So, what is FQDN exactly and what is the relation between all these names?</p>
  
  <p><strong>2) When I reverse lookup the IP 74.125.200.93, the hostname become <code>sa-in-f93.1e100.net</code>. Why does the reverse lookup give me FQDN as a hostname? Are these names interchangeable?</strong></p>
  
  <pre class="lang-python prettyprint-override"><code>socket.gethostbyaddr('74.125.200.93')
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code> Hostname :  sa-in-f93.1e100.net
    Aliases :  []
  Addresses :  ['74.125.200.93']
  </code></pre>
  
  <p><strong>3) Is <code>Aliases : www.youtube.com</code> also know as CNAME? According to <a href="http://support.dnsimple.com/articles/cname-record/" rel="nofollow noreferrer">http://support.dnsimple.com/articles/cname-record/</a> the answer seems to be yes:</strong></p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p><strong>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:</strong></p>
  
  <pre class="lang-none prettyprint-override"><code>Google
  
  404. That’s an error.
  
  The requested URL / was not found on this server. That’s all we know.
  </code></pre>
  
  <p><strong>EDIT #1</strong></p>
  
  <p>Sorry about the slow reply, I'm still reading those RFC docs, and I have some new questions:</p>
  
  <p>Again using <code>www.youtube.com</code> as example.</p>
  
  <p><strong>5)How FQDN is generated?</strong> Does it query parent domain until root(dynamically generated) each time I call <code>socket.getfqdn()</code> or <code>host -t PTR</code>? 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?</p>
  
  <p>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 <code>PTR</code>(since it's not relialbe)</p>
  
  <p><strong>6)Is it possible for DNS query go backwards?</strong></p>
  
  <p>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?</p>
  
  <p><strong>7)Isn't FQDN and IP should be 1 to 1 mapped?</strong></p>
  
  <p>Here is what I got when I run</p>
  
  <pre class="lang-none prettyprint-override"><code>host 216.58.193.78
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>How come one IP mapped to two FQDN?
  One machine two FQDN, how does it work?</p>