Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I just signed up for a VPS with Linode, and am going through the beginners' setup instructions, but am a bit lost with the editing for /etc/hosts. It suggests that I edit it as follows (where 12.34.56.78 is my server's ip):

127.0.0.1        localhost.localdomain        localhost
12.34.56.78      something.yourdomain.com     something

the file currently reads:

127.0.0.1 localhost

# The following lines are desirable for IPv6 capable hosts
...

First of all, does it matter which of the two localhost lines I use?

Secondly, I don't understand the purpose of the second line - Since the first refers to an IP of 127.0.0.1, I assume these are local addresses, so why would my server's address be of any consequence? Also, I don't presently want any subdomains - should I not include this line, or change it to something else? Does this affect the DNS connection between my domain name and the server?

I'm rather new at this, so I apologize in advance for any silly questions, and thank you for any help you can offer.

share|improve this question

3 Answers 3

up vote 1 down vote accepted

The first line is the loopback, that is, referring back to your own server. This is intrinsic to every computer system.

The second line is to establish which IP the server has been assigned, and which domain the server should serve.

You want to have both lines in the file. You can even have more lines similar to the second one, one for each domain being served.

share|improve this answer
    
So if I don't want a subdomain, should the line read 173.230.157.100 www.mydomain.com (That is, with a www). Also, does it need an alias and, if so, does it matter what it is? –  wyatt Aug 25 '10 at 6:51
    
I think I may have misunderstood this - is the leftmost part of the FQDN not a subdomain at all, but the name of the machine in question? If so, does it matter at all what I call it? –  wyatt Aug 25 '10 at 7:07

In the /etc/host the format of each entry is:

[internet address] [domain name] [alias]

  • internet address - a standard IP address, i.e. 127.0.0.1
  • domain name - A Fully Qualified Domain Name, FQDN, i.e. www.google.com
  • alias - this field is optional, i.e. localhost

the first line of your host file that refers to 127.0.0.1 could be modified also like this :

127.0.0.1 localhost

the other line that you set in this file have precedence in DNS resolution,your server before query a DNS Server look at this file /etc/host for resolve FQDN in IP address, therefore edit carefully this file.

share|improve this answer

Aleroot's answer is mostly correct, with the minor correction that the file name is /etc/hosts.

Please also be aware there is a file /etc/host.conf on most modern Linux systems I have seen which controls the order by which a domain name is resolved; the defaults I have seen are

hosts
dns

where the hosts file is used before any DNS lookup. Thus, it is important to be careful what hosts you put in /etc/hosts, as they will never look at DNS.

As an example, I've seen it where someone puts an entry for host FOO in the /etc/hosts file. Some months or years later when DNS is changed for FOO they wonder why said machine can't reach FOO. The problem was the hardcoded entry in /etc/hosts.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.