Difference between pinging with and without http://
I am trying to ping my website http://www.example.com/
and it resolves to an unknown IP address and times out.
PING http://www.example.com/ (198.105.254.228): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
but when I ping example.com
it works
What is it that I'm missing out here?
I am trying to ping my website http://www.example.com/ and it resolves to an unknown IP address and times out.
PING http://www.example.com/ (198.105.254.228): 56 data bytes
Request timeout for icmp_seq 0
The argument to ping is a hostname (or an IP address).
So the following will all work:
ping example.com
ping www.example.com
ping 127.0.0.1
On the other hand,
ping http://www.example.com/
will not work as http://www.example.com/ is an HTTP Uniform Resource Locator (URL) not a valid hostname (although part of it is a hostname).
A HTTP URL is made up of 4 parts:
- Scheme — always present
- Hostname — always present
- Path or Stem — always present but sometimes is null
- Parameters — optional
Ping will not normally recognise URLs as a valid destination hostname.
Notes:
Not all URLs have the format mentioned above.
A complete URL consists of a naming scheme specifier followed by a string whose format is a function of the naming scheme.
The format of a URL is defined in the IETF specification Uniform Resource Locators (URL)
DNS Hijacking
An exception to the above can happen if the DNS server (which resolves hostnames to IP addresses) is configured to return a valid IP address even if an invalid hostname is supplied.
This can happen if an ISP is hijacking your DNS queries.
From the answer Why is ping resolving to an IP 198.105.254.228 for any random hostname that i type? by Michael Hampton:
They are trying to be "helpful" by redirecting requests for nonexistent domains to a white label service that provides search results and advertising, from which everyone but you gets a cut of the revenue.
Fortunately they do have a preferences page where you can supposedly turn it off.
When you run the ping command with a string that is not an IP address, it first needs to resolve the IP address of the host you are attempting to ping.
When you run:
$ ping example.com
The DNS server returns the IP address of the server that hosts the website.
However when you prefix the protocol and path to create a standard http URL that is all sent to the DNS server to be resolved.
So instead of the DNS server finding the record for example.com
it looks for the record http://example.com/
which is not a valid hostname.
A lot of DNS servers will return with nothing. In that case the ping command will just error out with a DNS resolution error.
However your DNS server returns the IP address 123.456.789.000
. The address appears to be a suggestion service by Time Warner Cable to help users who mistyped the url in their browser.
But the ping command takes this literally and believes that the hostname http://example.com/
(which is not a valid hostname) resolves to the address 123.456.789.000
.
The reason the ping command times out after that is because 123.456.789.000
does not respond to ICMP requests.
The http:// stands for hyper text transfer protocol, the protocol used to access web pages. Pinging a server doesn't use HTTP, but instead consists of an ICMP (internet control message protocol) message, so the http:// doesn't make sense in this context.