Entries in /etc/hosts file

Hi –-

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

  1. OS: Hardy Heron/Ubuntu 8.04 LTS

  2. 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

  3. 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 http://fake.domain.local to call the drupal/sites/water folder and http://real.domain.com to do the same. Is it possible to do this same set-up on my linode?

THANK YOU in advance!!

3 Replies

There isn't really a two-column vs. three-column format. The format is

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 for more.

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.

Hey, thanks Vance. Appreciate the help. Question re what you wrote here:

"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.

You'll have to ask Phil why the Linode library recommends localhost.localdomain. As noted earlier, Ubuntu 8.04 does not use this by default. Note that Red Hat/CentOS does:

127.0.0.1    localhost.localdomain   localhost

If you're really determined, try reading this whole thread:

http://lists.debian.org/debian-devel/20 … html#01063">http://lists.debian.org/debian-devel/2005/09/thrd3.html#01063

http://lists.debian.org/debian-devel/20 … html#00194">http://lists.debian.org/debian-devel/2005/10/threads.html#00194

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.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct