Wednesday, July 3, 2019

domain name system - Why do I need to set a hostname?



I know there's quite a few questions about host names. But even after reading them, I didn't really understand the concept of host names entirely. So here's my question:



I've been following this guide in setting up a VPS with Linode.




The first step is to set a host name. From what I understand, a host name is just an arbitrary name you can set to identify your machine in a network. Also, the FQDN is the host name plus the domain name (which can or can not be related to web domains hosted on the server). Please correct me if I'm wrong.



Then it instructs me to modify /etc/hosts and add in something like:



12.34.56.78    plato.example.com    plato


So my question is, what exactly does this line accomplish? I've done it before but never really understood what it did. Also, if the host name and the domain name used in the FQDN is just arbitrary, where can they be used? Actual use cases would be very helpful and detailed explanation would be great. Thanks!


Answer




Certain applications will use the hostname for certain parameters unless explicitly set. Postfix, for example, will identify itself using the hostname of the machine unless you specify otherwise in the config file.



The hosts file is used for name resolution. When resolving domain names, your server will check its hosts file before making a DNS request.



That line you posted will essentially make your server resolve "plato.example.com" and "plato" to that IP address. Thats why you'll generally see the first line with 127.0.0.1 localhost localhost.localdomain .... so the server will always resolve its hostname to itself.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...