Ping 解析主机名,但需要 10 秒钟才能开始发送数据包

Ping 解析主机名,但需要 10 秒钟才能开始发送数据包

我有两台 Linux 机器连接到路由器,因此它们位于同一子网中。机器 A 尝试通过其本地 IP ping 机器 B,一切正常。但是当 A 尝试通过启用 DDNS 的域 ping B 时,ping 需要将近 10 秒钟才能开始打印任何内容(与 相同,gping但需要 5 秒钟)。我很确定 ping 已正确解析主机名:

[user@a]$ ping -4 foobar.ddns.net # next line is printed with no delay:
PING foobar.ddns.net (192.168.0.231) 56(84) bytes of data.

从上面这一行可以看出,它立即得到解决,但接下来将近 10 秒钟没有打印任何内容。10 秒后,我看到:

[user@a]$ ping -4 foobar.ddns.net
PING foobar.ddns.net (192.168.0.231) 56(84) bytes of data.
64 bytes from 192.168.0.231: icmp_seq=1 ttl=64 time=5.01 ms
64 bytes from 192.168.0.231: icmp_seq=2 ttl=64 time=4.10 ms
# ... 8 more lines
^C
--- foobar.ddns.net ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 15665ms
rtt min/avg/max/mdev = 3.745/4.457/6.017/0.629 ms

再次从上面可以看到,没有数据包丢失,只是最初有 10 秒延迟。直接指定 IP 也是一样:

[user@a]$ ping 192.168.0.231
PING 192.168.0.231 (192.168.0.231) 56(84) bytes of data.
64 bytes from 192.168.0.231: icmp_seq=1 ttl=64 time=12.2 ms
64 bytes from 192.168.0.231: icmp_seq=2 ttl=64 time=4.20 ms
^C
--- 192.168.0.231 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 4.204/8.200/12.196/3.996 ms

没有初始延迟。此外,ssh 可以通过 IP 或主机名从 A 连接到 B,没有延迟。最后一个有趣的点:当我处于 ping 的初始延迟中时,如果我点击ctrl-c,它会打印出它已收到一个数据包:

[user@a]$ ping -4 foobar.ddns.net # I will wait 2 seconds and will hit ctrl-c:
PING foobar.ddns.net (192.168.0.231) 56(84) bytes of data.
^C
64 bytes from 192.168.0.231: icmp_seq=1 ttl=64 time=26.4 ms

--- foobar.ddns.net ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 26.431/26.431/26.431/0.000 ms 

两台机器的时钟通过 NTP 正确调整(据我所知,它们的时间差小于 1 秒)。

初始延迟的原因可能是什么? ping 将主机名解析为 IP 后会等待,这很奇怪。

更新:netcat 具有相同的初始延迟。

更新:使用 strace 进行 ping:

execve("/usr/bin/ping", ["ping", "-c", "1", "foobar.ddns.net"], 0x7ffc14d170b8 /* 75 vars */) = 0
brk(NULL)                               = 0x55fde8f30000
arch_prctl(0x3001 /* ARCH_??? */, 0x7fff11df4c30) = -1 EINVAL (Invalid argument)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=184639, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 184639, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fb4dcd54000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/libcap.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0ps\0\0\0\0\0\0"..., 832) = 832
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=42992, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb4dcd52000
mmap(NULL, 45128, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fb4dcd46000
mmap(0x7fb4dcd49000, 20480, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7fb4dcd49000
mmap(0x7fb4dcd4e000, 8192, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x8000) = 0x7fb4dcd4e000
mmap(0x7fb4dcd50000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x9000) = 0x7fb4dcd50000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/libidn2.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=132872, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 135184, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fb4dcd24000
mmap(0x7fb4dcd26000, 16384, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7fb4dcd26000
mmap(0x7fb4dcd2a000, 106496, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7fb4dcd2a000
mmap(0x7fb4dcd44000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1f000) = 0x7fb4dcd44000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220~\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=1948832, ...}, AT_EMPTY_PATH) = 0
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
mmap(NULL, 1973104, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fb4dcb42000
mmap(0x7fb4dcb68000, 1417216, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x26000) = 0x7fb4dcb68000
mmap(0x7fb4dccc2000, 344064, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x180000) = 0x7fb4dccc2000
mmap(0x7fb4dcd16000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1d3000) = 0x7fb4dcd16000
mmap(0x7fb4dcd1c000, 31600, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fb4dcd1c000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/libunistring.so.5", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=1804144, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 1808616, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fb4dc988000
mmap(0x7fb4dc99a000, 266240, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x12000) = 0x7fb4dc99a000
mmap(0x7fb4dc9db000, 1449984, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x53000) = 0x7fb4dc9db000
mmap(0x7fb4dcb3d000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b4000) = 0x7fb4dcb3d000
close(3)                                = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb4dc986000
arch_prctl(ARCH_SET_FS, 0x7fb4dc986b80) = 0
set_tid_address(0x7fb4dc986e50)         = 5312
set_robust_list(0x7fb4dc986e60, 24)     = 0
rseq(0x7fb4dc9874a0, 0x20, 0, 0x53053053) = 0
mprotect(0x7fb4dcd16000, 16384, PROT_READ) = 0
mprotect(0x7fb4dcb3d000, 16384, PROT_READ) = 0
mprotect(0x7fb4dcd44000, 4096, PROT_READ) = 0
mprotect(0x7fb4dcd50000, 4096, PROT_READ) = 0
mprotect(0x55fde81e8000, 4096, PROT_READ) = 0
mprotect(0x7fb4dcdb3000, 8192, PROT_READ) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
munmap(0x7fb4dcd54000, 184639)          = 0
prctl(PR_CAPBSET_READ, CAP_MAC_OVERRIDE) = 1
prctl(PR_CAPBSET_READ, 0x30 /* CAP_??? */) = -1 EINVAL (Invalid argument)
prctl(PR_CAPBSET_READ, CAP_CHECKPOINT_RESTORE) = 1
prctl(PR_CAPBSET_READ, 0x2c /* CAP_??? */) = -1 EINVAL (Invalid argument)
prctl(PR_CAPBSET_READ, 0x2a /* CAP_??? */) = -1 EINVAL (Invalid argument)
prctl(PR_CAPBSET_READ, 0x29 /* CAP_??? */) = -1 EINVAL (Invalid argument)
getrandom("\x97\xeb\x6d\x17\x5a\x77\xc7\x2e", 8, GRND_NONBLOCK) = 8
brk(NULL)                               = 0x55fde8f30000
brk(0x55fde8f51000)                     = 0x55fde8f51000
capget({version=_LINUX_CAPABILITY_VERSION_3, pid=0}, NULL) = 0
capget({version=_LINUX_CAPABILITY_VERSION_3, pid=0}, {effective=0, permitted=0, inheritable=1<<CAP_WAKE_ALARM}) = 0
capget({version=_LINUX_CAPABILITY_VERSION_3, pid=0}, NULL) = 0
capset({version=_LINUX_CAPABILITY_VERSION_3, pid=0}, {effective=0, permitted=0, inheritable=0}) = 0
prctl(PR_SET_KEEPCAPS, 1)               = 0
getuid()                                = 1000
setuid(1000)                            = 0
prctl(PR_SET_KEEPCAPS, 0)               = 0
getuid()                                = 1000
openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=3052896, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 3052896, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fb4dc600000
close(3)                                = 0
openat(AT_FDCWD, "/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=2998, ...}, AT_EMPTY_PATH) = 0
read(3, "# Locale name alias data base.\n#"..., 4096) = 2998
read(3, "", 4096)                       = 0
close(3)                                = 0
openat(AT_FDCWD, "/usr/share/locale/en_US.utf8/LC_MESSAGES/iputils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en_US/LC_MESSAGES/iputils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en.utf8/LC_MESSAGES/iputils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en/LC_MESSAGES/iputils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
capget({version=_LINUX_CAPABILITY_VERSION_3, pid=0}, NULL) = 0
capget({version=_LINUX_CAPABILITY_VERSION_3, pid=0}, {effective=0, permitted=0, inheritable=0}) = 0
socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP) = 3
socket(AF_INET6, SOCK_DGRAM, IPPROTO_ICMPV6) = 4
capget({version=_LINUX_CAPABILITY_VERSION_3, pid=0}, NULL) = 0
capget({version=_LINUX_CAPABILITY_VERSION_3, pid=0}, {effective=0, permitted=0, inheritable=0}) = 0
openat(AT_FDCWD, "/usr/lib/gconv/gconv-modules.cache", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib/gconv/gconv-modules", O_RDONLY|O_CLOEXEC) = 5
newfstatat(5, "", {st_mode=S_IFREG|0644, st_size=3916, ...}, AT_EMPTY_PATH) = 0
read(5, "# GNU libc iconv configuration.\n"..., 4096) = 3916
read(5, "", 4096)                       = 0
close(5)                                = 0
openat(AT_FDCWD, "/usr/lib/gconv/gconv-modules.d", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 5
newfstatat(5, "", {st_mode=S_IFDIR|0755, st_size=4096, ...}, AT_EMPTY_PATH) = 0
getdents64(5, 0x55fde8f36120 /* 3 entries */, 32768) = 96
openat(AT_FDCWD, "/usr/lib/gconv/gconv-modules.d/gconv-modules-extra.conf", O_RDONLY|O_CLOEXEC) = 6
newfstatat(6, "", {st_mode=S_IFREG|0644, st_size=53974, ...}, AT_EMPTY_PATH) = 0
read(6, "# GNU libc iconv configuration.\n"..., 4096) = 4096
read(6, "B1002//\tJUS_I.B1.002//\nmodule\tJU"..., 4096) = 4096
read(6, "59-5//\nalias\tISO_8859-5//\t\tISO-8"..., 4096) = 4096
read(6, "59-16//\t\tINTERNAL\t\tISO8859-16\t1\n"..., 4096) = 4096
read(6, "-SE-A\t1\nmodule\tINTERNAL\t\tEBCDIC-"..., 4096) = 4096
read(6, "97\t\t1\n\n#\tfrom\t\t\tto\t\t\tmodule\t\tcos"..., 4096) = 4096
read(6, "1\n\n#\tfrom\t\t\tto\t\t\tmodule\t\tcost\nal"..., 4096) = 4096
read(6, "6//\t\tIBM1046//\nalias\tCP1046//\t\tI"..., 4096) = 4096
brk(0x55fde8f72000)                     = 0x55fde8f72000
read(6, "\tto\t\t\tmodule\t\tcost\nalias\tRUSCII/"..., 4096) = 4096
read(6, "03//\nmodule\tCSN_369103//\t\tINTERN"..., 4096) = 4096
read(6, "\tmodule\t\tcost\nalias\tISO-IR-8-1//"..., 4096) = 4096
read(6, "IBM1156\t\t1\n\n#\tfrom\t\t\tto\t\t\tmodule"..., 4096) = 4096
read(6, "\t\tIBM1166//\nalias\tCP1166//\t\tIBM1"..., 4096) = 4096
read(6, "alias\tROMAN9//\t\tHP-ROMAN9//\nalia"..., 4096) = 726
read(6, "", 4096)                       = 0
close(6)                                = 0
getdents64(5, 0x55fde8f36120 /* 0 entries */, 32768) = 0
close(5)                                = 0
futex(0x7fb4dcd1b72c, FUTEX_WAKE_PRIVATE, 2147483647) = 0
newfstatat(AT_FDCWD, "/etc/nsswitch.conf", {st_mode=S_IFREG|0644, st_size=390, ...}, 0) = 0
newfstatat(AT_FDCWD, "/", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
openat(AT_FDCWD, "/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 5
newfstatat(5, "", {st_mode=S_IFREG|0644, st_size=390, ...}, AT_EMPTY_PATH) = 0
read(5, "# Name Service Switch configurat"..., 4096) = 390
read(5, "", 4096)                       = 0
newfstatat(5, "", {st_mode=S_IFREG|0644, st_size=390, ...}, AT_EMPTY_PATH) = 0
close(5)                                = 0
newfstatat(AT_FDCWD, "/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=75, ...}, 0) = 0
openat(AT_FDCWD, "/etc/host.conf", O_RDONLY|O_CLOEXEC) = 5
newfstatat(5, "", {st_mode=S_IFREG|0644, st_size=73, ...}, AT_EMPTY_PATH) = 0
read(5, "# Resolver configuration file.\n#"..., 4096) = 73
read(5, "", 4096)                       = 0
close(5)                                = 0
futex(0x7fb4dcd2324c, FUTEX_WAKE_PRIVATE, 2147483647) = 0
openat(AT_FDCWD, "/etc/resolv.conf", O_RDONLY|O_CLOEXEC) = 5
newfstatat(5, "", {st_mode=S_IFREG|0644, st_size=75, ...}, AT_EMPTY_PATH) = 0
read(5, "# Generated by NetworkManager\nna"..., 4096) = 75
read(5, "", 4096)                       = 0
uname({sysname="Linux", nodename="a", ...}) = 0
newfstatat(5, "", {st_mode=S_IFREG|0644, st_size=75, ...}, AT_EMPTY_PATH) = 0
close(5)                                = 0
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 5
newfstatat(5, "", {st_mode=S_IFREG|0644, st_size=184639, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 184639, PROT_READ, MAP_PRIVATE, 5, 0) = 0x7fb4dcd54000
close(5)                                = 0
openat(AT_FDCWD, "/usr/lib/libnss_mymachines.so.2", O_RDONLY|O_CLOEXEC) = 5
read(5, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
newfstatat(5, "", {st_mode=S_IFREG|0755, st_size=365360, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 365496, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 5, 0) = 0x7fb4dc92c000
mmap(0x7fb4dc933000, 237568, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0x7000) = 0x7fb4dc933000
mmap(0x7fb4dc96d000, 81920, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0x41000) = 0x7fb4dc96d000
mmap(0x7fb4dc981000, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0x55000) = 0x7fb4dc981000
mmap(0x7fb4dc985000, 952, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fb4dc985000
close(5)                                = 0
openat(AT_FDCWD, "/usr/lib/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 5
read(5, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
newfstatat(5, "", {st_mode=S_IFREG|0644, st_size=728120, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 147912, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 5, 0) = 0x7fb4dc907000
mmap(0x7fb4dc90b000, 110592, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0x4000) = 0x7fb4dc90b000
mmap(0x7fb4dc926000, 16384, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0x1f000) = 0x7fb4dc926000
mmap(0x7fb4dc92a000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0x22000) = 0x7fb4dc92a000
close(5)                                = 0
mprotect(0x7fb4dc92a000, 4096, PROT_READ) = 0
mprotect(0x7fb4dc981000, 12288, PROT_READ) = 0
munmap(0x7fb4dcd54000, 184639)          = 0
rt_sigprocmask(SIG_BLOCK, [HUP USR1 USR2 PIPE ALRM CHLD TSTP URG VTALRM PROF WINCH IO], [], 8) = 0
futex(0x7fb4dc984b18, FUTEX_WAKE_PRIVATE, 2147483647) = 0
openat(AT_FDCWD, "/run/systemd/machines/foobar.ddns.net", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 5
newfstatat(5, "", {st_mode=S_IFREG|0644, st_size=184639, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 184639, PROT_READ, MAP_PRIVATE, 5, 0) = 0x7fb4dcd54000
close(5)                                = 0
openat(AT_FDCWD, "/usr/lib/libnss_mdns_minimal.so.2", O_RDONLY|O_CLOEXEC) = 5
read(5, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \20\0\0\0\0\0\0"..., 832) = 832
newfstatat(5, "", {st_mode=S_IFREG|0755, st_size=18184, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 20496, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 5, 0) = 0x7fb4dc901000
mmap(0x7fb4dc902000, 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0x1000) = 0x7fb4dc902000
mmap(0x7fb4dc904000, 4096, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0x3000) = 0x7fb4dc904000
mmap(0x7fb4dc905000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0x3000) = 0x7fb4dc905000
close(5)                                = 0
openat(AT_FDCWD, "/usr/lib/libresolv.so.2", O_RDONLY|O_CLOEXEC) = 5
read(5, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
newfstatat(5, "", {st_mode=S_IFREG|0755, st_size=59704, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 67720, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 5, 0) = 0x7fb4dc8f0000
mmap(0x7fb4dc8f3000, 32768, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0x3000) = 0x7fb4dc8f3000
mmap(0x7fb4dc8fb000, 8192, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0xb000) = 0x7fb4dc8fb000
mmap(0x7fb4dc8fd000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0xd000) = 0x7fb4dc8fd000
mmap(0x7fb4dc8ff000, 6280, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fb4dc8ff000
close(5)                                = 0
mprotect(0x7fb4dc8fd000, 4096, PROT_READ) = 0
mprotect(0x7fb4dc905000, 4096, PROT_READ) = 0
munmap(0x7fb4dcd54000, 184639)          = 0
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 5
newfstatat(5, "", {st_mode=S_IFREG|0644, st_size=184639, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 184639, PROT_READ, MAP_PRIVATE, 5, 0) = 0x7fb4dcd54000
close(5)                                = 0
openat(AT_FDCWD, "/usr/lib/libnss_resolve.so.2", O_RDONLY|O_CLOEXEC) = 5
read(5, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
newfstatat(5, "", {st_mode=S_IFREG|0755, st_size=161928, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 162120, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 5, 0) = 0x7fb4dc5d8000
mmap(0x7fb4dc5dc000, 106496, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0x4000) = 0x7fb4dc5dc000
mmap(0x7fb4dc5f6000, 32768, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0x1e000) = 0x7fb4dc5f6000
mmap(0x7fb4dc5fe000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0x26000) = 0x7fb4dc5fe000
close(5)                                = 0
openat(AT_FDCWD, "/usr/lib/libm.so.6", O_RDONLY|O_CLOEXEC) = 5
read(5, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
newfstatat(5, "", {st_mode=S_IFREG|0755, st_size=965016, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 966952, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 5, 0) = 0x7fb4dc4eb000
mmap(0x7fb4dc4fb000, 520192, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0x10000) = 0x7fb4dc4fb000
mmap(0x7fb4dc57a000, 376832, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0x8f000) = 0x7fb4dc57a000
mmap(0x7fb4dc5d6000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 5, 0xea000) = 0x7fb4dc5d6000
close(5)                                = 0
mprotect(0x7fb4dc5d6000, 4096, PROT_READ) = 0
mprotect(0x7fb4dc5fe000, 4096, PROT_READ) = 0
munmap(0x7fb4dcd54000, 184639)          = 0
rt_sigprocmask(SIG_BLOCK, [HUP USR1 USR2 PIPE ALRM CHLD TSTP URG VTALRM PROF WINCH IO], [], 8) = 0
futex(0x7fb4dc5ff900, FUTEX_WAKE_PRIVATE, 2147483647) = 0
socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 5
connect(5, {sa_family=AF_UNIX, sun_path="/run/systemd/resolve/io.systemd.Resolve"}, 42) = 0
sendto(5, "{\"method\":\"io.systemd.Resolve.Re"..., 100, MSG_DONTWAIT|MSG_NOSIGNAL, NULL, 0) = 100
mmap(NULL, 135168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb4dcd61000
recvfrom(5, 0x7fb4dcd61010, 135152, MSG_DONTWAIT, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)
ppoll([{fd=5, events=POLLIN}], 1, {tv_sec=119, tv_nsec=999966000}, NULL, 8) = 1 ([{fd=5, revents=POLLIN}], left {tv_sec=119, tv_nsec=999866687})
recvfrom(5, "{\"parameters\":{\"addresses\":[{\"if"..., 135152, MSG_DONTWAIT, NULL, NULL) = 125
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
close(5)                                = 0
munmap(0x7fb4dcd61000, 135168)          = 0
socket(AF_INET, SOCK_DGRAM, IPPROTO_IP) = 5
connect(5, {sa_family=AF_INET, sin_port=htons(1025), sin_addr=inet_addr("192.168.0.231")}, 16) = 0
getsockname(5, {sa_family=AF_INET, sin_port=htons(42756), sin_addr=inet_addr("192.168.0.166")}, [16]) = 0
close(5)                                = 0
setsockopt(3, SOL_IP, IP_RECVERR, [1], 4) = 0
setsockopt(3, SOL_IP, IP_RECVTTL, [1], 4) = 0
setsockopt(3, SOL_IP, IP_RETOPTS, [1], 4) = 0
setsockopt(3, SOL_SOCKET, SO_SNDBUF, [324], 4) = 0
setsockopt(3, SOL_SOCKET, SO_RCVBUF, [65536], 4) = 0
getsockopt(3, SOL_SOCKET, SO_RCVBUF, [131072], [4]) = 0
newfstatat(1, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}, AT_EMPTY_PATH) = 0
write(1, "PING foobar.ddns.net (192.168."..., 61PING foobar.ddns.net (192.168.0.231) 56(84) bytes of data.
) = 61
setsockopt(3, SOL_SOCKET, SO_TIMESTAMP_OLD, [1], 4) = 0
setsockopt(3, SOL_SOCKET, SO_SNDTIMEO_OLD, "\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16) = 0
setsockopt(3, SOL_SOCKET, SO_RCVTIMEO_OLD, "\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16) = 0
rt_sigaction(SIGINT, {sa_handler=0x55fde81df570, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fb4dcb80710}, NULL, 8) = 0
rt_sigaction(SIGALRM, {sa_handler=0x55fde81df570, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fb4dcb80710}, NULL, 8) = 0
rt_sigaction(SIGQUIT, {sa_handler=0x55fde81dac80, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fb4dcb80710}, NULL, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
ioctl(1, TCGETS, {c_iflag=ICRNL|IXON|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
ioctl(1, TIOCGWINSZ, {ws_row=70, ws_col=295, ws_xpixel=0, ws_ypixel=0}) = 0
capget({version=_LINUX_CAPABILITY_VERSION_3, pid=0}, NULL) = 0
capset({version=_LINUX_CAPABILITY_VERSION_3, pid=0}, {effective=0, permitted=0, inheritable=0}) = 0
sendto(3, "\10\0\5\310\377\377\0\1\302\334\240e\0\0\0\0\307!\t\0\0\0\0\0\20\21\22\23\24\25\26\27"..., 64, 0, {sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("192.168.0.231")}, 16) = 64
setitimer(ITIMER_REAL, {it_interval={tv_sec=0, tv_usec=0}, it_value={tv_sec=10, tv_usec=0}}, NULL) = 0
recvmsg(3, {msg_name={sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("192.168.0.231")}, msg_namelen=128 => 16, msg_iov=[{iov_base="\0\0\r\301\0\7\0\1\302\334\240e\0\0\0\0\307!\t\0\0\0\0\0\20\21\22\23\24\25\26\27"..., iov_len=192}], msg_iovlen=1, msg_control=[{cmsg_len=32, cmsg_level=SOL_SOCKET, cmsg_type=SO_TIMESTAMP_OLD, cmsg_data={tv_sec=1705041090, tv_usec=602526}}, {cmsg_len=20, cmsg_level=SOL_IP, cmsg_type=IP_TTL, cmsg_data=[64]}], msg_controllen=56, msg_flags=0}, 0) = 64
newfstatat(AT_FDCWD, "/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=75, ...}, 0) = 0
newfstatat(AT_FDCWD, "/etc/nsswitch.conf", {st_mode=S_IFREG|0644, st_size=390, ...}, 0) = 0
rt_sigprocmask(SIG_BLOCK, [HUP USR1 USR2 PIPE ALRM CHLD TSTP URG VTALRM PROF WINCH IO], [], 8) = 0
socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 5
connect(5, {sa_family=AF_UNIX, sun_path="/run/systemd/resolve/io.systemd.Resolve"}, 42) = 0
sendto(5, "{\"method\":\"io.systemd.Resolve.Re"..., 109, MSG_DONTWAIT|MSG_NOSIGNAL, NULL, 0) = 109
brk(0x55fde8f9f000)                     = 0x55fde8f9f000
recvfrom(5, 0x55fde8f5e4d0, 131080, MSG_DONTWAIT, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)
ppoll([{fd=5, events=POLLIN}], 1, {tv_sec=119, tv_nsec=999968000}, NULL, 8) = 1 ([{fd=5, revents=POLLIN}], left {tv_sec=112, tv_nsec=476016014})
recvfrom(5, "{\"error\":\"io.systemd.Resolve.Max"..., 131080, MSG_DONTWAIT, NULL, NULL) = 66
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
close(5)                                = 0
write(1, "64 bytes from 192.168.0.231: icm"..., 6064 bytes from 192.168.0.231: icmp_seq=1 ttl=64 time=4.06 ms
) = 60
write(1, "\n", 1
)                       = 1
write(1, "--- foobar.ddns.net ping stati"..., 42--- foobar.ddns.net ping statistics ---
) = 42
write(1, "1 packets transmitted, 1 receive"..., 601 packets transmitted, 1 received, 0% packet loss, time 0ms
) = 60
write(1, "rtt min/avg/max/mdev = 4.055/4.0"..., 50rtt min/avg/max/mdev = 4.055/4.055/4.055/0.000 ms
) = 50
close(1)                                = 0
close(2)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++

我确实看到EAGAIN (Resource temporarily unavailable)有两个。我正在使用 systemd 的解析(应该早点提到)。

更新:运行 ping 可-n消除任何延迟:

来自man ping

-n 仅数字输出。不会尝试查找主机地址的符号名称(无反向 DNS 解析)。这是数字目标或 -f 选项的默认设置。覆盖先前定义的 -H 选项。


结论:

由于它是分配给主机名的私有 IP,因此反向 DNS 查找不可能成功,只会造成延迟。

答案1

我认为这不是正向解析的问题,而是反向解析的问题 - ping 在显示响应时报告地址,而不是名称。尝试检查将 192.168.0.231 解析回名称(或失败)需要多长时间。您也可以尝试ping -n抑制 DNS 查找。

附注:可以将私有 IP 空间解析回本地名称。但是,这需要为适当的区域运行自己的权威名称服务器,并且可能需要解析器配置才能使用它。

相关内容