You are not logged in.

#1 2009-03-16 19:17:14

Nazgulled
Member
Registered: 2009-03-08
Posts: 102

Correct syntax for the hosts file

Every wiki page I read and every forum post I read, I seem to find always different ways to configure the hosts file. One recommends one way and says it's the correct way, while another says different.

My hostname in /etc/rc.conf is "NAZARCH" and my current "hosts" file is this:

#
# /etc/hosts: static lookup table for host names
#

#<ip-address>    <hostname.domain.org>    <hostname>
127.0.0.1        NAZARCH.localdomain    NAZARCH    localhost
192.168.1.100    VMHOST.localdomain     VMHOST

# End of file

The "192.168.1.100" IP is the IP of my host machine (I'm running VirtualBox) and I want the hostname "VMHOST" to point to that IP.

I think I'm doing everything correctly for both entries, but would like the experts opinion.

Offline

#2 2009-03-16 19:26:20

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: Correct syntax for the hosts file

I don't see why that wouldn't work, but try removing VMHOST.localdomain from the second line.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#3 2009-03-16 19:27:28

wonder
Developer
From: Bucharest, Romania
Registered: 2006-07-05
Posts: 5,941
Website

Re: Correct syntax for the hosts file

just ip host
e.g
192.168.1.100 vmhost


Give what you have. To someone, it may be better than you dare to think.

Offline

#4 2009-03-16 19:27:52

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Correct syntax for the hosts file

man hosts

192.168.1.100    VMHOST.localdomain     VMHOST
Is the same as
192.168.1.100 VMHOST.localdomain
192.168.1.100 VMHOST

Offline

#5 2009-03-16 19:29:07

Nazgulled
Member
Registered: 2009-03-08
Posts: 102

Re: Correct syntax for the hosts file

But the default file had "localhost.localdomain localhost".

What about the first line? just ip host too? like:
127.0.0.1 NAZARCH

?

Won't that make "localhost" not too work?

@rson451
I didn't said it was not working, cause it is, I was just wondering for the correct syntax.

Last edited by Nazgulled (2009-03-16 19:30:53)

Offline

#6 2009-03-16 19:30:56

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Correct syntax for the hosts file

If you have
127.0.0.1 localhost.localdomain localhost
127.0.0.1 google.com

Then all those three will point to 127.0.0.1 (try it out with ping)

Offline

#7 2009-03-16 19:32:13

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: Correct syntax for the hosts file

You can define multiple names per ip.  The default way you see is just a way to condense that list.

Edit: OP, I see.  As stated previously, man hosts will show you what you want to know.

Last edited by rson451 (2009-03-16 19:33:37)


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#8 2009-03-16 19:34:22

Nazgulled
Member
Registered: 2009-03-08
Posts: 102

Re: Correct syntax for the hosts file

I see now what you mean.

Thank you all smile

Offline

Board footer

Powered by FluxBB