Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hostname Invalid Output #1764

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

Hostname Invalid Output #1764

Blackglade opened this issue Jan 16, 2017 · 5 comments

Comments

@Blackglade
Copy link

@Blackglade Blackglade commented Jan 16, 2017

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

@crawford
Copy link
Member

@crawford 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
Copy link
Author

@Blackglade 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
Copy link
Contributor

@euank 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
Copy link
Member

@crawford 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
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 added a commit to euank/coreos-overlay that referenced this issue Mar 14, 2017
The only change this pixes up is the addition of myhostname in
nsswitch.conf

See coreos/bugs#1764
@euank
Copy link
Contributor

@euank 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
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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.