Skip to content

Commit e9eff47

Browse files
committed
nixos/networking: don't add extra names to ::1
From hosts(5): > For each host a single line should be present with the following > information: > > IP_address canonical_hostname [aliases...] With lines like "::1 localhost ahost.adomin ahost", we were saying that the canonical name for "ahost" was "localhost", the opposite of a canonical name. This is why a second loopback address (127.0.0.2) is used for hostnames with IPv4 — if they were put after "localhost" on the 127.0.0.1 line, the same thing would happen. With IPv6 we can't do the same thing as there's only a single loopback address, so instead the right thing to do is to simply not list the hostnames in /etc/hosts, and rely on the myhostname NSS plugin, which will handle this correctly. (Note that the examples in hosts(5) also do not include IPv6 FQDN or hostname entries.)
1 parent 4c43880 commit e9eff47

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

nixos/modules/config/networking.nix

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ in
163163
++ lib.optional (cfg.hostName != "") cfg.hostName; # Then the hostname (without the domain)
164164
in {
165165
"127.0.0.2" = hostnames;
166-
} // lib.optionalAttrs cfg.enableIPv6 {
167-
"::1" = hostnames;
168166
};
169167

170168
networking.hostFiles = let

nixos/tests/hostname.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ let
6262
fqdn_and_host_name
6363
== machine.succeed("getent hosts 127.0.0.2 | awk '{print $2,$3}'").strip()
6464
)
65+
66+
assert "${fqdn}" == machine.succeed("getent hosts ${hostName} | awk '{print $2}'").strip()
6567
'';
6668
};
6769

0 commit comments

Comments
 (0)