Solved Correct way to set up /etc/hosts

rota

New Member

Reaction score: 4
Messages: 19

How to configure the /etc/hosts file if my hostname is:
Code:
freebsd.at.mybox
Should it look like this?

Code:
::1                     freebsd freebsd.at.mybox localhost localhost.my.domain
127.0.0.1               freebsd freebsd.at.mybox localhost localhost.my.domain
Edit: Nevermind, found it in the FreeBSD GNOME FAQ, it should look like this

Code:
::1                     localhost localhost.my.domain freebsd freebsd.at.mybox
127.0.0.1               localhost localhost.my.domain freebsd freebsd.at.mybox
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 9,283
Messages: 33,826

You can remove that localhost.my.domain. It's just an example. You might want to add localhost.at.mybox though.
 

osx-addict

Active Member

Reaction score: 3
Messages: 174

What's the purpose of the "::1"? I've never seen that on either Linux, HPUX, AIX or Solaris boxes in the past.. Just curious..
 

osx-addict

Active Member

Reaction score: 3
Messages: 174

Ahh.. I've yet to use a host that has it enabled.. (mine's disabled -- probably 'fear' of the 'unknown') --:p
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 9,283
Messages: 33,826

I've been experimenting with IPv6 for quite some time now. I wanted to get a head start on everybody else :stud

I have seen IPv6 enabled on both Linux and Solaris without it being used. This can lead to unexpected behavior and might even pose a security risk (when services are restricted on IPv4 but wide open on IPv6).

Simple rule, if you don't use it, don't enable it ;)
 

Kamolpat

New Member


Messages: 14

What is the different in /etc/hosts between
example #1
Code:
::1  localhost  localhost.abc.com
127.0.0.1  localhost  localhost.abc.com
203.xxx.xxx.xxx ns1.abc.com  ns1
and

example #2
Code:
::1  localhost.abc.com  localhost
127.0.0.1  localhost.abc.com  localhost
203.xxx.xxx.xxx ns1.abc.com  ns1
I read from various source, some said example #1 some said example #2.

I think the correct one should be example #2, according to common configuration structure. But why in current BSD manual show setting in example #1 (https://www.freebsd.org/doc/handbook/configtuning-configfiles.html on topic 12.8.2.2. /etc/hosts)

Which one is correct and why?
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 9,283
Messages: 33,826

They're both correct. The order on the line is irrelevant as long as the IP address is first.
 

Kamolpat

New Member


Messages: 14

I'm in curious that why the header email (from GMail or any free mail) always show
Code:
Received: from ns1.abc.com (localhost [127.0.0.1])
by ns1.abc.com (8.14.4/8.14.4) with ESMTP id t0R7PDMY099767
Why does it not show right IP of the server, it always shows (localhost[127.0.0.1]) instead of right IP of the server. As I do test with online tool. The open relay is closed. Or this is the correct setting (as I found in others mail's header show similar like this). Can anyone help explain or any useful link that I can read for more?
 
Last edited by a moderator:

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 9,283
Messages: 33,826

Because the connection was made using 127.0.0.1, not the server's IP address.
 

Kamolpat

New Member


Messages: 14

So my setting in example #1 or example #2 is correct and email header:
Code:
Received: from ns1.abc.com (localhost [127.0.0.1])
is all working correctly....right?
 
Last edited by a moderator:

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 9,283
Messages: 33,826

Yes, the 'ns1.abc.com' is what's being sent by the mail client in the HELO/EHLO phase. The address [127.0.0.1] is where the connection really came from. The localhost bit is what was reverse resolved.
 

molofishy

Member

Reaction score: 3
Messages: 52

I've got two servers on the same internet connection: I have to tunnel through server1 to get to server2. My /etc/hosts file on both servers looks like the following:
Code:
::1                     localhost localhost.my.domain
127.0.0.1               localhost localhost.my.domain

10.0.1.5                server1
10.0.1.6                server2
The addition of the last two lines enables me to "ssh server2" from server1, instead of "ssh 10.0.1.6" (a simple pragmatic addition). Is there any value of having the first two lines there or can I delete them? Also, the last two lines only have 2 columns: internet address and alias, although things are working. The hosts man page, suggests 3 columns. What value would this add?
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 9,283
Messages: 33,826

Is there any value of having the first two lines there or can I delete them?
Leave them or you're going to have issues with resolving localhost.

Also, the last two lines only have 2 columns: internet address and alias, although things are working. The hosts man page, suggests 3 columns. What value would this add?
Doesn't matter. If you really want to be 'complete' add the Fully Qualified Domain Name (FQDN):
Code:
1.2.3.4 myhost myhost.example.com
 

kpa

Beastie's Twin

Reaction score: 1,826
Messages: 6,318

The only value of any entry in /etc/hosts is that the names in that file are resolvable without DNS. This can be critical for some services like Sendmail that tries to resolve the hostname early during the system start up and will hang the boot for a while if DNS is not available yet. You can also override DNS responses for the local system if that is desired for some reason.
 

gpw928

Well-Known Member

Reaction score: 125
Messages: 370

Isn't there a dot needed at the end of the domain name?
You don't need the trailing dot, which is generally used when you want to stop the resolvers from appending domains in the search list contained in /etc/resolv.conf.
The most portable approach is to construct each line in /etc/hosts with the fully qualified domain name to immediately follow the IP address, with other aliases after that, e.g.
Code:
192.168.1.21 hp4050n.my.domain hp4050n laserjet printer
This method works with all Unix/Linux variants I know of (in particular, Debian systems require the canonical host name to be mentioned first so that their domain name can be determined by using the resolvers to look up the FQDN of their unadorned host name).
 

proton1234

Member


Messages: 65

with the fully qualified domain name
Yes I know that it will be working without a dot at the end but I've read that FQDN should include dot at the end and without it it won't be fully qualified. That is why I asked the question.
 

gpw928

Well-Known Member

Reaction score: 125
Messages: 370

The host file, and its format, predates the DNS. The trailing dot is used when you want to stop the DNS library resolvers from appending domains in the search list contained in /etc/resolv.conf.
 

msplsh

Well-Known Member

Reaction score: 76
Messages: 261

Looking at resolver, it seems that by default it will not use the search domain on the first try at resolving the name if you have at least one dot in the name, so the trailing one is redundant.
 
Top