Hostname Invalid Output #1764

Closed
Blackglade opened this Issue Jan 16, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@Blackglade

Issue Report

Bug

hostname -s returns hostname: Unknown Error when on most Distro's I've tested, it usually returns the original hostname

CoreOS Version

NAME="Container Linux by CoreOS"
ID=coreos
VERSION=1235.6.0
VERSION_ID=1235.6.0
BUILD_ID=2017-01-10-0545
PRETTY_NAME="Container Linux by CoreOS 1235.6.0 (Ladybug)"

Environment

Digital Ocean 1GB Droplet

Expected Behavior

hostname -s is expected to return the original hostname if no short version is found

Actual Behavior

hostname: Unknown host

Reproduction Steps

Type hostname -s

@Blackglade Blackglade referenced this issue in discourse/discourse_docker Jan 16, 2017

Closed

CoreOS Bug #327

@crawford

This comment has been minimized.

Show comment
Hide comment
@crawford

crawford Feb 24, 2017

Member

I'm unable to reproduce the issue on the latest Alpha.

core@apollo ~ $ hostname -s
apollo
core@apollo ~ $ cat /etc/os-release 
NAME="Container Linux by CoreOS"
ID=coreos
VERSION=1325.1.0
VERSION_ID=1325.1.0
BUILD_ID=2017-02-23-0035
PRETTY_NAME="Container Linux by CoreOS 1325.1.0 (Ladybug)"
ANSI_COLOR="38;5;75"
HOME_URL="https://coreos.com/"
BUG_REPORT_URL="https://github.com/coreos/bugs/issues"

Could you try again?

Member

crawford commented Feb 24, 2017

I'm unable to reproduce the issue on the latest Alpha.

core@apollo ~ $ hostname -s
apollo
core@apollo ~ $ cat /etc/os-release 
NAME="Container Linux by CoreOS"
ID=coreos
VERSION=1325.1.0
VERSION_ID=1325.1.0
BUILD_ID=2017-02-23-0035
PRETTY_NAME="Container Linux by CoreOS 1325.1.0 (Ladybug)"
ANSI_COLOR="38;5;75"
HOME_URL="https://coreos.com/"
BUG_REPORT_URL="https://github.com/coreos/bugs/issues"

Could you try again?

@Blackglade

This comment has been minimized.

Show comment
Hide comment
@Blackglade

Blackglade Mar 7, 2017

Tested this again on the latest Alpha (1339.0.0) as well and got the same issue!
test

This is a brand new container by the way, I just spun it up using Digital Ocean

Blackglade commented Mar 7, 2017

Tested this again on the latest Alpha (1339.0.0) as well and got the same issue!
test

This is a brand new container by the way, I just spun it up using Digital Ocean

@euank

This comment has been minimized.

Show comment
Hide comment
@euank

euank Mar 7, 2017

Member

hostname -s on Gentoo, and subsequently Container Linux, ends up using the "gethostname" syscall which also ends up doing network-stuff by default.

There are a number of ways this can be fixed.

nsswitch config

Update /etc/nsswitch.conf's "hosts" line to be the following: hosts: files usrfiles dns myhostname (change is including 'myhostname' at the end).
Note that it's a symlink to /usr/, so it'll have to be clobbered.

This will allow hostname and hostname -s (and actually hostname -i) to succeed without them resolving normally.

It's possible this should be the default on Container Linux and we just haven't bothered to make it so yet.

/etc/hosts

Appending "$public_ip4 $my_hostname" to /etc/hosts should work as well.

Alternately, if hostname -i can be wrong, adding the hostname as the first entry after 127.0.0.1 will also have hostname -s work (order does matter! if it's not first you'll get 'localhost' for it).

Actual valid dns

This one won't work on DO necessarily, but I solve this for myself by running a dns resolver for my VMs which contains a mapping of ip<->hostname and can resolve those locally.
I think on EC2 the default hostnames end up working via this method.


Hopefully one of those things helps.

@crawford adding myhostname to the default nsswitch config for hosts would probably be less confusing for most people; any reason we shouldn't?

Member

euank commented Mar 7, 2017

hostname -s on Gentoo, and subsequently Container Linux, ends up using the "gethostname" syscall which also ends up doing network-stuff by default.

There are a number of ways this can be fixed.

nsswitch config

Update /etc/nsswitch.conf's "hosts" line to be the following: hosts: files usrfiles dns myhostname (change is including 'myhostname' at the end).
Note that it's a symlink to /usr/, so it'll have to be clobbered.

This will allow hostname and hostname -s (and actually hostname -i) to succeed without them resolving normally.

It's possible this should be the default on Container Linux and we just haven't bothered to make it so yet.

/etc/hosts

Appending "$public_ip4 $my_hostname" to /etc/hosts should work as well.

Alternately, if hostname -i can be wrong, adding the hostname as the first entry after 127.0.0.1 will also have hostname -s work (order does matter! if it's not first you'll get 'localhost' for it).

Actual valid dns

This one won't work on DO necessarily, but I solve this for myself by running a dns resolver for my VMs which contains a mapping of ip<->hostname and can resolve those locally.
I think on EC2 the default hostnames end up working via this method.


Hopefully one of those things helps.

@crawford adding myhostname to the default nsswitch config for hosts would probably be less confusing for most people; any reason we shouldn't?

@crawford

This comment has been minimized.

Show comment
Hide comment
@crawford

crawford Mar 8, 2017

Member

Nope, let's go ahead and add it.

Member

crawford commented Mar 8, 2017

Nope, let's go ahead and add it.

euank added a commit to euank/baselayout that referenced this issue Mar 13, 2017

nsswitch: use nss-myhostname
This modules ensures that `hostname -s` and `hostname -i` will always
return something.

It's prioritized last so any existing hostname configuration (e.g. in
/etc/hosts) will still work correctly.

This configuration is similar to what most distributions do.

See coreos/bugs#1764

@euank euank referenced this issue in coreos/baselayout Mar 13, 2017

Merged

nsswitch: use nss-myhostname #63

euank added a commit to euank/coreos-overlay that referenced this issue Mar 14, 2017

sys-apps/baselayout: bump for nss-myhostname
The only change this pixes up is the addition of myhostname in
nsswitch.conf

See coreos/bugs#1764

@euank euank referenced this issue in coreos/coreos-overlay Mar 14, 2017

Merged

sys-apps/baselayout: bump for nss-myhostname #2480

@euank

This comment has been minimized.

Show comment
Hide comment
@euank

euank Mar 14, 2017

Member

The nsswitch.conf change I mentioned above should be set by default in the next Container Linux alpha release.

In the meanwhile, any of the options I mentioned should work on existing releases.

Member

euank commented Mar 14, 2017

The nsswitch.conf change I mentioned above should be set by default in the next Container Linux alpha release.

In the meanwhile, any of the options I mentioned should work on existing releases.

@euank euank closed this Mar 14, 2017

ChrisMcKenzie added a commit to ChrisMcKenzie/coreos-overlay that referenced this issue Dec 9, 2017

sys-apps/baselayout: bump for nss-myhostname
The only change this pixes up is the addition of myhostname in
nsswitch.conf

See coreos/bugs#1764
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment