linux - 为什么我不能在 Linux 上 ping 带有前导或尾随下划线的地址

标签 linux dns ping

在 window 上:

  • 在浏览器中访问 _.github.com 有效
  • nslookup _.github.com 有效
  • ping _.github.com 有效

在 linux 上(在两个独立的网络上测试):

  • 在浏览器中访问 _.github.com 有效
  • host _.github.com 有效
  • ping _.github.com
  • python -c "import requests; requests.get('_.github.com')" 不会

这是怎么回事?

最佳答案

因为 Linux(更具体地说,它的某些组件,例如 libresolv 甚至 ping 本身)正在遵守 RFC。主机名中不允许使用下划线,主机名是您在使用 ping 时查找的内容。 (其他类型的 DNS 记录中允许使用下划线,例如 SRV 记录、TXT 记录,例如用于 DKIM 的记录...)

参见 RFC 1123第 2.1 节和 RFC 952 .以下是该主题讨论的其他一些链接:

Stack Overflow - Can (hostname) subdomains have an underscore “_” in it?

Domainkey - Underscores in DNS

Quora - Why are underscores not allowed in DNS host names?

更新:正如一些人在评论中指出的那样,Linux ping 对 a_a.github.com 很满意。再做一些测试(在本例中为 CentOS 7):

ping: unknown host _.github.com
ping: unknown host a_.github.com
ping: unknown host _a.github.com

$ ping a_a.github.com
PING github.map.fastly.net (23.235.40.133) 56(84) bytes of data.
64 bytes from 23.235.40.133: icmp_seq=1 ttl=59 time=29.7 ms

所以看起来 Linux ping 并没有完全拒绝下划线,但它确实不允许它成为主机名原子中的第一个或最后一个字符(或者,因此,唯一的字符)。

关于linux - 为什么我不能在 Linux 上 ping 带有前导或尾随下划线的地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33447903/

相关文章:

c++ - unix 套接字与共享内存消息哪个更快

c - unlinkat() C 中的目录

java - 无法在 xfce4 桌面上启动 Java 应用程序? - 去你的 lightdm

azure - 通过 Azure 上的 Blob 存储托管的根域静态网站?

c++ - Ubuntu系统中不同内容的同名 header

dns - 使用 Python 请求精确捕获 DNS 错误

apache - 子域不起作用

java - Tomcat 7.0 启动时抛出错误

java - 如何在java中搜索字符串及其后面的数字

javascript - 运行 Node.js 命令不会产生任何输出并且不会退出