I just bought a Linode VPS hosting plan and was following this guide to set up. In the "Setting the Hostname" section and "Update /etc/hosts
" section, it says the FQDN/hostname to be set here does not need to be related with the websites I am about to host, which makes me confused.
I did my own research by reading lots of articles but am still not very sure what role the hostname/FQDN is playing in my web hosting business. Here are some basic facts I've managed to find out, feel free to correct me if anything wrong:
- FQDN must be something like xxx.somedomain.com, if "xxx." is omitted then it is not a FQDN.
- the
xxx
, which I think could be loosely called a subdomain, can also be referred to as "hostname", according to https://kb.iu.edu/d/aiuv. -
In my local machine, by adding the following line to the
hosts
file63.117.14.58 www.yahoo.com whatever
every network requests for "www.yahoo.com" or "whatever" will be redirected to IP address 63.117.14.58(which is google.com's IP). It is a way to block unwanted sites in local machine.
Now the tutorial suggests adding this line to the "hosts" file in my server
12.34.56.78(//my server's IP) myhostname.anything.com myhostname
It mentions that in the above line, domain name may or may not be the domain I am about to host, but the hostname should be the one I have already set during previous steps. My questions are:
1)Based on Facts#3, I think this line redirects any requests on the server for myhostname.anything.com
or myhostname
to my IP address, but what does this mean? Shouldn't any request for myhostname.anything.com
from a user's computer already be translated to a certain IP address(Be it or not my IP address)? Why do I have to redirect it on my server? My understanding about how a HTTP request works is when user type in the domain name into the browser, the browser will contact the domain server, and the domain server will direct it to a DNS server based on the domain's DNS record, and then the DNS server will resolve the IP address, and then browser fetch data from that IP address. This procedure of my understanding seems having nothing to do with the "hosts" file on my server.
2)
A.In regards of the FQDN, why the hostname has to be same with the hostname I set on my server and the domain name doesn't?
B.What will happen if I do set a different hostname here?
C.And what is the purpose to set or not set my domain name as the FQDN here?
D.And what will happen if I only set a FQDN but not the hostname? like this
12.34.56.78(//my server's IP) myhostname.anything.com
Lots of questions but I believe the answers to some of them are overlapped, and overall I think the big question is "What part does setting hostname/editting hosts file play in my webhosting business?"
Thank you for your time in advance.
Best Answer
It's going to be rough for people to answer this question because it starts with a simpler premise and proceeds to go down a deep rabbit hole from there. Let's start from the beginning.
Host file vs. DNS
I don't think this needs much explanation, so I'll keep it brief. The purpose of the hosts file is to define host to IP address mappings that do not rely upon DNS. The most important of these for a server is the device's own name, because it's silly for a problem with your DNS server to prevent your device from being able to refer to itself by name.
So long as we're only using host files, we don't need to use domains at all. DNS isn't involved, so who cares? Unfortunately as our network grows, it becomes less sustainable to have each device independently tracking the name of all devices on our network. That leads us to using DNS, and introduces some new logistical hurdles.
Hostname vs. FQDN
Hostnames are device names, or node names if you prefer. It's a uniquely identifying name that is meaningful to the device owner, and not necessarily meaningful or even exposed to people consuming the services on the device. This is what Linode means when it says that the name doesn't need to have anything to do with the services that you're hosting.
For example, let's say you own a company named Contoso, and you operate a website called
example.com
. The website is hosted on six machines, nameddalek01
throughdalek06
. All the outside world needs to know is that they can get the website they want if they plugwww.example.com
into their web browser. Overly inquisitive Time Lords need not concern themselves with the fact that their request forwww.example.com
was serviced bydalek03
.By itself, a hostname doesn't necessarily have anything to do with DNS at all. It's just the name of the device, and it doesn't even necessarily have a domain suffix associated with it. So far it's simple!
Now we make things a little trickier. Story time!
www.example.com
, because it's hosted by several different machines. It's a good thing we have a uniquely identifying name for the server with a problem!dalek01
throughdalek06
into a DNS domain somewhere. Fortunately we owncontoso.com
(named after our company), completely separate fromwww.example.com
, which might be one of our customers.corp.contoso.com
. All of our desktop machines are configured with a DNS search suffix ofcorp.contoso.com
. This means that if we create a DNS entry calleddalek01.corp.contoso.com
, anyone on our network can get to that machine simply by connecting todalek01
with their SSH client. Convenient!dalek01
knows that it's calleddalek01
because we put it in the hosts file. We want it to know that it's also calleddalek01.corp.contoso.com
, but we don't want it to rely on DNS to know its own name. That would be silly. Therefore we define an alias fordalek01.corp.contoso.com
in the hosts file ondalek01
so that it knows all of its names.www.example.com
, oblivious to the fact that you have six servers nameddalek01
throughdalek06
, the fact that your company is named Contoso (your customers aside), or that to make things convenient for your employees you created DNS records fordalek01
throughdalek06.corp.contoso.com
.Putting it all together
Hopefully this covers all the bases.