Nixpkgs: hostname is broken

Created on 20 Nov 2013  ·  29Comments  ·  Source: NixOS/nixpkgs

I was trying to look into this more, but one of the most recent updates (builds since ac6bc8c990ac8298abd010ed262769bf09616185) broke my hostname lookup.

$ hostname
wl
$ hostname -a
hostname: Unknown host
$ hostname -s
hostname: Unknown host

bug trivial nixos module (update)

All 29 comments

Could you post the output with the -v flag?

Here all the commands you mentioned work.

[root@wdl:~/.cfg]# hostname -v
gethostname()=`wdl.d.apt.wkennington.com'
wdl.d.apt.wkennington.com

[root@wdl:~/.cfg]# hostname -v
gethostname()=`wdl.d.apt.wkennington.com'
wdl.d.apt.wkennington.com

And something with the latest repository and an error and verbosity?

nixpkgs: b6a720141ed178e80056328f0315711c73ba5fe3

[root@wdl:~/nixpkgs]# hostname -va
gethostname()=wdl.d.apt.wkennington.com' Resolvingwdl.d.apt.wkennington.com' ...
hostname: Unknown host

From what I could determine it looks like something to do with nss-myhostname is broken.

After a recent upgrade (possibly after switching to NixOS 15.09, not sure) I have this problem again.

$ hostname
crystal

$ time hostname -v -s
gethostname()=`crystal'
Resolving `crystal' ...
hostname: Host name lookup failure

real    0m25.035s
user    0m0.000s
sys 0m0.002s

I have this in configuration.nix

networking.hostName = "crystal";

I noticed it because emacs takes a long time to startup.
This occurs to me inside a virtualbox machine.

This is the content of /etc/hosts

$ cat /etc/hosts 
127.0.0.1 localhost
::1 localhost

You can work around this by adding networking.extraHosts = "127.0.0.1 crystal".

But this should be a trivial fix in https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/config/networking.nix#L136

Replacing 127.0.0.1 localhost with 127.0.0.1 localhost ${cfg.hostName} should do the trick.
Adding an equivalent to the IPv6 config would also make sense.

I did it:

$ cat /etc/hosts 
127.0.0.1 localhost
::1 localhost

127.0.0.1 crystal

But don't think it is the right solution.
This way hostname -s works but it is slow:

$ time hostname -s
crystal

real    0m15.019s
user    0m0.002s
sys 0m0.000s

Oh wow, mine resolves much faster:

~> time hostname -va
gethostname()=`nixie'
Resolving `nixie' ...
Result: h_name=`nixie'
Result: h_addr_list=`127.0.0.1'

hostname -va  0.00s user 0.00s system 0% cpu 0.211 total
~> time hostname -vs
gethostname()=`nixie'
Resolving `nixie' ...
Result: h_name=`nixie'
Result: h_addr_list=`127.0.0.1'
nixie
hostname -vs  0.00s user 0.00s system 0% cpu 0.221 total

Can you do those commands under strace, e.g.: strace hostname and
paste it here? Normally (without -a) hostname should just call
uname(2) and do no DNS lookups.

Also show your /etc/resolv.conf and /etc/nsswitch.conf.

And make sure nscd is running. Without it, probably nss_myhostname (which is responsible for making sure the hostname resolves to an IP address) won't be found.

But even without nscd, hostname should fall back onto /etc/hosts.

I am actually not running nscd, so I just tried strace hostname -s.
It finds my hostname through /etc/hosts without any issues, it particularly does not take 15+ seconds.
It does, however, try to DNS resolve before going to /etc/hosts, so a slow DNS resolution may be the issue here.

A simple strace hostname ends up looking at uname without ever accessing the outside world.

[...]
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("8.8.8.8")}, 16) = 0
poll([{fd=3, events=POLLOUT}], 1, 0)    = 1 ([{fd=3, revents=POLLOUT}])
sendto(3, "/p\1\0\0\1\0\0\0\0\0\0\5nixie\tgermadian\3com"..., 37, MSG_NOSIGNAL, NULL, 0) = 37
poll([{fd=3, events=POLLIN}], 1, 5000)  = 1 ([{fd=3, revents=POLLIN}])
ioctl(3, FIONREAD, [106])               = 0
recvfrom(3, "/p\201\203\0\1\0\0\0\1\0\0\5nixie\tgermadian\3com"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("8.8.8.8")}, [16]) = 106
close(3)
[...]
open("/run/opengl-driver/lib/libnss_myhostname.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/nix/store/npfsi1d9ka8zwnxzn3sr08hbwvpapyk7-glibc-2.21/lib/libnss_myhostname.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver/lib/libnss_mymachines.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/nix/store/npfsi1d9ka8zwnxzn3sr08hbwvpapyk7-glibc-2.21/lib/libnss_mymachines.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/etc/hosts", O_RDONLY|O_CLOEXEC)  = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=52, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f79242ec000
read(3, "127.0.0.1 localhost\n::1 localhos"..., 4096) = 52
close(3)                                = 0
munmap(0x7f79242ec000, 4096)            = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f79242ec000
write(1, "nixie\n", 6nixie
)                  = 6
exit_group(0)                           = ?
+++ exited with 0 +++

I don't think there is really anything wrong here.
I do find it curious that hostname -s seeks out my DNS server before going to /etc/hosts, I had expected it to be the other way around.

According to systemd nscd is OK:

$ systemctl status nscd
● nscd.service - Name Service Cache Daemon
   Loaded: loaded (/nix/store/45zzi8f1xvbnbxncnv4wvc9vxf6sn5vr-unit-nscd.service/nscd.service)
   Active: active (running) since Tue 2015-12-08 10:30:50 CET; 7h ago
  Process: 4316 ExecStartPost=/nix/store/10jz3ahw5x4rbkhin5wk3pbmkgy8i92w-unit-script/bin/nscd-post-start (code=exited, status=0/SUCCESS)
  Process: 4303 ExecStart=nscd -f /nix/store/cpkw5czpxpyp13kjp617yakmch3r99pw-nscd.conf (code=exited, status=0/SUCCESS)
  Process: 4292 ExecStartPre=/nix/store/zsdsanz1z1hjzzg96m6i26yr6m8qxqzk-unit-script/bin/nscd-pre-start (code=exited, status=0/SUCCESS)
 Main PID: 4306 (nscd)
   CGroup: /system.slice/nscd.service
           └─4306 nscd -f /nix/store/cpkw5czpxpyp13kjp617yakmch3r99pw-nscd.conf

The output of hostname -a is an empty string.
Here is its strace:

$ time strace hostname -a
execve("/run/current-system/sw/bin/hostname", ["hostname", "-a"], [/* 73 vars */]) = 0
brk(0)                                  = 0x9326000
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7783000
access("/etc/ld-nix.so.preload", R_OK)  = -1 ENOENT (No such file or directory)
open("/run/opengl-driver/lib/tls/i686/sse2/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/run/opengl-driver/lib/tls/i686/sse2", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver/lib/tls/i686/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/run/opengl-driver/lib/tls/i686", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver/lib/tls/sse2/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/run/opengl-driver/lib/tls/sse2", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver/lib/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/run/opengl-driver/lib/tls", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver/lib/i686/sse2/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/run/opengl-driver/lib/i686/sse2", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver/lib/i686/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/run/opengl-driver/lib/i686", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver/lib/sse2/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/run/opengl-driver/lib/sse2", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/run/opengl-driver/lib", {st_mode=S_IFDIR|0555, st_size=4096, ...}) = 0
open("/run/opengl-driver-32/lib/tls/i686/sse2/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/run/opengl-driver-32/lib/tls/i686/sse2", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver-32/lib/tls/i686/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/run/opengl-driver-32/lib/tls/i686", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver-32/lib/tls/sse2/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/run/opengl-driver-32/lib/tls/sse2", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver-32/lib/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/run/opengl-driver-32/lib/tls", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver-32/lib/i686/sse2/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/run/opengl-driver-32/lib/i686/sse2", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver-32/lib/i686/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/run/opengl-driver-32/lib/i686", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver-32/lib/sse2/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/run/opengl-driver-32/lib/sse2", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver-32/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/run/opengl-driver-32/lib", {st_mode=S_IFDIR|0555, st_size=4096, ...}) = 0
open("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/tls/i686/sse2/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/tls/i686/sse2", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/tls/i686/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/tls/i686", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/tls/sse2/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/tls/sse2", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/tls", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/i686/sse2/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/i686/sse2", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/i686/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/i686", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/sse2/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/sse2", 0xbfb36500) = -1 ENOENT (No such file or directory)
open("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0`\211\1\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0555, st_size=1912146, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7782000
mmap2(NULL, 1714748, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb75df000
mmap2(0xb777c000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19d000) = 0xb777c000
mmap2(0xb777f000, 10812, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb777f000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb75de000
set_thread_area({entry_number:-1, base_addr:0xb75de700, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0 (entry_number:6)
mprotect(0xb777c000, 8192, PROT_READ)   = 0
mprotect(0xb77a5000, 4096, PROT_READ)   = 0
uname({sysname="Linux", nodename="crystal", ...}) = 0
brk(0)                                  = 0x9326000
brk(0x9347000)                          = 0x9347000
getpid()                                = 4427
open("/etc/resolv.conf", O_RDONLY|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=81, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb75dd000
read(3, "# Generated by resolvconf\ndomain"..., 4096) = 81
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0xb75dd000, 4096)                = 0
socket(PF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
connect(3, {sa_family=AF_LOCAL, sun_path="/var/run/nscd/socket"}, 110) = 0
send(3, "\2\0\0\0\r\0\0\0\6\0\0\0hosts\0", 18, MSG_NOSIGNAL) = 18
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 5000) = 1 ([{fd=3, revents=POLLIN|POLLHUP}])
recvmsg(3, {msg_name(0)=NULL, msg_iov(2)=[{"hosts\0", 6}, {"\310O\3\0\0\0\0\0", 8}], msg_controllen=16, [{cmsg_len=16, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, [4]}], msg_flags=MSG_CMSG_CLOEXEC}, MSG_CMSG_CLOEXEC) = 14
mmap2(NULL, 217032, PROT_READ, MAP_SHARED, 4, 0) = 0xb75a9000
close(4)                                = 0
close(3)                                = 0
socket(PF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
connect(3, {sa_family=AF_LOCAL, sun_path="/var/run/nscd/socket"}, 110) = 0
send(3, "\2\0\0\0\5\0\0\0\10\0\0\0crystal\0", 20, MSG_NOSIGNAL) = 20
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 5000) = 0 (Timeout)
close(3)                                = 0
open("/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0444, st_size=172, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb75a8000
read(3, "passwd:    files \ngroup:     fil"..., 4096) = 172
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0xb75a8000, 4096)                = 0
open("/run/opengl-driver/lib/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver-32/lib/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\200\32\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0555, st_size=54298, ...}) = 0
mmap2(NULL, 50132, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb759c000
mmap2(0xb75a7000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xa000) = 0xb75a7000
close(3)                                = 0
mprotect(0xb75a7000, 4096, PROT_READ)   = 0
open("/etc/host.conf", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/etc/hosts", O_RDONLY|O_CLOEXEC)  = 3
fstat64(3, {st_mode=S_IFREG|0444, st_size=54, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb759b000
read(3, "127.0.0.1 localhost\n::1 localhos"..., 4096) = 54
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0xb759b000, 4096)                = 0
open("/run/opengl-driver/lib/libnss_dns.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver-32/lib/libnss_dns.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/libnss_dns.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\340\v\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0555, st_size=25279, ...}) = 0
mmap2(NULL, 24708, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7595000
mmap2(0xb759a000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x4000) = 0xb759a000
close(3)                                = 0
open("/run/opengl-driver/lib/libresolv.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver-32/lib/libresolv.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/libresolv.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0P&\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0555, st_size=90945, ...}) = 0
mmap2(NULL, 92136, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb757e000
mmap2(0xb7591000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x12000) = 0xb7591000
mmap2(0xb7593000, 6120, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb7593000
close(3)                                = 0
mprotect(0xb7591000, 4096, PROT_READ)   = 0
mprotect(0xb759a000, 4096, PROT_READ)   = 0
socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("192.168.1.1")}, 16) = 0
gettimeofday({1449595639, 203314}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0)    = 1 ([{fd=3, revents=POLLOUT}])
send(3, "`[\1\0\0\1\0\0\0\0\0\0\7crystal\7homenet\rtel"..., 50, MSG_NOSIGNAL) = 50
poll([{fd=3, events=POLLIN}], 1, 5000)  = 1 ([{fd=3, revents=POLLIN}])
ioctl(3, FIONREAD, [50])                = 0
recvfrom(3, "`[\205\203\0\1\0\0\0\0\0\0\7crystal\7homenet\rtel"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("192.168.1.1")}, [16]) = 50
close(3)                                = 0
socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("192.168.1.1")}, 16) = 0
gettimeofday({1449595639, 208018}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0)    = 1 ([{fd=3, revents=POLLOUT}])
send(3, "\304q\1\0\0\1\0\0\0\0\0\0\7crystal\0\0\34\0\1", 25, MSG_NOSIGNAL) = 25
poll([{fd=3, events=POLLIN}], 1, 5000)  = 0 (Timeout)
gettimeofday({1449595644, 212952}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0)    = 1 ([{fd=3, revents=POLLOUT}])
send(3, "\304q\1\0\0\1\0\0\0\0\0\0\7crystal\0\0\34\0\1", 25, MSG_NOSIGNAL) = 25
poll([{fd=3, events=POLLIN}], 1, 5000)  = 0 (Timeout)
close(3)                                = 0
open("/run/opengl-driver/lib/libnss_myhostname.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver-32/lib/libnss_myhostname.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/libnss_myhostname.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver/lib/libnss_mymachines.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/run/opengl-driver-32/lib/libnss_mymachines.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/nix/store/pb6papnlgg62wkim7qsg8c2jw4izffx8-glibc-2.21/lib/libnss_mymachines.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/etc/hosts", O_RDONLY|O_CLOEXEC)  = 3
fstat64(3, {st_mode=S_IFREG|0444, st_size=54, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb757d000
read(3, "127.0.0.1 localhost\n::1 localhos"..., 4096) = 54
close(3)                                = 0
munmap(0xb757d000, 4096)                = 0
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb757d000
write(1, "\n", 1
)                       = 1
exit_group(0)                           = ?
+++ exited with 0 +++

real    0m15.032s
user    0m0.003s
sys 0m0.005s

Perhaps I had to mention it before explicitly: the machine has no DNS registration (it is a virtual box guest).
(But neither had it before and emacs had no slowdowns at startup.)

hostname (without -a) works here too, both with and without

networking.extraHosts = "127.0.0.1 crystal";

added to configuration.nix:

$ time strace hostname
[... snip ...]
mprotect(0xb7753000, 8192, PROT_READ)   = 0
mprotect(0xb777c000, 4096, PROT_READ)   = 0
uname({sysname="Linux", nodename="crystal", ...}) = 0
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb75b4000
write(1, "crystal\n", 8crystal
)                = 8
exit_group(0)                           = ?
+++ exited with 0 +++

real    0m0.006s
user    0m0.001s
sys 0m0.002s

Still no resolv.conf and nsswitch.conf.

Also, looking at the traces, can you show the output of echo $LD_LIBRARY_PATH?

Ah, sorry!

$ echo $LD_LIBRARY_PATH
/run/opengl-driver/lib:/run/opengl-driver-32/lib
$ cat /etc/resolv.conf
# Generated by resolvconf
domain homenet.telecomitalia.it
nameserver 192.168.1.1
$ cat /etc/nsswitch.conf 
passwd:    files 
group:     files 
shadow:    files 
hosts:     files  dns   myhostname mymachines
networks:  files dns
ethers:    files
services:  files
protocols: files

All of these look normal to me, hostname does exactly the same thing
when run on my machine.

Except it timeouts on DNS requests ("Timeout" in polls in the trace).
With the information you've shown till now I would guess that the
problem is outside of NixOS.

If you think that the problem is with NixOS then:

  • Can you run _the_ problematic command under strace or describe what
    is the problem with the traces you've shown here?

(If the program forks under strace (hostname doesn't), you can do
strace -f, e.g. strace -f emacs to trace its children. I
absolutely wouldn't want to read that, unless it's a last resort.)

  • Is your primary problem a emacs problem? Are you sure that your
    emacs problem is hostname problem? Why?
  • Please document any changes you do to configuration.nix or paste
    contents of all the generated hosts, resolve.conf and
    nsswitch.conf files along with the traces. E.g. it's unclear
    whenever strace hostname -a is a trace with which /etc/hosts.
  • Don't "snip" pieces from the traces and other outputs of commands.
  • If possible, boot the system with the older generation from boot menu
    (the one that worked) and post the traces from there.

Meanwhile, with "not a NixOS problem" hypothesis in mind I would

1) try to run the problematic command with services.nscd.enable set to
both possible values in configuration.nix and compare the traces
(possibly in both generations, if you don't have the the previous
generation's config you can hack around this by disabling nscd and
then rming it's socket so that systemd wouldn't socket-activate it)
to be sure;

2) check ip addr, iptables -L -v, iptables -L -v -t nat and
iptables -L -v -t raw on both vm and host;

3) fire up tcpdump on vm and on host and then try the problematic
commands (in both generations);

4) try a different DNS server in vm;

5) try a different virtualized network driver (if possible);

6) try a different virtualization system.

@oxij: thank you for your suggestions and your time.

So, l'll try to recap the situation:

My principal problem is that emacs is slow at startup.
(An strace of emacs is at the bottom of this message.)

I believe that the problem is in NixOS because:

  • It has been a while since I did any update on the host system (a MacBook Pro running Yosemite);
  • The computer is connected to an ADSL wifi at home where everything is unchanged and seems OK;
  • I installed a debian guest, and I don't have the same problem on that.

I'll try to provide more information.

First of all, here is a recap of my configuration.

$ cat /etc/hosts 
127.0.0.1 localhost
::1 localhost

(I also tried adding 127.0.0.1 localhost crystal but it doesn't help.)

$ cat /etc/resolv.conf
# Generated by resolvconf
domain homenet.telecomitalia.it
nameserver 192.168.1.1
$ cat /etc/nsswitch.conf 
passwd:    files 
group:     files 
shadow:    files 
hosts:     files  dns   myhostname mymachines
networks:  files dns
ethers:    files
services:  files
protocols: files

Here is the configuration on the debian host that works:

$ cat /etc/hosts
127.0.0.1   localhost
127.0.1.1   nux

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
$ cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 192.168.1.1
$ cat /etc/nsswitch.conf 
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd:         compat
group:          compat
shadow:         compat

hosts:          files myhostname mdns4_minimal [NOTFOUND=return] dns mdns4
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

Here is the command I use to test emacs.
Recall:

  • -q is "do not load init files";
  • -f is "run lisp function";
  • save-buffers-kill-terminal is "exit emacs".
    (On the debian guest this takes a fraction of second.)
$ time emacs -q -f save-buffers-kill-terminal

(emacs:1546): GLib-GIO-CRITICAL **: g_settings_schema_source_lookup: assertion 'source != NULL' failed

real    0m15.354s
user    0m0.201s
sys 0m0.067s

Finally here you can get the strace of the emacs execution. The three "Timeout" near the end are those that slowdown the startup.
https://gist.github.com/maggesi/964844d5a50afe3c16e8

Does it change anything when you add 127.0.1.1 some-hostname to /etc/hosts?

  • Do you happen to use DHCP in the Debian guest, but not in the NixOS
    guest?
  • Is '192.168.1.1' your ADSL router?

    If the answer is "no" fill the other IP address, if "yes":

** Does ping 192.168.1.1 from your vm gets its pongs?

** Does dig @192.168.1.1 google.com from vm (install bind package)
return a correct filled "A" record?

** Does dig @192.168.1.1 crystal from vm return a correct "A" filled
record?

** Does dig @192.168.1.1 crystal.homenet.telecomitalia.it from vm
return a correct "A" filled record?

  • What's the output of ip addr in vm?
  • Does your router run Linux?

If the answer is "yes":

** What's the output of ip addr or ifconfig -a on the router?

** Does it run dnsmasq daemon?

** What's the config of that?

  • Does any or both of the following together fix your problem?

** Does removing the domain line from that file in the vm help?

$ cat /etc/resolv.conf
# Generated by resolvconf
domain homenet.telecomitalia.it
nameserver 192.168.1.1

(You can do

$ cd /etc
$ mv resolv.conf resolv.conf_
$ cp -L resolv.conf_ resolv.conf
$ vim resolv.conf

and then

$ rm resolv.conf
$ mv resolv.conf_ resolv.conf

to revert.)

** Does changing the hosts line in

$ cat /etc/nsswitch.conf 
passwd:    files 
group:     files 
shadow:    files 
hosts:     files  dns   myhostname mymachines
networks:  files dns
ethers:    files
services:  files
protocols: files

to

hosts:     files  myhostname mymachines dns

help?

(The same method applies.)

Just wanted to remark that I had the same symptom (slow Emacs startup), and before I even looked to see if anyone had reported a similar issue, I straced Emacs, saw references to my system's hostname, immediately checked /etc/hosts, and grumbled upon finding that it had no entry for it--just127.0.0.1 localhost and ::1 localhost. So I added networking.extraHosts to /etc/nixos/configuration.nix:

networking = rec {
  hostName = "myhostname";
  extraHosts = "127.0.0.1 ${hostName}";
};

...and it solved the problem, just as it has 99% of the time in the past thirty years I've come across a sluggishly-misbehaving Unix machine that was missing an entry for itself in /etc/hosts. :)

This really ought to be the default, with an option to disable it if desired.

tl;dr: if you want to avoid an outgoing AAAA DNS query for yourhostnamehere when hostname -f happens, then add a line in /etc/hosts like ::1 yourhostnamehere.

Hi. I didn't read this whole thread but, if an ipv6 entry for the host is missing(even though ipv6 is disabled in 2 ways - see below), then an outgoing DNS query is issued regardless.
eg.
\1. (term1) sudo tcpdump -vvvvv dst port 53
2. (term2) sudo systemctl restart nscd && hostname -va

(term2)

$ sudo systemctl restart nscd && hostname -va
gethostname()=`vbox1'
Resolving `vbox1' ...
Result: h_name=`vbox1'
Result: h_aliases=`localhost'
Result: h_addr_list=`::1'
localhost 

(term1)

tcpdump: listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes
18:33:22.602116 IP (tos 0x0, ttl 64, id 16578, offset 0, flags [DF], proto UDP (17), length 51)
    vbox1.44705 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c4f -> 0xc2db!] 29639+ AAAA? vbox1. (23)
18:33:22.605198 IP (tos 0x0, ttl 64, id 16579, offset 0, flags [DF], proto UDP (17), length 66)
    vbox1.50319 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c5e -> 0xc6c9!] 16056+ PTR? 8.8.8.8.in-addr.arpa. (38)
18:33:22.666087 IP (tos 0x0, ttl 64, id 16593, offset 0, flags [DF], proto UDP (17), length 68)
    vbox1.57417 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c60 -> 0xa1f5!] 33352+ PTR? 15.2.0.10.in-addr.arpa. (40)
^C

with /etc/hosts:

127.0.0.1 localhost

and with /proc/cmdline containing ipv6.disable=1 and configuration.nix having networking.enableIPv6 = false;. (as confirmed by https://github.com/NixOS/nixpkgs/blob/ae74c356d94b795eb07dfe9978788b49b70f5959/nixos/modules/config/networking.nix#L154-L161 )

\3. (term2) Can also replace hostname -va with hostname -f or hostname -vf to get the same outgoing dns query:

$ sudo systemctl restart nscd && hostname -vf
gethostname()=`vbox1'
Resolving `vbox1' ...
Result: h_name=`vbox1'
Result: h_aliases=`localhost'
Result: h_addr_list=`::1'
vbox1

It gets the right hostname vbox1 but at the price of an outgoing dns query:

tcpdump: listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes
18:39:00.837940 IP (tos 0x0, ttl 64, id 61535, offset 0, flags [DF], proto UDP (17), length 51)
    vbox1.59371 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c4f -> 0x20f2!] 56422+ AAAA? vbox1. (23)
18:39:00.841228 IP (tos 0x0, ttl 64, id 61536, offset 0, flags [DF], proto UDP (17), length 66)
    vbox1.52334 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c5e -> 0x8887!] 29979+ PTR? 8.8.8.8.in-addr.arpa. (38)
18:39:00.881220 IP (tos 0x0, ttl 64, id 61564, offset 0, flags [DF], proto UDP (17), length 68)
    vbox1.52236 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c60 -> 0x490d!] 61293+ PTR? 15.2.0.10.in-addr.arpa. (40)
^C

Unplugging cable (even though we're in virtualbox), will still make this work, just rerun step 1 and 3 above.

$ sudo systemctl restart nscd && hostname -vf
gethostname()=`vbox1'
Resolving `vbox1' ...
Result: h_name=`vbox1'
Result: h_aliases=`localhost'
Result: h_addr_list=`::1'
vbox1

EDIT2: grrr I had to edit some wrong pastes! (I kept forgetting to right click and copy, else it would paste the previously copied text!)

tcpdump: listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes
18:39:00.837940 IP (tos 0x0, ttl 64, id 61535, offset 0, flags [DF], proto UDP (17), length 51)
    vbox1.59371 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c4f -> 0x20f2!] 56422+ AAAA? vbox1. (23)
18:39:00.841228 IP (tos 0x0, ttl 64, id 61536, offset 0, flags [DF], proto UDP (17), length 66)
    vbox1.52334 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c5e -> 0x8887!] 29979+ PTR? 8.8.8.8.in-addr.arpa. (38)
18:39:00.881220 IP (tos 0x0, ttl 64, id 61564, offset 0, flags [DF], proto UDP (17), length 68)
    vbox1.52236 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c60 -> 0x490d!] 61293+ PTR? 15.2.0.10.in-addr.arpa. (40)
^C

$ sudo systemctl restart nscd && hostname -vf
gethostname()=`vbox1'
Resolving `vbox1' ...
Result: h_name=`vbox1'
Result: h_aliases=`localhost'
Result: h_addr_list=`::1'
vbox1
$ sudo tcpdump -vvvvv dst port 53
tcpdump: listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
19:00:20.099387 IP (tos 0x0, ttl 64, id 31538, offset 0, flags [DF], proto UDP (17), length 51)
    localhost.51123 > localhost.domain: [bad udp cksum 0xfe32 -> 0x7e0f!] 48541+ AAAA? vbox1. (23)
19:00:20.100000 IP (tos 0x0, ttl 64, id 31540, offset 0, flags [DF], proto UDP (17), length 51)
    localhost.39472 > localhost.domain: [bad udp cksum 0xfe32 -> 0xab92!] 48541+ AAAA? vbox1. (23)
^C

The permanent fix to avoid the outgoing AAAA dns query for your hostname, is to add this line in /etc/hosts:

::1 vbox1

so now I have:

127.0.0.1 localhost

::1 localhost
::1 vbox1

Now remember, I still have ipv6 disabled in those 2 places though! But no outgoing AAAA query this time! (note, had to rerun step 1 and 3)

$ sudo systemctl restart nscd && hostname -vf
gethostname()=`vbox1'
Resolving `vbox1' ...
Result: h_name=`vbox1'
Result: h_addr_list=`::1'
vbox1
$ sudo tcpdump -vvvvv dst port 53
tcpdump: listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes
^C

Btw, now hostname -va resolved to nothing:

$ sudo systemctl restart nscd && hostname -va
gethostname()=`vbox1'
Resolving `vbox1' ...
Result: h_name=`vbox1'
Result: h_addr_list=`::1'

Hmm, I guess I should add an alias maybe... ::1 vbox1 vbox1 let's say.
or just replace ::1 localhost with ::1 vbox1 localhost ...

So, why was this bad? at some point in Gentoo or/and Manjaro, running startx and mc for the first time, while network cable was unplugged, would hang and I found out it's because they both were running hostname -f, however in nixos they don't seem to do that! (but I only tested mc aka midnight commander)

EDIT: tested on nixos-unstable channel
<<< Welcome to NixOS 16.09.git.32b7b00M (\m) - \l >>>

@NotaseCretagen, what happens when you add

127.0.0.1 vbox1

to the hosts file? Will that prevent the AAAA lookup?

Ah, very good point @peti ! I don't know how I missed talking about that.
The answer is no, however. The lookup still happens, if I comment out the two ::1 lines (but kept the ::1 localhost line which comes with a msvp hosts file which I downloaded because I currently couldn't edit it out due to file being symlinked)

Tested on this file
with both 127.0.0.1 vbox1 vbox1 and 127.0.0.1 vbox1 variants separately.

$ sudo systemctl restart nscd && hostname -vf
gethostname()=`vbox1'
Resolving `vbox1' ...
Result: h_name=`vbox1'
Result: h_aliases=`localhost'
Result: h_addr_list=`::1'
vbox1
$ sudo tcpdump -vvvvv dst port 53
tcpdump: listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes
12:50:54.945108 IP (tos 0x0, ttl 64, id 25560, offset 0, flags [DF], proto UDP (17), length 51)
    vbox1.33660 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c4f -> 0xd443!] 36228+ AAAA? vbox1. (23)
12:50:54.956309 IP (tos 0x0, ttl 64, id 25561, offset 0, flags [DF], proto UDP (17), length 66)
    vbox1.44428 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c5e -> 0x1768!] 1309+ PTR? 8.8.8.8.in-addr.arpa. (38)
12:50:55.038533 IP (tos 0x0, ttl 64, id 25629, offset 0, flags [DF], proto UDP (17), length 68)
    vbox1.58517 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c60 -> 0x56e8!] 51465+ PTR? 15.2.0.10.in-addr.arpa. (40)

To fix(no outgoing query) just uncomment the second line(although I uncomment both) here: https://gist.github.com/NotaseCretagen/4f0b76cce6c098877029035818eddcd9#file-hosts-L15-L16

It's worth noting that, if nscd isn't running, then having only these in /etc/hosts:

127.0.0.1 localhost.localdomain localhost

127.0.0.1 localhost

Will cause both an A? and an AAAA? outgoing queries.

But I figured, the A? wasn't happening due to nscd taking care of that part! (while it is running)

$ sudo systemctl stop nscd ; hostname -vf
gethostname()=`vbox1'
Resolving `vbox1' ...
hostname: Unknown host

$ sudo tcpdump -vvvvv dst port 53
tcpdump: listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes
14:22:55.460294 IP (tos 0x0, ttl 64, id 4641, offset 0, flags [DF], proto UDP (17), length 51)
    10.0.2.15.36167 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c4f -> 0x31d1!] 9772+ AAAA? vbox1. (23)
14:22:55.474560 IP (tos 0x0, ttl 64, id 4645, offset 0, flags [DF], proto UDP (17), length 66)
    10.0.2.15.49736 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c5e -> 0x5adb!] 44269+ PTR? 8.8.8.8.in-addr.arpa. (38)
14:22:55.582051 IP (tos 0x0, ttl 64, id 4707, offset 0, flags [DF], proto UDP (17), length 51)
    10.0.2.15.45998 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c4f -> 0x1bb9!] 12509+ A? vbox1. (23)
14:22:55.585952 IP (tos 0x0, ttl 64, id 4711, offset 0, flags [DF], proto UDP (17), length 68)
    10.0.2.15.38821 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c60 -> 0x0c18!] 24778+ PTR? 15.2.0.10.in-addr.arpa. (40)
^C

Now, start that baby up and what do you know?!

$ sudo systemctl start nscd ; hostname -vf
gethostname()=`vbox1'
Resolving `vbox1' ...
Result: h_name=`vbox1'
Result: h_aliases=`localhost'
Result: h_addr_list=`::1'
vbox1
$ sudo tcpdump -vvvvv dst port 53
tcpdump: listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes
14:25:31.133349 IP (tos 0x0, ttl 64, id 7233, offset 0, flags [DF], proto UDP (17), length 51)
    vbox1.46876 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c4f -> 0x70b5!] 48498+ AAAA? vbox1. (23)
14:25:31.145152 IP (tos 0x0, ttl 64, id 7267, offset 0, flags [DF], proto UDP (17), length 66)
    vbox1.52337 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c5e -> 0xd184!] 11291+ PTR? 8.8.8.8.in-addr.arpa. (38)
14:25:31.222660 IP (tos 0x0, ttl 64, id 7323, offset 0, flags [DF], proto UDP (17), length 68)
    vbox1.34852 > google-public-dns-a.google.com.domain: [bad udp cksum 0x1c60 -> 0x9e73!] 56815+ PTR? 15.2.0.10.in-addr.arpa. (40)
^C

Now, I guess since the A? is taken care of by nscd, then maybe it should(?) also take care of the AAAA? ? or we should not forget to add ::1 vbox1 to /etc/hosts in this case.

Cheers!

EDIT: Note that the PTR queries are made by tcpdump, to avoid those just add the -n arg. ie.

sudo tcpdump -vvvvv -n dst port 53
tcpdump: listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes
15:29:57.036394 IP (tos 0x0, ttl 64, id 5799, offset 0, flags [DF], proto UDP (17), length 51)
    10.0.2.15.38425 > 8.8.8.8.53: [bad udp cksum 0x1c4f -> 0x4358!] 3027+ AAAA? vbox1. (23)
15:29:57.139646 IP (tos 0x0, ttl 64, id 5851, offset 0, flags [DF], proto UDP (17), length 51)
    10.0.2.15.48607 > 8.8.8.8.53: [bad udp cksum 0x1c4f -> 0x61bb!] 57513+ A? vbox1. (23)

EDIT2: this is what I'm using as a workaround, although, I'm not sure if something similar should be in here instead.

Debian GNU/Linux 7

root@virt:~# cat /etc/hosts
127.0.0.1 localhost.localdomain localhost
10.0.0.4 virt.lan virt pvelocalhost

# The following lines are desirable for IPv6 capable hosts

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

pro/contra of resolving the own hostname to the first network interfaces ip instead of 127.0.0.1?

how would one get the first interfaces ip on systemd systems?

the workaround also fixes hostname -f for me: https://github.com/davidak/nixos-config/blob/d1fcef16470c567245fcb480c55f980b59bfc208/binary/configuration.nix#L32-L35

but host localhost puts the hostname before the domain:
localhost.lan.davidak.de does not exist, try again

on the debian maschine: localhost has address 127.0.0.1

it's still the case with debian style hosts: https://github.com/davidak/nixos-config/blob/2e3800c6d63211b9f8b25cb16f64ce999bba0507/binary/configuration.nix#L32-L43

@peti Let me add my 2 cents.

Let's get back to 127.0.1.1 <my-hostname>. Some mentioned Debian does it, it seems nobody mentioned why. Apparently, some apps expect that mapping canonical hostnames to an IP, and mapping that IP to an hostname, returns the same hostname. [Some argue those apps are broken, yet Debian still does it.] More apps expect that 127.0.0.1 and localhost map to each other. To have both conditions, you can't map the hostname to 127.0.0.1—but 127.0.1.1 avoids the problem. And it's still a loopback IP!

pro/contra of resolving the own hostname to the first network interfaces ip instead of 127.0.0.1?

Is that IP constant? If yes, you're good. IIUC that was the standard configuration, back when Unix systems all just had static public IPs.

Quoting from the Debian Reference on this:

The Debian Installer creates this entry [the 127.0.1.1 one] for a system without a permanent IP address as a workaround for some software (e.g., GNOME) as documented in the bug #719621.

See also https://lists.debian.org/debian-boot/2005/06/msg00938.html, where this was decided.

EDIT: here's another reference for this behavior: https://serverfault.com/a/490530/29689.

myhostname was broken at some point (nss module was not in library path of nscd), but it works again and returns an ip for the hostname:

╭─[/etc/nixos/nixpkgs]─[joerg@turingmachine]
╰─[:)] % hostname -f
turingmachine
$ getent ahostsv4 turingmachine     
169.254.164.33  STREAM turingmachine
169.254.164.33  DGRAM
169.254.164.33  RAW
172.22.213.17   STREAM
172.22.213.17   DGRAM
172.22.213.17   RAW
172.23.75.82    STREAM
172.23.75.82    DGRAM
172.23.75.82    RAW
10.0.0.1        STREAM
10.0.0.1        DGRAM
10.0.0.1        RAW
172.17.0.1      STREAM
172.17.0.1      DGRAM
172.17.0.1      RAW
$ getent ahostsv6 turingmachine                                                                                                             
fd42:4992:6a6d:600::1 STREAM turingmachine
fd42:4992:6a6d:600::1 DGRAM
fd42:4992:6a6d:600::1 RAW
fe80::6af7:28ff:feb2:8706 STREAM
fe80::6af7:28ff:feb2:8706 DGRAM
fe80::6af7:28ff:feb2:8706 RAW
fe80::3602:86ff:fe1a:7b47 STREAM
fe80::3602:86ff:fe1a:7b47 DGRAM
fe80::3602:86ff:fe1a:7b47 RAW
fe80::82        STREAM
fe80::82        DGRAM
fe80::82        RAW
fe80::82        STREAM
fe80::82        DGRAM
fe80::82        RAW
fe80::82        STREAM
fe80::82        DGRAM
fe80::82        RAW
fe80::82        STREAM
fe80::82        DGRAM
fe80::82        RAW
fe80::d40f:78ff:fe61:a006 STREAM
fe80::d40f:78ff:fe61:a006 DGRAM
fe80::d40f:78ff:fe61:a006 RAW
Was this page helpful?
0 / 5 - 0 ratings

Related issues

teto picture teto  ·  3Comments

ghost picture ghost  ·  3Comments

langston-barrett picture langston-barrett  ·  3Comments

grahamc picture grahamc  ·  3Comments

ob7 picture ob7  ·  3Comments