49

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?

JumpingJezza
  • 147
  • 8
Saransh Singh
  • 666
  • 1
  • 5
  • 8
  • 32
    What's confusing here is that ping shouldn't be even able to resolve that as a hostname, much less send out failed ICMP packets. What OS/version are you on? – fluffy Jun 21 '15 at 08:31
  • 11
    I apologize, but I voted this down because of a combination of reasons - new user with one question that contains a URL to their website with apparently falsified output from PING. By all rights, that's an attempt to drive traffic to the URL. Unless we can find out which operating system has a version of PING that 1) knows what a URL is, and 2) identifies the icmp_seq number for each time out. – Dawn Benton Jun 21 '15 at 15:11
  • 1
    @DawnBenton To add on that, the actual command is missing. We can almost safely assume it isn't a simple `ping http://example.com`. Windows sends a default of 32 bytes, while Linux usuallyis 64 bytes. – Ismael Miguel Jun 21 '15 at 16:01
  • @IsmaelMiguel Can someone try this on Ubuntu? According to [Ping fails: is a webserver configuration issue or not?](http://serverfault.com/q/200721) it uses 56 data bytes and outputs "Request timeout for icmp_seq 0" etc – DavidPostill Jun 21 '15 at 16:09
  • 2
    IMO - Spam: http://stackoverflow.com/questions/30958899/difference-between-pinging-with-and-without-http - Saransh, please edit the website name out and post your actual Ping results for both cases. Otherwise it will (most likely) be closed. – Ƭᴇcʜιᴇ007 Jun 21 '15 at 16:33
  • 11
    Probably related: [Why is ping resolving to an IP 198.105.254.228 for any random hostname that i type?](http://superuser.com/questions/836997/why-is-ping-resolving-to-an-ip-198-105-254-228-for-any-random-hostname-that-i-ty) – Mokubai Jun 21 '15 at 17:47
  • 3
    Keep in mind that `www.example.com` and `example.com` are *not* the same in terms of DNS records. So there really are two differences between the examples given. – user Jun 21 '15 at 18:16
  • 26
    To the people who downvoted because they didn't know there are DNS services that hijack failed lookups, didn't know `ping` and `getaddrinfo()` and friends pass through slashes, didn't know that `56 data bytes` is a common default, etc.: Please take this as a sign that your efforts to learn about things more before trying to help would be appreciated. – rakslice Jun 21 '15 at 20:03
  • 6
    @Ƭᴇcʜιᴇ007 The ping results are real, I see the exact same when I ping an invalid hostname with TimeWarner Cable DNS on OS X. – Hunter Dolan Jun 21 '15 at 21:29
  • 2
    Hello all I wasn't trying to falsify anything what so ever you want I can prove the output is correct and I am using a Mac OS if that helps – Saransh Singh Jun 22 '15 at 03:49
  • Techie007 as you can see people asked me to post the q here and that's y i did it its not a spam, I just needed some help – Saransh Singh Jun 22 '15 at 03:52
  • @SaranshSingh The problem about being spam-ish is that you have **YOUR** website there, instead of the default `example.com`, **as you should have**. And yes, I recommend you to go to http://example.com/. – Ismael Miguel Jun 22 '15 at 09:06
  • @rakslice It was me who was commenting about the ping size. And I commented because I've never seen a default of 56 bytes. And, if you refer to my comment, it is saying **usually**, instead of **always**. – Ismael Miguel Jun 22 '15 at 09:08
  • 6
    @IsmaelMiguel On the contrary, over at ServerFault we actively encourage people to use their real domains when posting questions. At least one person has had a complex DNS issue diagnoses for them like that. I don't see why that should be different here and I don't understand why everyone is getting at the OP – Dan Jun 22 '15 at 10:00
  • 1
    @Dan That doesn't apply in this answer. The important point is that there is a `http://` in the domain name. And that's it. It really looks like a self-promotion. Now that the spammy website was removed, I've upvoted the post accordingly, since it is a good question (even though you could just Google the answer, but well, lets not be that nitty picky). – Ismael Miguel Jun 22 '15 at 10:44
  • 3
    @IsmaelMiguel It doesn't apply here but only because we know the answer.The OP didn't know that and you're making the presumption it's self promotion based on nothing more than the fact a real domain was used. Which, IMHO, should be encouraged – Dan Jun 22 '15 at 10:48
  • @Dan It's not that only, but also the fact that the SAME question was posted on StackOverflow and no other attempt, with another address, was tried or specified. If it had a Google attempt, I wouldn't even complain if it had an attempt to use Google or (the standard) example.com. – Ismael Miguel Jun 22 '15 at 11:03

4 Answers4

108

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.

DavidPostill
  • 153,128
  • 77
  • 353
  • 394
34

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.

Hunter Dolan
  • 453
  • 4
  • 7
  • 5
    It's worth pointing out that the actual domain/ip was edited out by the Community bot."123.456.789.000" was originally the IP address that TWC's DNS threw out when you attempted to resolve a non existent hostname. – Hunter Dolan Jun 21 '15 at 21:25
  • 1
    The bot does not know how to make automatic edits; I would say it is an edit that was suggested by an anonymous user. – Léo Lam Jun 22 '15 at 11:09
  • The edit was proposed by an anonymous user and approved by myself and another user. – DavidPostill Jun 23 '15 at 16:58
21

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.

KJ4TIP
  • 361
  • 1
  • 8
  • I'd say it's not obvious to someone who doesn't already know, but now that you know the info from KJ4TIP's answer, look at the output: `Request timeout for icmp_seq 0` You can see the ICMP there, meaning ICMP sequence 0, 1, 2... – Tyler Collier Jun 21 '15 at 02:03
0

Why would you use 'ping' anyway. It's not going to work if there is a firewall in the way blocking 'ping' traffic.

In my opinion if your going to test a web server then its better to use 'telnet', then you can test the host and the port it should be listening on.

eg: To test your web server telnet www.mywebserver.com 80 at the blank screen, type in 'get' then 'enter' and you should get a pile of http response back from the web server. (eg: HTTP/1.1 400 Bad Request...)

This tells me that not only is the server 'up' but it's also listening and responding on port 80. (I'd also expect any firewalls to let port 80 through to my web server )

Similarly 'telnet' also works for testing mail servers , ftp and just about anything else.

MattW
  • 11