Nixpkgs: incorrect hostname --fqdn

Created on 2 Oct 2015  路  25Comments  路  Source: NixOS/nixpkgs

I'm not sure whether it's a bug of nixos, but i noticed unusual situation about my configuration.

This is invalid ( i think ) behavior

{
  networking = { 
    hostName = "hostname";
    domain = "domain.tld";
  };
}
# hostname --short
hostname
# hostname --domain
(none)

After small change results are correct

{
  networking = { 
    hostName = "hostname";
    domain = "domain.tld";
    search = [ "domain.tld" ];
  };
}
# hostname --short
hostname
# hostname --domain
domain.tld

Nothing huge, but if one needs hostname correct --fqdn solution is not totally obvious.

bug trivial nixos module (update)

Most helpful comment

still the case for NixOS 15.09.1012.9fe0c23, the workaround don't work.

because of this i have problems with postfix.

All 25 comments

still the case for NixOS 15.09.1012.9fe0c23, the workaround don't work.

because of this i have problems with postfix.

This is a well-known problem caused by the fact that NixOS won't record the host name as an alias for "127.0.0.1" in /etc/hosts.

This is a well-known problem caused by the fact that NixOS won't record the host name as an alias for "127.0.0.1" in /etc/hosts.

Is this simply an oversight that could be corrected with a quick PR, or was this done by design?

I volunteered to make a fix and then I never did it. :disappointed: The whole story is at https://github.com/NixOS/nixpkgs/issues/1248.

[chronos@yegatool:~]$ hostname --fqdn
yegatool

@Mic92 This seems to be resolved, and seems to be a duplicate of #1248. Since you've closed the latter, could you also close this one?

I can reproduce that this now works on master (but is still broken on 17.09)

> hostname --fqdn
host.domain.tld
> hostname
host
> hostname --short
host
>  hostname --domain
host.domain.tld

@yegortimoshenko, according to the very example you cited, this issue is not resolved because hostname --fqdn still doesn't work even though a domain name is configured.

@peti Oh, I don't have a domain set:

[chronos@yegatool:~]$ hostname --domain

@florianjacob tested it with a domain and it seems to be fixed. I assume this is fallout from #1248.

Which commit is supposed to fix this? With domain set, the issue persists for me.

Same problem as @srhb ... any fixes?

I can confirm that this is currently broken again in stable 18.03.

It's broken also on unstable

I just setup a new server and I gave this some time. In my installation adding networking.search or adding the hostname to networking.hosts doesn't help until I stopped nscd, after that hostname --fqdn and dnsdomainname gave the right results. Looking at the contents of nssswitch i see entries for the systemd-supplied mymachines and myhostname and I'm wondering if those are the culprit

I would rather say nscd because it caches result. myhostname loads its information from the operating system and is stateless itself: https://github.com/systemd/systemd/blob/master/src/nss-myhostname/nss-myhostname.c#L88 mymachines only returns results for containers/vms registered via machined.

I had this problem consistently, but removing myhostname from nsswitch.conf fixed it for me.

I also needed

{ config, ... }:

{
  networking.hosts = with config.networking;
    { "127.0.1.1" = [ "${hostname}.${domain}" ]; };
}

An easier change than modifying nsswitch.conf appears to be to use systemd-resolved. The networking.hosts stuff from before is still required, though.

@alyssais Is your setup public on github?

I tried to remove myhostname using the NixOS option system.nssHosts, but it is an additive operation only. Or did you just replace the read-only nsswitch.conf with the right options?

I was looking at the systemd-resolved options as well, but couldn't get it to work. Even a pointer to a post would help.

On Mon, Apr 29, 2019 at 03:34:53PM -0700, Attila Gulyas wrote:

@alyssais Is your setup public on github?

Not on GitHub, but it is public.

Here's the relevant commit:

https://edef.eu/~qyliss/nixlib/commit/7ac2a71fc41ebc3ebe565b5f773c151b1994fec2.html

Thank you @alyssais ! Tried all possible combination, even reinstalled the whole system and started from a clean config, but in the end it was @davidak's extraHosts workaround that worked for me from his comment to #1248. Others have mentioned this as well, but his config has a line for ::1 and that seems to be crucial, no clue why.

The suggested workarounds didn't fully work out for me. In order to get ssh with kerberos authentication with GSSAPIAuthentication and a krb5.keytab working, the order in the hosts file seems to be important: the fqdn needs to be first, neither hostname nor localhost. Otherwise I'll get an sshd error No key table entry found matching host/localhost@. I finally ended up with

{ config, pkgs, lib, ... }:
{
    networking.hosts =
    {
      "127.0.1.1" = lib.mkForce [ "${hostName}.${domain}" "${hostName}"];
      "::1" = lib.mkForce ["${hostName}.${domain}" "${hostName}" "localhost"];
    };
}

@Mic92 After your writings about nss-myhostname, I assume hostname --fqdn / ssh with kerberos both just do use nss?

In that case, what do they exactly do, and why does this fail with myhostname in nsswitch.conf?

I'd presonally prefer fixing NSS over adding things to text files, even if these are generated by nix.

@primeos just pointed me here via #87633. This is issue really causes subtle issues. I only noticed this was the problem when my email client failed to send an email, because it failed to send a FQDN...

I've written a small integration test, if someone feels like experimenting:

https://github.com/blitz/nixpkgs/commit/efd537c925c468b8e676419a54855d01ee56aebb

Oh, I completely forgot to close this issue. With #76542 this should finally be resolved :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

grahamc picture grahamc  路  3Comments

domenkozar picture domenkozar  路  3Comments

copumpkin picture copumpkin  路  3Comments

ayyess picture ayyess  路  3Comments