Entries in /etc/hosts file
Feeling a wee bit foolish asking this question but after days of research I keep coming up with a headache and conflicting information, which is hard on a perfectionist!
Situation:
4. me: server admin noob & only days old here
OS: Hardy Heron/Ubuntu 8.04 LTS
CMS: Drupal 6.16 – to be installed using multisite configuration, which enables Drupal to run multiple sites from one install with each (dev & prod) site using its own mysql database
Goal:To have test sites and live sites on one linode, although this may change later
Problem
I am trying to figure out the correct entries for the /etc/hosts file. On my Win XP box locally and a Win 2003 server I was able to work on remotely for awhile, it was simple. I just added the registered domain names and unregistered names to the windows hosts file, associating them with the IP…and then I set up virtual hosts in the httpd file of apache, each pointing to the drupal index.php file used for install.
When I read the various how to's for /etc/hosts in ubuntu, I read what seems to me conflicting information. In one instance, I read that one just does this entry (x=numbers)
__127.0.0.1 localhost
69.164.XXX.XXX registered domain name, sans www but with extension .com or .org__
Elsewhere I read that one must use a three column entry and machine name and domain name:
__127.0.0.1 localhost.localdomain localhost #localdomain??
69.164.xxx.xxx magdalen.test magdalen #magdalen is machine name; test is name of dev site
69.164.xxx.xxx magdalen.learn.uidaho.edu magdalen__
1. So what's the scoop with the three column versus two column entries? When do I use which?
2. Do I use the machine (host name) or not?
3. What's with the localhost.localdomain entry??
4. In my current set up on Win boxes, I have fake.domain.local (example) associated with localhost IP on winxp local PC (dev. server). And, I have real.domain.com associated with public IP on the live server. I solved file path problems that occur when loading dev files to live site by adding a patch with an array in it to Drupal 6x core that causes
THANK YOU in advance!!
3 Replies
IP-address canonical-hostname [aliases...]
Suppose your primary name for your Linode at 12.34.56.78 is foo.example.com, and you also want to refer to it as example.com as well as just foo. You would add the following line to /etc/hosts:
12.34.56.78 foo.example.com example.com foo
You should leave the line for localhost as it was originally provided (actually, you can add stuff onto the end of the line, but you shouldn't change the canonical hostname for 127.0.0.1). My Ubuntu 8.04 server simply has
127.0.0.1 localhost
See man 5 hosts
Keep in mind that the entries in /etc/hosts will not affect IP address resolution by other hosts - you need to modify your DNS entries for that.
"You should leave the line for localhost as it was originally provided (actually, you can add stuff onto the end of the line, but you shouldn't change the canonical hostname for 127.0.0.1)."
Those instructions contrast with the ones from the Getting Started section here at linode. It reads:
"You'll also want to make sure proper entries for your Linode's fully qualified domain name (FQDN) and localhost are set up in your /etc/hosts file. You can use the following example file, modifying the entries to suit your setup (12.34.56.78 should be replaced with your Linode's IP address). File: /etc/hosts
127.0.0.1 localhost.localdomain localhost
12.34.56.78 something.yourdomain.com something"
My hosts file simply has the 127.0.0.1 localhost
So the Linode instructions are to set localhost as the alias and localhost.localdomain as canonical domain name???? What the? And is that to be typed verbatim???
I like your way best.
127.0.0.1 localhost.localdomain localhost
If you're really determined, try reading this whole thread:
Can't say I have the patience or mental capacity to understand all the issues involved, so my approach remains the same as my earlier suggestion: keep the default canonical name provided by the distro. If you need to, you can add aliases to the end of the line.