/etc/hosts problem when choosing other hostname then osmc

During regular installation of osmc version feb 2016. the /etc/hosts/ file does not get updated if you choose another hostname then osmc.

This causes problems with samba and ssh connections to other osmc devices in the network.
Please fix :smiley:

PRETTY_NAME=ā€œOpen Source Media Centerā€
NAME=ā€œOSMCā€
VERSION=ā€œFebruary 2016ā€
VERSION_ID=ā€œ2016.02-4ā€

/etc/hosts does not need to be updated. We use nss-myhostname

Have you tried rebooting before reporting problems ? What ā€œproblemsā€ do you see exactly, if you still see any after a reboot ?

Ive reinstalled osmc and rebooted about 60 times this week, as I have extensivly tested
stuff ive been doing on osmc :smiley:

The problems I am experiencing are that since the last updates the my other OSMC boxes do not connect to my original one (called) osmc via ssh.

When I connected from my server called naspberry (osmc feb 2016) I got resolved to localhost by /etc/hosts/ so that.

But Ill test it 20 more times and then get back to you about itā€¦
Maybe I am missing something ā€¦

Have I tried rebooting before reportingā€¦ have you checked your own /etc/hosts/ ?

Thanks! :smiley:

Tried it again ā€¦ on a virgin install:

If I want to connect on the command line from an osmc-box renamed to naspberry during installation, to an osmcbox called osmc. The naspberry box will standard only resolve to it self.
because this is in the /etc/hosts file:

::1 osmc localhost6.localdomain6 localhost6
127.0.1.1 osmc

127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

So unless you change the /etc/hosts/ to this

::1 naspberry localhost6.localdomain6 localhost6
127.0.1.1 naspberry

127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

During installation when the installer is asking you, if you want to change the hostname.
the hostname only is changed in /etc/hostname. and not in /etc/hosts
So if you want to: ping, ssh, nfs, from the command line of the naspberry box to a box called osmc it does not work it loops back to 127.0.1.1 (ipv4) or ::1 (ipv6)

Also not after a reboot,

Or am I missing something?

Did you read the nss-myhostname page I linked to, to see how it works ?

It automatically resolves the hostname set in /etc/hostname. For example if I change my hostname to ā€˜veroā€™ then from the same machine ping vero it will resolve to 127.0.0.1 automatically - no changes to /etc/hosts needed.

Yes, that is because there is still a default entry for ā€˜osmcā€™ in /etc/hosts, so ā€˜osmcā€™ will still resolve to the localhost as well. I would recommend that if you have multiple devices you donā€™t call any of them ā€˜osmcā€™ to avoid this.

The whole reason for using nss-myhostname is so that we donā€™t have to programatically go parsing and modifying the users /etc/hosts file, as doing a truly robust parser that will seek out and change only the correct hostname entries is non-trivial. Unfortunately a side effect is that the original redundant osmc entry remains.

It may be possible for us to completely leave out the osmc /etc/hosts entry now that we use nss-myhostname to avoid this problem in future.

cc @sam_nazarko

Do not get me wrong ā€¦ So you clearly do not intend it to be a multi user system.
And only want it to be what youā€™ve created a jukeboxā€¦

It is not a problem for me that the installer does not do it. I can do it myself.

It just brings expectations the moment the installer suggests that one can change the hostname, one would think that it would also resolve correctly from the command line one would even expect that the installer will change the nsswitch.conf. in which you refer to

hosts: files myhostname mdns4_minimal [NOTFOUND=return] dns mdns4 ā€¦

Does the average user even care that you use nss-myhostname?
They would probably not even care about this issue either.

For some what ever reason I have not seen it work yet ā€¦ What kind of a nameserver are you running on your network? Probably one that is setup perfectly ā€¦

I am looking at this from a user friendly non-bug point of view , how hard is it to append adding the new host name to the /etc/hosts/ properly from the installer? probably less work then not including it all togetherā€¦

:smiley:

As someone who has just been reading this thread in passing, Iā€™m slightly confused ā€¦

Just change the hostname from osmc to something else and it will all work, E.g.:

The problem you are having is because the current installation leaves behind a single ā€œ/etc/hostsā€ file entry called ā€œosmcā€. Iā€™m sure, if itā€™s considered a problem, that will be fixed, but as @DBMandrake also pointed out:

And heā€™s right - it is; your question:

Shows that you donā€™t realise whatā€™s actually involved in doing that correctly (you canā€™t just append like that ā€¦).

So what is the problem with just not calling your osmc box ā€œosmcā€? Youā€™ve changed the name of one, just change the name of the other as well and it will all work correctly.

Why is that an issue?

Then why suggest the name OSMC during installation all together ā€¦

From a user friendly point of view , Its should say Pick any name but not OSMC ,

Read back this entire thread ā€¦ I am not attacking you ā€¦ From the get go I was basically told to stfu

"Have you tried rebooting before reporting problems ? What ā€œproblemsā€ do you see exactly, if you still see any after a reboot ? " as if the issue does not ecxist.

As if my suggestion did not matter and how dare I even write it up ā€¦

So what would you suggest it pick?

OSMC is a perfectly sensible default name.
If youā€™ve only got one OSMC system, itā€™s a perfectly good name.
If you want to have more than one OSMC system, youā€™d change the name anyway - you canā€™t have ā€œosmcā€ and ā€œosmcā€ and expect anything to be able to differentiate between them.

So for the one specific case where you want more than one machine, still insist on calling one ā€œosmcā€, and want to be able to resolve that name from the command line, you might want to make one simple edit to one text file.
Since thatā€™s the only circumstances under which this would be any sort of issue, probably not worth changing installation messages, is it ā€¦

OSMC is a super name and I think you guys do great work!! I want to be able to use the name osmcā€¦
But its you that suggested I can not or one could not ā€¦ Please read back

If someone decides to use another hostname ā€¦ next to this default ā€œosmcā€ hostnameā€¦ on his network.

You suggest this name by default so its safe to say that atleast the first box in a network of multiple is called OSMCin 80% of cases.

But say then if you call another box ā€œsomething-elseā€ ā€¦ Reboot ā€¦

And thenā€¦
want to get some stuff from host ā€œosmcā€ you can not because on the commandline of
host ā€œsomething-elseā€ you get resolved to localhost.(instead of ā€œsomething-elseā€).
and there is no nsswitch.conf. which is going to stop it from doing so ā€¦

So please say you understand now ā€¦ I want to use OSMC as a host name

Then how can you stand by this answer:

Yes, that is because there is still a default entry for ā€˜osmcā€™ in
/etc/hosts, so ā€˜osmcā€™ will still resolve to the localhost as well. I
would recommend that if you have multiple devices you donā€™t call any of
them ā€˜osmcā€™ to avoid this.

What on earth does multi-user have to do with the hostname ?

Youā€™re getting a bit muddled up. If you check /etc/nsswitch.conf youā€™ll see that it already has ā€˜myhostnameā€™ there. We donā€™t expect anyone to need to edit that file manually.

The ā€œinstallerā€ is actually the walkthrough process, which runs once after installation. One of the things it offers to do is change the hostname. You can change the hostname via Kodi at any time - the normal location of the setting is ā€œDevice nameā€ in Settings->Services->General.

Normally this setting only changes Kodiā€™s idea of the device name, (for Airplay for example) however we have gone out of our way to patch Kodi so that changing the name here also changes the system hostname at /etc/hostname for you automatically. So no manual editing of /etc/hostname is required either.

It doesnā€™t matter what nameserver Iā€™m using - the myhostname entry is the second entry in nsswitch.conf - it is higher priority than everything except /etc/hosts. This is partly done for security reasons.

Iā€™ve explained already what your problem is - the new name that you select will resolve correctly from that device however because there is still a manual entry for ā€˜osmcā€™ in /etc/hosts this will prevent any OSMC install from being able to correctly resolve another osmc install that is still called osmc.

To fix this we would need to remove the osmc entry from /etc/hosts completely. Now that we have nss-myhostname (it was only added a couple of months ago) we can probably do this - but we wonā€™t be retroactively editing the users /etc/hosts file (thatā€™s why we added nss-myhostname in the first place) so that change would only be for new installs.

In the meantime my suggestion is if you have multiple installs, donā€™t name any of them osmc, or edit /etc/hosts yourself.

The main purpose of these hosts entries is that some software that runs on the system needs to be able to resolve its own hostname, regardless of what that might be. (sudo is a good example) that is where nss-myhostname provides a nice clean, automated solution.

1 Like

OSMC is a super name and I think you guys do great work!! I want to be able to use the name osmcā€¦
But its you that suggested I can not or one could not ā€¦ Please read back

If someone decides to use another hostname ā€¦ next to this default ā€œosmcā€ hostnameā€¦ on his network.

You suggest this name by default so its safe to say that atleast the first box in a network of multiple is called OSMCin 80% of cases.

But say then if you call another box ā€œsomething-elseā€ ā€¦ Reboot ā€¦

And thenā€¦
want to get some stuff from host ā€œosmcā€ you can not because on the commandline of
host ā€œsomething-elseā€ you get resolved to localhost.(instead of ā€œsomething-elseā€).
and there is no nsswitch.conf. which is going to stop it from doing so ā€¦

So please say you understand now ā€¦ I want to use OSMC as a host name

Then how can you stand by this answer:

Yes, that is because there is still a default entry for ā€˜osmcā€™ in
/etc/hosts, so ā€˜osmcā€™ will still resolve to the localhost as well. I
would recommend that if you have multiple devices you donā€™t call any of
them ā€˜osmcā€™ to avoid this.

Please say you understand my responses.

Iā€™ve explained twice now what is causing your problem, why it is currently the way it is, how you can easily solve your problem (by editing one file) and have said twice now that we will look into changing the /etc/hosts file on a fresh install to prevent this happening in the future. This is an issue that we are well aware of but like any bug it has to come somewhere on our priority listā€¦

So I donā€™t know what more you expect ?

1 Like

I already wrote I can do that myself ā€¦

I am sorry I think I missed/ am missing the point here.

Lets maybe trim back the topic a bit then no need to let others suffer ā€¦

Thanks

Iā€™ve not seen anybody (you or the OSMC developers - of which Iā€™m not one, BTW, just another user trying to help ā€¦) being ā€œattackedā€; neither did I read any response as telling you to ST*U.

I think perhaps there might be some misinterpretation of tone due to the language difference - although your English is very good, the ā€œ,ā€ quotation marks are usually an indication :slight_smile:

You said you had problems, but didnā€™t explain what they were.
Now it is clear what the problem is, youā€™ve been told:

  1. Two work-arounds for the issue (edit 1 line in 1 text file, or donā€™t call both boxes ā€œosmcā€)
  2. That the developers are aware of it and will consider a fix at some point.
  3. Exactly why it is currently being done that way, and how any fix would resolve it.

Your suggestion has been ruled out as impractical (it is considerably more complex than you seem to understand), and unnecessary if the developers fix it as they seem to intend to.

So your issue is understood; you have 2 alternative work-arounds for it; a proper fix will be considered for a future release. Seems you should have everything you could want ā€¦?

Fantastic!!

Indeed I think the issue is mostly communication!
Your reply is absolutly fantastic :smile_cat: !!

Thanks!

1 Like

In the past we have recommended that to change the hostname completely, you edit both /etc/hostname and update the loopback references in /etc/hosts as well.

However to greatly simplify the process we set up a callback in Kodi so that changes to the Device Name always update the hostname, and that changes to /etc/hostname also update Kodiā€™s Device Name. This allows users to change their system hostname without any command line interaction. Additionally, it reduces confusion (some users may have believed in the past that modifying this Kodi setting was changing their hostname) and offers a greater level of persistence (deleting Kodiā€™s user data will not erase the previously configured device name).

Modifying /etc/hosts when this is done would have been inappropriate, as there are a few issues that can occur. The most obvious challenge is that we need to know the previous hostname. However if a user edits /etc/hostname manually, then we would be unable to assess how /etc/hosts should be structured without knowin the previous hostname, and without knowing whether the previous hostname had also been reflected in /etc/hosts.

Using libnss-myhostname lets us resolve those gethostname() calls which can occur when you edit /etc/hostname, but not /etc/hosts and then run any command with a privileged context (i.e. sudo)

Sam

2 Likes