You are not logged in.

#1 2017-02-11 20:28:30

jwhendy
Member
Registered: 2010-04-01
Posts: 621

definitive format for /etc/hosts?

Greetings,


Way back sometime, I'm near positive the wiki suggested the following for /etc/hosts (which I'll call "legacy" format):

#<ip-address>	<hostname.domain.org>	<hostname>
127.0.0.1	localhost.localdomain	localhost    myhostname
::1		localhost.localdomain	localhost    myhostname

I just installed on a new drive and noticed the wiki now as the following (which I'll call "new" format):

Hostname

Create the hostname(5) file:

/etc/hostname

myhostname

Consider adding a matching entry to hosts(5):

/etc/hosts

127.0.0.1	localhost.localdomain	localhost
::1		localhost.localdomain	localhost
127.0.1.1	myhostname.localdomain	myhostname

There's conflicting info all over the place.

legacy
- /etc/hosts
- is this correct please? /etc/hosts
- what is localhost.localdomain for?: quite an interesting thread with some various distro entries cited showing inconsistency

new
- wik on network config
- arch install guide
- man hosts appears to call out the new format

EXAMPLE
       # The following lines are desirable for IPv4 capable hosts
       127.0.0.1       localhost

       # 127.0.1.1 is often used for the FQDN of the machine
       127.0.1.1       thishost.mydomain.org  thishost

Then again, it doesn't have "localhost.localdomain localhost" as the line, but just "localhost"?

Anyway, to some degree I don't really even care as long as this doesn't break anything. I'm unaware of ever needing this feature, but in some of those threads it seemed like aliasing sped up network speed?

Perhaps the main questions are:
- should "myhostname" be on the 127.0.0.1 line?
- should "myhostname" also/and/or be on a line with 127.0.1.1?

Offline

#2 2017-02-11 21:14:18

Alad
Wiki Admin/IRC Op
From: Bagelstan
Registered: 2014-05-04
Posts: 2,412
Website

Re: definitive format for /etc/hosts?


Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby

Offline

#3 2017-02-12 17:19:49

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: definitive format for /etc/hosts?

You could just check 'man hosts'

For  each  host  a  single  line should be present with the following information:
IP_address canonical_hostname [aliases...]

You can add your hostname at the end of the 127.0.0.1 line without problems.


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#4 2017-02-12 22:14:18

jwhendy
Member
Registered: 2010-04-01
Posts: 621

Re: definitive format for /etc/hosts?

@R00KIE: I posted an example right out of /etc/hosts showing 127.0.0.1 with only localhost. Did you see it? I agree I can certainly check man entries, but I see inconsistencies around the web for this recommendation, including a change in Arch's own recommendation. I'd be willing to update the wiki with additional information, for example:

- what does setting up /etc/hostname and /etc/hosts do?
- what happens if you add your hostname alias to /etc/hosts and what happens if you don't?
- what happens if you use 127.0.0.1 vs. 127.0.1.1?
- does any of this affect a typical user's setup/functionality?

I understand I can add my hostname to the end of the line... this is what I've had for years. The question is what it should be, if it matters at all. For a long-ish time Arch user, it's confusing to have one thing on an old setup and then see the wiki's been changed with it's recommendation. My preference is this is avoided and sources are cited with respect to the recommendation.

Hopefully that clarifies what I'm after.

These are all the variants I've seen thus far:

/etc/hosts

127.0.0.1    localhost
127.0.0.1    localhost.localdomain    localhost
127.0.0.1    localhost.localdomain    localhost    myhostname
127.0.1.1    myhostname.localdomain    myhostname  ## in addition to a solo "120.0.0.1  localhost" entry

Offline

#5 2017-02-13 18:00:47

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: definitive format for /etc/hosts?

Nothing stops you from putting everything in only one line under 127.0.0.1, but if for some reason you don't want that I suppose you can use any other IP in the range 127.0.0.0/8 as that will land on the loopback anyway.

Regarding the wiki, it can be edited by anyone thus it might reflect the preference of whoever edited it last. I suppose that it might be easier to tell people to add a new line to /etc/hosts than to tell new users to edit an existing line and not screw it up.

As long as it works and you know what you've done I'd say use whatever you prefer, just because other people start using a different format doesn't mean you have to blindly follow.


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#6 2017-02-13 18:23:34

jwhendy
Member
Registered: 2010-04-01
Posts: 621

Re: definitive format for /etc/hosts?

@R00KIE: for sure. While I love arch, I don't have a ton of time to dive into the depths of linux. I rely on the wiki to give me trusted knowledge for implementing things I don't have a reason to fully understand (or fully understand "yet").

I agree I don't have to blindly follow, but my questions still stand:

- what does setting up /etc/hostname and /etc/hosts do?
- what happens if you add your hostname alias to /etc/hosts and what happens if you don't?
- what happens if you use 127.0.0.1 vs. 127.0.1.1?
- does any of this affect a typical user's setup/functionality?

You're just telling me I can use what I already have... but again it wasn't clear from the wiki on why one vs. the other. Part of posting here is if someone knowledgeable could answer the question definitively, I'd gladly edit the wiki myself to explain a little or point to a helpful resource no why /etc/hosts should be this way or that. It's sounding more and more like it doesn't matter at all. If I were still in college I'd just remove things (like any reference to "myhostname" at all) and see what breaks. At the moment I don't want to do that smile

The other issue is sometimes "as long as it works" is fine because the user just hasn't run into a problem with it yet. So maybe from this thread I assume "it doesn't matter" and in months I post an issue with VPN or something and someone asks me to post the output of /etc/hosts. I do so and then they say "Why the hell haven't you got a 127.0.1.1 line?! It's clearly documented in the wiki that this new such and such change requires that!" Just a hypothetical example but not that ridiculous. When I see new information, I assume wiki authors are more knowledgeable, and thus more likely to be correct.

So I asked.

Offline

#7 2017-02-13 19:37:31

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: definitive format for /etc/hosts?

The reason for all this confusion is because of historically buggy DNS assumptions in software - e.g. Gnome, glibc.

Software has thankfully settled down to where just this is sufficient:

127.0.0.1    localhost

Although, combining IPv4 and IPv6 still seems flaky (sadly), so I recommend sticking to IPv4.

Offline

#8 2017-02-13 19:50:10

jwhendy
Member
Registered: 2010-04-01
Posts: 621

Re: definitive format for /etc/hosts?

@brebs: I'll just take your word on that... I'm not parsing much of the content in those with my current knowledge!

Re. ipv6, does that affect the default line containing:

#<ip-address>	<hostname.domain.org>	<hostname>
::1		localhost.localdomain	localhost

?

Offline

#9 2017-02-13 20:05:59

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: definitive format for /etc/hosts?

I mean having no "::1" entries in /etc/hosts, and blacklisting the "ipv6" kernel module.

This is extreme, but effective smile

Offline

#10 2017-02-13 20:20:20

jwhendy
Member
Registered: 2010-04-01
Posts: 621

Re: definitive format for /etc/hosts?

@brebs: interesting. I've run into this at least once in the past! I've never known what to do with that thing. As unexpected evidence (you reminded me!) that these sorts of things actually can matter, here's a post from me sometime ago where I had ipv6 commented out and cups stopped working for me!

Then again, I was just in a different building at work that has a newer internet infrastructure (not sure on all the details, but there's been emails about it) and I couldn't even connect via ethernet in a conference room. Checking dmesg spit out something about not getting an ipv6 address, I commented out the ::1 line, and I was able to connect to a wired connection. Who'd have thought!?!

Offline

#11 2017-02-13 20:31:42

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,525
Website

Re: definitive format for /etc/hosts?

Note that there may be differences in documentation due to the requirements of a "regular" system versus on servers.

For "regular" systems (e.g., your desktop/laptop/media-center PC/kerosene-powered cheese grater) the requirements are fairly lax: there are a lot of ways to set up /etc/hosts what will work just fine.

For web servers you need to be a bit more strict.  For email servers (in my experience) you need to be even more strict.  I don't know what exactly is "right" nor what the logic is - but I've learned through the experience of setting up a few servers what actually works or doesn't - and in contrast to web/email servers it really feels like nearly "anything goes" for /etc/hosts for home computers.  For my web and mail server I need the following:

127.0.0.1                            localhost.localdomain     localhost
45.NN.NNN.NNN                        MyHostName.domain.org     MyHostName www Subdomain Subdomain2
::1                                  localhost.localdomain     localhost
2600:XXXX::XXXX:XXXX:XXXX:XXXX       MyHostName.domain.org     MyHostName www Subdomain Subdomain2

where Ns are decimal digits and X's hex digits.  Any deviation from this format that I've tried leads to a failure of the mail and/or web server (the mail fails first).  An exception is that the subdomains may be unneccesary ... which I've only just realized as I've added more subdomains without adding them to /etc/hosts and everything still seems fine.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB