arp 命令如何解析主机名?

mrh*_*h53 3 networking ethernet

当我运行 arp 命令时,我得到以下信息:

mark@mark-P8Z77-I-0:~$ arp
Address                  HWtype  HWaddress           Flags Mask            Iface
192.168.1.128            ether   08:86:3b:c8:d8:09   C                     eth0
192.168.1.4              ether   e0:91:f5:7c:7c:34   C                     eth0
192.168.1.110            ether   9c:d3:6d:b1:d3:49   C                     eth0
192.168.1.101            ether   94:10:3e:48:60:0d   C                     eth0
mark-N3050T              ether   d0:17:c2:ad:ff:58   C                     eth0
192.168.1.117            ether   b8:27:eb:ad:2e:72   C                     eth0
192.168.1.129                    (incomplete)                              eth0
192.168.1.103            ether   ec:1a:59:cb:42:25   C                     eth0
192.168.1.111            ether   54:4a:16:02:54:a8   C                     eth0
192.168.1.127            ether   84:ba:3b:05:6d:45   C                     eth0
192.168.1.106            ether   a4:77:33:2b:29:40   C                     eth0
192.168.1.122            ether   00:18:dd:04:6a:cc   C                     eth0
mark-N53Jf               ether   48:5d:60:71:7f:be   C                     eth0
gateway                  ether   28:c6:8e:20:a8:e5   C                     eth0
Run Code Online (Sandbox Code Playgroud)

报告中出现的所有三个主机名也可以使用ping hostname arp 表进行 ping ,/proc/net/arp 仅包含 ip 地址:

mark@mark-P8Z77-I-0:~$ cat /proc/net/arp
IP address       HW type     Flags       HW address            Mask     Device
192.168.1.128    0x1         0x2         08:86:3b:c8:d8:09     *        eth0
192.168.1.4      0x1         0x2         e0:91:f5:7c:7c:34     *        eth0
192.168.1.110    0x1         0x2         9c:d3:6d:b1:d3:49     *        eth0
192.168.1.101    0x1         0x2         94:10:3e:48:60:0d     *        eth0
192.168.1.138    0x1         0x2         d0:17:c2:ad:ff:58     *        eth0
192.168.1.117    0x1         0x2         b8:27:eb:ad:2e:72     *        eth0
192.168.1.129    0x1         0x0         00:00:00:00:00:00     *        eth0
192.168.1.103    0x1         0x2         ec:1a:59:cb:42:25     *        eth0
192.168.1.111    0x1         0x2         54:4a:16:02:54:a8     *        eth0
192.168.1.127    0x1         0x2         84:ba:3b:05:6d:45     *        eth0
192.168.1.106    0x1         0x2         a4:77:33:2b:29:40     *        eth0
192.168.1.122    0x1         0x2         00:18:dd:04:6a:cc     *        eth0
192.168.1.121    0x1         0x2         48:5d:60:71:7f:be     *        eth0
192.168.1.1      0x1         0x2         28:c6:8e:20:a8:e5     *        eth0
Run Code Online (Sandbox Code Playgroud)

arp 命令和 ping 使用什么服务来解析主机名?

我已经尝试了几种,但最接近的是 avahi-browse。但是,它在我的网络上报告的主机名比 arp 报告多,并且所有主机名都.local附加到名称后。

此外,arp 报告的三个主机名中有两个是远程 ubuntu 系统。我不记得在这些系统上执行任何特殊配置以允许这种行为。“网关”主机名由路由器提供。连接的系统之一是 raspian 系统。

我将如何为这种行为配置 raspian?主机名是如何转移的?

我将使用什么命令来解析这些主机名?

最后一点:主机名似乎根据数据的陈旧程度来来去去,但我还没有对此进行全面调查。我只知道我需要从给定的(ubuntu)主机 ping 才能捕获其他系统的主机名。我还没有确定哪些查询最能快速填充这些信息。

在查看了截至美国东部标准时间 12 月 18 日晚上 8:00 的评论后,我可以分享以下信息:主机行/etc/nsswitch.conf

hosts:          files mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns mdns4 myhostname
Run Code Online (Sandbox Code Playgroud)

没有列出远程主机 /etc/hosts

avahi-resolve-address 解决以下问题:

192.168.1.1    Failed to resolve: Timeout reached (is "gateway")
192.168.1.117 raspberrypi.local    (shows in arp report as 192.168.1.117)
192.168.1.138 mark-3050T.local    (shows in arp as mark-3050T)
192.168.1.130 is currently offline but is similar to 192.168.1.130
Run Code Online (Sandbox Code Playgroud)

虽然arp上报了mark-N3050T,但是ping不通。 ping mark-N3050T.local失败但ping 192.168.1.138成功 ping 网关成功。 ping raspberrypi.local即使 arp 未报告 raspberrypi 也会成功

当我写我的原始帖子时ping mark-N3050T会起作用,所以发生了一些老化,删除了这个主机名。我还没有找到刷新主机名的命令。arp 和 ping 之间的区别在于 arp 将 IP 地址解析为主机名,而 ping 执行相反的操作。但是,我希望答案具有对称性。

我只是为了增加我对 LAN 网络如何工作的理解。我很感激任何愿意帮助我的人。

hee*_*ayl 8

这是顺序:

  • 首先从arp获取它的数据(缓存)/proc/net/arp,Linux 通过用户空间的伪procfs文件系统/proc/net/arp文件公开它的 ARP 缓存。内核不存储任何域名,只存储IP地址;这类似于使用arp -n

  • 现在,当您想要arp获取主机名时,arp只需准确地遵循glibc's nsswitchconfiguration,/etc/nsswitch.conf并尝试使用该文件中提到的序列获取主机名,例如hosts: files mdns4 dns,在这种情况下arp将:

    • 检查/etc/hosts文件
    • 然后mdns(多播 DNS)
    • 通用DNS

    请注意,如果您.local在域名末尾看到,那么它(大概)由mdns(除非您确实拥有这样的 TLD)解析。