Solved Correct way to set up /etc/hosts

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
 
You can remove that localhost.my.domain. It's just an example. You might want to add localhost.at.mybox though.
 
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..
 
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 ;)
 
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?
 
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:
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:
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.
 
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?
 
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
 
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.
 
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).
 
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.
 
Back
Top