Cygwin Ping

If you use Cygwin, you may notice that when you try to use the ping command, you get an error.

This is because typing ping in a Cygwin terminal window executes the *nix version of ping rather than the Windows ping. The *nix ping requires low level socket access that is only available when running as an Administrator. Because there is no sudo command in Cygwin, the only way to acquire administrator privileges is to quit your current terminal window and restart it with the privileges. This is rather cumbersome if you simply want to check whether a server is running.

The solution is to create an alias to the Windows ping in your .bash_profile file. That means any time you run the ping command, you are now running the windows version which requires no admin rights.

Add the following line to the .bash_profile file (create it if necessary) in your home directory.
alias ping='$SYSTEMROOT/system32/ping'

Before:

user@host ~
$ ping google.com
ping: socket: Operation not permitted

After:

user@host ~
$ pingw google.com

Pinging google.com [173.194.36.104] with 32 bytes of data:
Reply from 173.194.36.104: bytes=32 time=24ms TTL=56
Reply from 173.194.36.104: bytes=32 time=23ms TTL=56
Reply from 173.194.36.104: bytes=32 time=23ms TTL=56
Reply from 173.194.36.104: bytes=32 time=23ms TTL=56

Ping statistics for 173.194.36.104:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 23ms, Maximum = 24ms, Average = 23ms

If you require the *nix native version of ping at any time, you can simply run /bin/ping google.com with admin rights.

7 thoughts on “Cygwin Ping

  1. Can you please elaborate a bit more on "you can run /bin/ping with admin rights". How do you get "admin" rights in cygwin?

    Many thanks,

    Georgios

  2. Hi,

    You can get Windows admin rights by right clicking on your Cygwin shortcut, and selecting "Run as administrator" under the Advanced options of the Shortcut tab.

    Jon

  3. CYGWIN and PING | Apps DBA notes

  4. Hi,

    I tried running the following command through jenkins on Windows with cygwin latest version installed.
    ping -c 1
    It is throwing the error 'bad option c'
    > Is there any plugin kind of thing for cyqwin to support the advanced options in ping command?

    Thank You.

Leave a Reply