Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can I not ping addresses with leading or trailing underscores on linux

Tags:

linux

ping

dns

On windows:

  • Accessing _.github.com in the browser works
  • nslookup _.github.com works
  • ping _.github.com works

On linux (tested on two separate networks):

  • Accessing _.github.com in the browser works
  • host _.github.com works
  • ping _.github.com does not
  • python -c "import requests; requests.get('_.github.com')" does not

What is going on here?

like image 517
Eric Avatar asked Oct 19 '22 23:10

Eric


1 Answers

Because Linux (more specifically, some component of it such as libresolv or even ping itself) is honoring the RFCs. Underscores are not allowed in hostnames, and a hostname is what you are looking up when using ping. (Underscores are allowed in other types of DNS records, for example SRV records, TXT records such as those used for DKIM...)

See RFC 1123 section 2.1, and RFC 952. Here are some other links to discussion of this topic:

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

Domainkey - Underscores in DNS

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

Update: As a couple of people pointed out in comments, Linux ping is happy with a_a.github.com. Doing a few more tests (CentOS 7 in this case):

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

So it seems Linux ping does not reject the underscore completely, but it does appear it disallows it being the first or last character (or, as a consequence, the only character) in an atom of the hostname.

like image 196
Dan Lowe Avatar answered Oct 22 '22 02:10

Dan Lowe