56

I am using an HTTP proxy server to connect to the internet.

Because of that my pings are not working

ping www.google.com

says Unreachable Host

How can I configure ping to use the HTTP proxy?

1
  • 1
    It may be helpful to know what setup you are using? Is this a linux server with squid and iptables for example?
    – user15968
    Aug 13, 2010 at 9:51

4 Answers 4

51

In general you can't. ping needs a direct network connection on the IP level to do its work. A proxy works on a higher layer of the TCP/IP network model, where there is no direct access to the IP protocol.

You would need to somehow circumvent the proxy (change firewall settings, use a VPN, ...). Whether this is possible (and allowed) depends on your network configuration, but it's probably not possible.

As a workaround, there are many web-based ping services available (search for "web-based ping"). These will work.

3
  • Web-based pings cannot be used to test the latency of my own connection, as they are initiated from the server. Maybe some implementation of ping in java that runs in the browser. Sep 8, 2015 at 8:14
  • While the ICMP protocol operates on ISO/OSI layer 3, the ping utility operates on layer 7. To quote my CS teacher, ping is a 3-7 hybrid. It may well be possible that the layer 7 part is capable of proxy handling. This would explain why my answer to this question works (at least for me).
    – s3lph
    Sep 13, 2015 at 18:56
  • @the_Seppi: Interesting, I've never heard of ping being layer 7. Do you have any pointers for further reading?
    – sleske
    Sep 13, 2015 at 20:28
10

You may try this,But first you have to install curl.

http_proxy=http://<proxy_username>:<proxy_password>@<your_proxy_server>:<your_proxy_port>  curl -I http://google.com/
5
  • 40
    this is not PING. Feb 24, 2015 at 20:42
  • 4
    or you can use curl -x 'http://<proxy_username>:<proxy_password>@<your_proxy_server>:<your_proxy_port>'
    – phyatt
    Dec 7, 2017 at 18:20
  • 2
    @törzsmókus: But it is likely a good answer to the source of the question ... to test, if some server is available and working! Nov 19, 2018 at 9:51
  • 1
    The question was, How can I configure ping to use the HTTP proxy? This post by @Ishant Mrinal does not answer that. If someone asks a question [How] to test, if some server is available and working [from behind a proxy?], feel free to add this answer, and also link to it in the comments of this question. Nov 19, 2018 at 12:05
  • 3
    @törzsmókus - You are correct in that the answer does not address strictly the question. It may be the case that the OP (or other readers searching for a similar idea, as myself) asks this while not being specifically interested in using ping, but in using it only as a quick way to test if a given PC is reaching the outside network (as another use, besides the comment by Andreas Dietrich). I found this answer useful (the main idea behind SO), and so did at least other 8 users. Jan 8, 2019 at 6:38
6

As others noted, ping doesn't work through proxy.

But you can use utility httping for that. It sends a HEAD request (by default) to a web server and measures the time it took to get a response.

Example:

httping -x 192.68.1.12:1080 -g http://google.com

Example output:

➜  ~ httping -g http://google.com -c 3
PING google.com:80 (/):
connected to 64.233.165.113:80 (313 bytes), seq=0 time= 38.49 ms 
connected to 64.233.165.101:80 (313 bytes), seq=1 time= 66.94 ms 
connected to 64.233.165.100:80 (313 bytes), seq=2 time= 40.79 ms 
--- http://google.com/ ping statistics ---
3 connects, 3 ok, 0.00% failed, time 3162ms
round-trip min/avg/max = 38.5/48.7/66.9 ms

Where:

  • -x - Address of a proxy server, port is optional
  • -g - URL to send a request to

Other useful options:

  • -5 - Use SOCKS5. Should be put after the -x option, i.e.:

    httping -x localhost:1080 -5 -g http://google.com
    
  • -c - How many probes to send before exiting. Infinite by default.
  • -G - Do a GET request instead of a HEAD request. That means that also full page/file will be transferred. Note that in this case you're no longer measuring the latency! Useful for testing actual websites.

Be noticed that the time measured also includes the latency introduced by the proxy server itself.


The utility is available through a number of repositories for different OS'es and Linux distros:

Ubuntu:

sudo apt install httping

Alpine:

sudo apk add httping

macOS with Homebrew:

brew install httping

As another example, I used httping to estimate latency of my connection to Tor network through Tor proxy:

httping -x localhost:9050 -5 -g http://google.com

The only option I wish httping had is the ability to ask SOCKS5 proxy for domain name resolution, instead of doing it on its own, which is a more secure way with Tor.


Here is a link to the author's website:

https://www.vanheusden.com/httping/

2
  • 2
    This is not ping. Ping works on low level to get you faster responses. If you are using httping, then as it works with HEAD requests, there will be much speed loss depending on server's ability to serve requests, PHP, Node.js whatever. Example: I am getting a ping of less than 10ms for Google DNS 8.8.8.8, but I am getting ping of 120ms via httping for google.com even when website is CDN enabled.
    – Rehmat
    May 30, 2021 at 4:41
  • @Rehmat That's literally the third sentence in my answer. Since ping is typically used to figure out if one can reach a specific server (or, often, any server at all) through a specific connection, httping is a good enough replacement for situations where ping won't do. May 31, 2021 at 7:46
1

Following : Bogdan Kondratov answer, here is a free http-ping utility for windows

 http-ping -p http://142.4.15.25:3128 https://www.coretechnologies.com

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .