Proper Layout of /etc/hosts
I know this is a basic topic, and I have set these up many a time in simple environements and gotten the machine to work but I wanted to ask the forum about this question since I have read several help files online that have not really NAILED DOWN my question on /etc/hosts in a way in which I may want to use it.
I'm looking for the best practice in setting up the /etc/hosts for a linux box called "linuxserv" with an internal domain of abc.com and external domain of xyz.com. Heres how I set up a basic system, IS IT WRONG TO GIVE IT TWO NAMES THAT POINT TO 127.0.0.1? # Do not remove the following line, or various programs # that require network functionality will fail. 127.0.0.1 localhost.localdomain localhost 127.0.0.1 linuxserv.abc.com linuxserv What about adding the internal IP address of the system like so, DOES THE FORMAT BELOW LOOK ACCEPTABLE? # Do not remove the following line, or various programs # that require network functionality will fail. 127.0.0.1 localhost.localdomain localhost 127.0.0.1 linuxserv.abc.com linuxserv 192.168.1.2 linuxserv.abc.com linuxserv Now lets say linuxserv also had a second network interface that links to the external network. What about adding the external IP address of the system like so, DOES THE FORMAT BELOW LOOK ACCEPTABLE? # Do not remove the following line, or various programs # that require network functionality will fail. 127.0.0.1 localhost.localdomain localhost 127.0.0.1 linuxserv.abc.com linuxserv 192.168.1.2 linuxserv.abc.com linuxserv 234.X.X.X linuxserv.xyz.com linuxserv What would make any of these unacceptable, or wrong in a best practice environement? :confused: :Pengy: |
Quote:
|
That did not really clear up my question. I'm looking for someone to reply with information regarding my setup posted above. I understand the basics but wanted to get a better grasp of the hosts file and its formats.
|
127.0.0.1 linuxserv.abc.com linuxserv
192.168.1.2 linuxserv.abc.com linuxserv 234.X.X.X linuxserv.xyz.com linuxserv I believe that these lines would cause a problem. One thing that is sometimes done is to block access to a certain website by making its IP address 127.0.0.1 in the hosts file. 127.0.0.1 localhost localhost.localdomain 127.0.0.1 www.crackerland.com That is assuming that /etc/hosts is searched first. That is true if a line in your host.conf is: order hosts,bind |
Here's the first few lines of my primary /etc/hosts file:
Code:
$ cat /mnt/fc3/etc/hosts | more |
What is wrong with the original hosts file?
Here is my understanding of hosts files:
Repeating the "linuxserver" entry without a comment (#) before it is not correct. This entry is interpreted as an alias for the IP address on the line. In the hosts file with multiple repeats of the same alias the last entry of that alias wins. If you want to clarify that the hosts file entry is a Linux Server, change the entries to " # linuxserv" Also, with respect to "Is it correct to have two lines with the same IP" the answer is no. -The last entry of the same IP is the one that has precedence. -The correct method is to put all the aliases on one line separated by white space (spaces or tabs) One additional point: -For the server you are on, the last alias on the line should be "loghost". -This has two purposes. -The first is to clarify the host machine in the file. -The second is to explicitly tell applications which is the host to write log files to. I normally put the loghost line fairly close after the lines: " # Do not remove the following line, or various programs # that require network functionality will fail. 127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 " |
Ummm. not quite.
You can have as many lines as you want. As many names as you want on a single line even. What ever looks good to you. When looking up the name given the IP number, only the first one will be given. When looking up an IP number for a given name, the IP number of the first line with the matching name is given. The format convention is: IPnumber canonical-hostname alias alias... The canonical-hostname is assumed to mean the FQDN name equal to that used by the domain name system. But it doesn't have to. The alias names are just that - alternate names, sometimes short, alternate spellings, or just to allow for name changes (the alias would conventionally be the old name.. but during a change it could even be the new name). This is a simple linear search - comments are ignored. For a reference see the manpage (man hosts). The only reason the 127.0.0.1 line should be present is that the local loopback interface (lo0) is usually initialized before the other network interfaces are, and before a DNS server might be started - thus allowing the localhost to exist by default. This also applies to the IPv6 local host (the ::1 is the IPv6 version of localhost). |
Quote:
Quote:
Quote:
Quote:
|
All times are GMT -5. The time now is 06:25 AM. |