Can't connect to Internet in bash using Mac OS





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}








4

















My browser works perfectly using the using Internet, however, when I tried to use this command in bash:



ping -q -w1 -c1 google.com &>/dev/null && echo online || echo offline


It gives me "offline" results. I have also tried another one in a different network:



ping -c 3 www.google.com


It returns:



PING www.google.com (74.125.193.147): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1

--- www.google.com ping statistics ---
3 packets transmitted, 0 packets received, 100.0% packet loss


All of these seem to point out that the terminal couldn't reach to the internet. I have tried using wifi and lan cable, the outcomes are the same.



I need to run a program which requires connection to a server, I wonder if you have any solutions to switch it back to online. I'm on macOS 10.13 and am looking to determine from the command line if a network connection is viable.



Is this possible?










share|improve this question





























  • Please edit your question to fix this. Also add which browser you are using and the output of curl https://google.com/.

    – nohillside
    May 28 at 14:37











  • I'm using chrome. Here's the output <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <A HREF="google.com/">here</A>. </BODY></HTML>

    – Zeyan Zhong
    May 28 at 16:03






  • 1





    If curl works I suspect some filtering done by your ISP

    – nohillside
    May 28 at 16:10


















4

















My browser works perfectly using the using Internet, however, when I tried to use this command in bash:



ping -q -w1 -c1 google.com &>/dev/null && echo online || echo offline


It gives me "offline" results. I have also tried another one in a different network:



ping -c 3 www.google.com


It returns:



PING www.google.com (74.125.193.147): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1

--- www.google.com ping statistics ---
3 packets transmitted, 0 packets received, 100.0% packet loss


All of these seem to point out that the terminal couldn't reach to the internet. I have tried using wifi and lan cable, the outcomes are the same.



I need to run a program which requires connection to a server, I wonder if you have any solutions to switch it back to online. I'm on macOS 10.13 and am looking to determine from the command line if a network connection is viable.



Is this possible?










share|improve this question





























  • Please edit your question to fix this. Also add which browser you are using and the output of curl https://google.com/.

    – nohillside
    May 28 at 14:37











  • I'm using chrome. Here's the output <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <A HREF="google.com/">here</A>. </BODY></HTML>

    – Zeyan Zhong
    May 28 at 16:03






  • 1





    If curl works I suspect some filtering done by your ISP

    – nohillside
    May 28 at 16:10














4












4








4


2






My browser works perfectly using the using Internet, however, when I tried to use this command in bash:



ping -q -w1 -c1 google.com &>/dev/null && echo online || echo offline


It gives me "offline" results. I have also tried another one in a different network:



ping -c 3 www.google.com


It returns:



PING www.google.com (74.125.193.147): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1

--- www.google.com ping statistics ---
3 packets transmitted, 0 packets received, 100.0% packet loss


All of these seem to point out that the terminal couldn't reach to the internet. I have tried using wifi and lan cable, the outcomes are the same.



I need to run a program which requires connection to a server, I wonder if you have any solutions to switch it back to online. I'm on macOS 10.13 and am looking to determine from the command line if a network connection is viable.



Is this possible?










share|improve this question

















My browser works perfectly using the using Internet, however, when I tried to use this command in bash:



ping -q -w1 -c1 google.com &>/dev/null && echo online || echo offline


It gives me "offline" results. I have also tried another one in a different network:



ping -c 3 www.google.com


It returns:



PING www.google.com (74.125.193.147): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1

--- www.google.com ping statistics ---
3 packets transmitted, 0 packets received, 100.0% packet loss


All of these seem to point out that the terminal couldn't reach to the internet. I have tried using wifi and lan cable, the outcomes are the same.



I need to run a program which requires connection to a server, I wonder if you have any solutions to switch it back to online. I'm on macOS 10.13 and am looking to determine from the command line if a network connection is viable.



Is this possible?







macos terminal network command-line bash






share|improve this question
















share|improve this question













share|improve this question




share|improve this question








edited May 28 at 17:35









bmike

170k47 gold badges311 silver badges669 bronze badges




170k47 gold badges311 silver badges669 bronze badges










asked May 28 at 14:15









Zeyan ZhongZeyan Zhong

212 bronze badges




212 bronze badges
















  • Please edit your question to fix this. Also add which browser you are using and the output of curl https://google.com/.

    – nohillside
    May 28 at 14:37











  • I'm using chrome. Here's the output <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <A HREF="google.com/">here</A>. </BODY></HTML>

    – Zeyan Zhong
    May 28 at 16:03






  • 1





    If curl works I suspect some filtering done by your ISP

    – nohillside
    May 28 at 16:10



















  • Please edit your question to fix this. Also add which browser you are using and the output of curl https://google.com/.

    – nohillside
    May 28 at 14:37











  • I'm using chrome. Here's the output <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <A HREF="google.com/">here</A>. </BODY></HTML>

    – Zeyan Zhong
    May 28 at 16:03






  • 1





    If curl works I suspect some filtering done by your ISP

    – nohillside
    May 28 at 16:10

















Please edit your question to fix this. Also add which browser you are using and the output of curl https://google.com/.

– nohillside
May 28 at 14:37





Please edit your question to fix this. Also add which browser you are using and the output of curl https://google.com/.

– nohillside
May 28 at 14:37













I'm using chrome. Here's the output <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <A HREF="google.com/">here</A>. </BODY></HTML>

– Zeyan Zhong
May 28 at 16:03





I'm using chrome. Here's the output <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <A HREF="google.com/">here</A>. </BODY></HTML>

– Zeyan Zhong
May 28 at 16:03




1




1





If curl works I suspect some filtering done by your ISP

– nohillside
May 28 at 16:10





If curl works I suspect some filtering done by your ISP

– nohillside
May 28 at 16:10










3 Answers
3






active

oldest

votes


















5


















I prefer to use the system configuration utility tool to test for reachability instead of using ping / host / nslookup or another proxy for determining if a network entity is or is not reachable.



scutil -r google.com
Reachable


The benefits of this are that if you have VPN connections, dial up, modem, or a routing conflict, this will actually test that you can reach the device and not just resolve the cached host name, etc... in my experience. (also, it's a lot harder to mess up the indirection, files, logic and you get a direct answer back in English)



Like all good command line tools, it returns 0 to let you know the answer it provides is confident and an error if you have problems testing reachability.




 -r [-W] { nodename | address | local-address remote-address }
Check the network reachability of the specified host name, IP
address, or a pair of local and remote IP addresses. One or more of
the following strings will be reported to standard output.

Not Reachable The specified nodename/address cannot be
reached using the current network configura-
tion.

Reachable The specified nodename/address can be reached
using the current network configuration.

Transient Connection The specified nodename/address can be reached
via a transient (e.g. PPP) connection.

Connection Required The specified nodename/address can be reached
using the current network configuration but a
connection must first be established. As an
example, this status would be returned for a
dialup connection that was not currently active
but could handle network traffic for the target
system.

Connection Automatic The specified nodename/address can be reached
using the current network configuration but a
connection must first be established. Any
traffic directed to the specified name/address
will initiate the connection.

Local Address The specified nodename/address is one associ-
ated with a network interface on the system.

Directly Reachable Addresss
Network traffic to the specified node-
name/address will not go through a gateway but
is routed directly to one of the interfaces on
the system.

The reachability can also be monitored by specifying the -W (watch)
option. This will result in the current status being reported as
well as the status when/if the network configuration changes.

A zero exit status will be returned when the reachability status is
reported correctly. A non-zero exit status will be returned if
errors are detected with an error reported to standard error.



Since Apple's index of manual pages is a PITA to use, here's a hopefully more stable link to the entire manual page online: https://ss64.com/osx/scutil.html



As a bonus - here is another decent Q&A relating to scutil and checking resolution:
nslookup & dig fail; ping, traceroute, and scutil -r work






share|improve this answer



























  • This really doesn't have the same meaning as the command the question was about. The question centers around checking whether or not you have an internet connection by sending a packet to Google and seeing if you get a response back. Your answer does not send any packets, nor does it say whether or not you have an Internet connection at all. So depending on what this needs to be used for, it could fool the system into failing by assuming an Internet connection is there, but it is really not. Ofcourse in practice [...]

    – jksoegaard
    May 28 at 18:07













  • [...] on home user systems, having google.com reachable usually means that they have an internet connection. But only usually.

    – jksoegaard
    May 28 at 18:09











  • @jksoegaard I so appreciate the comments. I’ll try and mess with this and wireshark to confirm no packets leave in a test with my setup. I’ve never caught scutil being wrong, it I haven’t tried to break it or really validate. Thanks for planting a bug!

    – bmike
    May 28 at 19:30






  • 2





    The way scutil reachability test works is specifically by not sending a packet out, but instead testing whether or not a packet would be sent out if a request was made. It is the same way the Reachability API works on iOS.

    – jksoegaard
    May 28 at 19:36











  • So I really need to edit my answer as part seems incorrect or misleading.

    – bmike
    May 28 at 19:48



















4


















Your problem is that you're using invalid options for the ping command. It seems likely that you have copied a command line intended for use on Linux, and tried to use it unmodified on macOS.



The specific problem here is that Linux uses "-w" to specify timeouts, whereas macOS uses "-t". This means that your command line should instead be this:



ping -q -t1 -c1 google.com &>/dev/null && echo online || echo offline





share|improve this answer



























  • Shouldn't ping -c 3 www.google.com work in any case?

    – nohillside
    May 28 at 15:14











  • Well, he wrote that he tried it on a "different network". That network seems to not have an internet connection, or have only a firewall/filtered internet connection. I have corrected the mistake in the command line he's trying to use, so that's why I did not focus on helping him with his debug commands as well.

    – jksoegaard
    May 28 at 15:32











  • I have tried ping -q -t1 -c1 google.com &>/dev/null && echo online || echo offline, it also comes out as "offline".

    – Zeyan Zhong
    May 28 at 16:02






  • 1





    @ZeyanZhong Try it without redirecting output to /dev/null, so you can actually see what's happening: ping -q -t1 -c1 google.com

    – Gordon Davisson
    May 28 at 17:51











  • @GordonDavisson This is the output: PING google.com (74.125.193.101): 56 data bytes --- google.com ping statistics --- 1 packets transmitted, 0 packets received, 100.0% packet loss

    – Zeyan Zhong
    May 29 at 9:59



















0


















Your command ping -c 3 www.google.com should have produced 3 internet response packets of the type ICMP ECHO REPLY. The ping command sends ECHO packets using the ICMP protocol, and the responses (if any) are ECHO REPLY packets. The curl command on the other hand, sends HTTP packets using the TCP protocol. Since the latter works and the former doesn't, there is probably something between your machine and www.google.com that blocks the ICMP protocol. A lot of misconfigured firewalls do this, so that is where I would start looking for the cause.



Blocking ICMP is bad practice since it stops things like Path MTU Discovery from working (MTU = Maximum Transmission Unit size). This stops most traffic from working if the remote MTU is smaller than the local MTU. So it's an extremely bad idea to block ICMP in the firewall.






share|improve this answer



































    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5


















    I prefer to use the system configuration utility tool to test for reachability instead of using ping / host / nslookup or another proxy for determining if a network entity is or is not reachable.



    scutil -r google.com
    Reachable


    The benefits of this are that if you have VPN connections, dial up, modem, or a routing conflict, this will actually test that you can reach the device and not just resolve the cached host name, etc... in my experience. (also, it's a lot harder to mess up the indirection, files, logic and you get a direct answer back in English)



    Like all good command line tools, it returns 0 to let you know the answer it provides is confident and an error if you have problems testing reachability.




     -r [-W] { nodename | address | local-address remote-address }
    Check the network reachability of the specified host name, IP
    address, or a pair of local and remote IP addresses. One or more of
    the following strings will be reported to standard output.

    Not Reachable The specified nodename/address cannot be
    reached using the current network configura-
    tion.

    Reachable The specified nodename/address can be reached
    using the current network configuration.

    Transient Connection The specified nodename/address can be reached
    via a transient (e.g. PPP) connection.

    Connection Required The specified nodename/address can be reached
    using the current network configuration but a
    connection must first be established. As an
    example, this status would be returned for a
    dialup connection that was not currently active
    but could handle network traffic for the target
    system.

    Connection Automatic The specified nodename/address can be reached
    using the current network configuration but a
    connection must first be established. Any
    traffic directed to the specified name/address
    will initiate the connection.

    Local Address The specified nodename/address is one associ-
    ated with a network interface on the system.

    Directly Reachable Addresss
    Network traffic to the specified node-
    name/address will not go through a gateway but
    is routed directly to one of the interfaces on
    the system.

    The reachability can also be monitored by specifying the -W (watch)
    option. This will result in the current status being reported as
    well as the status when/if the network configuration changes.

    A zero exit status will be returned when the reachability status is
    reported correctly. A non-zero exit status will be returned if
    errors are detected with an error reported to standard error.



    Since Apple's index of manual pages is a PITA to use, here's a hopefully more stable link to the entire manual page online: https://ss64.com/osx/scutil.html



    As a bonus - here is another decent Q&A relating to scutil and checking resolution:
    nslookup & dig fail; ping, traceroute, and scutil -r work






    share|improve this answer



























    • This really doesn't have the same meaning as the command the question was about. The question centers around checking whether or not you have an internet connection by sending a packet to Google and seeing if you get a response back. Your answer does not send any packets, nor does it say whether or not you have an Internet connection at all. So depending on what this needs to be used for, it could fool the system into failing by assuming an Internet connection is there, but it is really not. Ofcourse in practice [...]

      – jksoegaard
      May 28 at 18:07













    • [...] on home user systems, having google.com reachable usually means that they have an internet connection. But only usually.

      – jksoegaard
      May 28 at 18:09











    • @jksoegaard I so appreciate the comments. I’ll try and mess with this and wireshark to confirm no packets leave in a test with my setup. I’ve never caught scutil being wrong, it I haven’t tried to break it or really validate. Thanks for planting a bug!

      – bmike
      May 28 at 19:30






    • 2





      The way scutil reachability test works is specifically by not sending a packet out, but instead testing whether or not a packet would be sent out if a request was made. It is the same way the Reachability API works on iOS.

      – jksoegaard
      May 28 at 19:36











    • So I really need to edit my answer as part seems incorrect or misleading.

      – bmike
      May 28 at 19:48
















    5


















    I prefer to use the system configuration utility tool to test for reachability instead of using ping / host / nslookup or another proxy for determining if a network entity is or is not reachable.



    scutil -r google.com
    Reachable


    The benefits of this are that if you have VPN connections, dial up, modem, or a routing conflict, this will actually test that you can reach the device and not just resolve the cached host name, etc... in my experience. (also, it's a lot harder to mess up the indirection, files, logic and you get a direct answer back in English)



    Like all good command line tools, it returns 0 to let you know the answer it provides is confident and an error if you have problems testing reachability.




     -r [-W] { nodename | address | local-address remote-address }
    Check the network reachability of the specified host name, IP
    address, or a pair of local and remote IP addresses. One or more of
    the following strings will be reported to standard output.

    Not Reachable The specified nodename/address cannot be
    reached using the current network configura-
    tion.

    Reachable The specified nodename/address can be reached
    using the current network configuration.

    Transient Connection The specified nodename/address can be reached
    via a transient (e.g. PPP) connection.

    Connection Required The specified nodename/address can be reached
    using the current network configuration but a
    connection must first be established. As an
    example, this status would be returned for a
    dialup connection that was not currently active
    but could handle network traffic for the target
    system.

    Connection Automatic The specified nodename/address can be reached
    using the current network configuration but a
    connection must first be established. Any
    traffic directed to the specified name/address
    will initiate the connection.

    Local Address The specified nodename/address is one associ-
    ated with a network interface on the system.

    Directly Reachable Addresss
    Network traffic to the specified node-
    name/address will not go through a gateway but
    is routed directly to one of the interfaces on
    the system.

    The reachability can also be monitored by specifying the -W (watch)
    option. This will result in the current status being reported as
    well as the status when/if the network configuration changes.

    A zero exit status will be returned when the reachability status is
    reported correctly. A non-zero exit status will be returned if
    errors are detected with an error reported to standard error.



    Since Apple's index of manual pages is a PITA to use, here's a hopefully more stable link to the entire manual page online: https://ss64.com/osx/scutil.html



    As a bonus - here is another decent Q&A relating to scutil and checking resolution:
    nslookup & dig fail; ping, traceroute, and scutil -r work






    share|improve this answer



























    • This really doesn't have the same meaning as the command the question was about. The question centers around checking whether or not you have an internet connection by sending a packet to Google and seeing if you get a response back. Your answer does not send any packets, nor does it say whether or not you have an Internet connection at all. So depending on what this needs to be used for, it could fool the system into failing by assuming an Internet connection is there, but it is really not. Ofcourse in practice [...]

      – jksoegaard
      May 28 at 18:07













    • [...] on home user systems, having google.com reachable usually means that they have an internet connection. But only usually.

      – jksoegaard
      May 28 at 18:09











    • @jksoegaard I so appreciate the comments. I’ll try and mess with this and wireshark to confirm no packets leave in a test with my setup. I’ve never caught scutil being wrong, it I haven’t tried to break it or really validate. Thanks for planting a bug!

      – bmike
      May 28 at 19:30






    • 2





      The way scutil reachability test works is specifically by not sending a packet out, but instead testing whether or not a packet would be sent out if a request was made. It is the same way the Reachability API works on iOS.

      – jksoegaard
      May 28 at 19:36











    • So I really need to edit my answer as part seems incorrect or misleading.

      – bmike
      May 28 at 19:48














    5














    5










    5









    I prefer to use the system configuration utility tool to test for reachability instead of using ping / host / nslookup or another proxy for determining if a network entity is or is not reachable.



    scutil -r google.com
    Reachable


    The benefits of this are that if you have VPN connections, dial up, modem, or a routing conflict, this will actually test that you can reach the device and not just resolve the cached host name, etc... in my experience. (also, it's a lot harder to mess up the indirection, files, logic and you get a direct answer back in English)



    Like all good command line tools, it returns 0 to let you know the answer it provides is confident and an error if you have problems testing reachability.




     -r [-W] { nodename | address | local-address remote-address }
    Check the network reachability of the specified host name, IP
    address, or a pair of local and remote IP addresses. One or more of
    the following strings will be reported to standard output.

    Not Reachable The specified nodename/address cannot be
    reached using the current network configura-
    tion.

    Reachable The specified nodename/address can be reached
    using the current network configuration.

    Transient Connection The specified nodename/address can be reached
    via a transient (e.g. PPP) connection.

    Connection Required The specified nodename/address can be reached
    using the current network configuration but a
    connection must first be established. As an
    example, this status would be returned for a
    dialup connection that was not currently active
    but could handle network traffic for the target
    system.

    Connection Automatic The specified nodename/address can be reached
    using the current network configuration but a
    connection must first be established. Any
    traffic directed to the specified name/address
    will initiate the connection.

    Local Address The specified nodename/address is one associ-
    ated with a network interface on the system.

    Directly Reachable Addresss
    Network traffic to the specified node-
    name/address will not go through a gateway but
    is routed directly to one of the interfaces on
    the system.

    The reachability can also be monitored by specifying the -W (watch)
    option. This will result in the current status being reported as
    well as the status when/if the network configuration changes.

    A zero exit status will be returned when the reachability status is
    reported correctly. A non-zero exit status will be returned if
    errors are detected with an error reported to standard error.



    Since Apple's index of manual pages is a PITA to use, here's a hopefully more stable link to the entire manual page online: https://ss64.com/osx/scutil.html



    As a bonus - here is another decent Q&A relating to scutil and checking resolution:
    nslookup & dig fail; ping, traceroute, and scutil -r work






    share|improve this answer














    I prefer to use the system configuration utility tool to test for reachability instead of using ping / host / nslookup or another proxy for determining if a network entity is or is not reachable.



    scutil -r google.com
    Reachable


    The benefits of this are that if you have VPN connections, dial up, modem, or a routing conflict, this will actually test that you can reach the device and not just resolve the cached host name, etc... in my experience. (also, it's a lot harder to mess up the indirection, files, logic and you get a direct answer back in English)



    Like all good command line tools, it returns 0 to let you know the answer it provides is confident and an error if you have problems testing reachability.




     -r [-W] { nodename | address | local-address remote-address }
    Check the network reachability of the specified host name, IP
    address, or a pair of local and remote IP addresses. One or more of
    the following strings will be reported to standard output.

    Not Reachable The specified nodename/address cannot be
    reached using the current network configura-
    tion.

    Reachable The specified nodename/address can be reached
    using the current network configuration.

    Transient Connection The specified nodename/address can be reached
    via a transient (e.g. PPP) connection.

    Connection Required The specified nodename/address can be reached
    using the current network configuration but a
    connection must first be established. As an
    example, this status would be returned for a
    dialup connection that was not currently active
    but could handle network traffic for the target
    system.

    Connection Automatic The specified nodename/address can be reached
    using the current network configuration but a
    connection must first be established. Any
    traffic directed to the specified name/address
    will initiate the connection.

    Local Address The specified nodename/address is one associ-
    ated with a network interface on the system.

    Directly Reachable Addresss
    Network traffic to the specified node-
    name/address will not go through a gateway but
    is routed directly to one of the interfaces on
    the system.

    The reachability can also be monitored by specifying the -W (watch)
    option. This will result in the current status being reported as
    well as the status when/if the network configuration changes.

    A zero exit status will be returned when the reachability status is
    reported correctly. A non-zero exit status will be returned if
    errors are detected with an error reported to standard error.



    Since Apple's index of manual pages is a PITA to use, here's a hopefully more stable link to the entire manual page online: https://ss64.com/osx/scutil.html



    As a bonus - here is another decent Q&A relating to scutil and checking resolution:
    nslookup & dig fail; ping, traceroute, and scutil -r work







    share|improve this answer













    share|improve this answer




    share|improve this answer










    answered May 28 at 17:34









    bmikebmike

    170k47 gold badges311 silver badges669 bronze badges




    170k47 gold badges311 silver badges669 bronze badges
















    • This really doesn't have the same meaning as the command the question was about. The question centers around checking whether or not you have an internet connection by sending a packet to Google and seeing if you get a response back. Your answer does not send any packets, nor does it say whether or not you have an Internet connection at all. So depending on what this needs to be used for, it could fool the system into failing by assuming an Internet connection is there, but it is really not. Ofcourse in practice [...]

      – jksoegaard
      May 28 at 18:07













    • [...] on home user systems, having google.com reachable usually means that they have an internet connection. But only usually.

      – jksoegaard
      May 28 at 18:09











    • @jksoegaard I so appreciate the comments. I’ll try and mess with this and wireshark to confirm no packets leave in a test with my setup. I’ve never caught scutil being wrong, it I haven’t tried to break it or really validate. Thanks for planting a bug!

      – bmike
      May 28 at 19:30






    • 2





      The way scutil reachability test works is specifically by not sending a packet out, but instead testing whether or not a packet would be sent out if a request was made. It is the same way the Reachability API works on iOS.

      – jksoegaard
      May 28 at 19:36











    • So I really need to edit my answer as part seems incorrect or misleading.

      – bmike
      May 28 at 19:48



















    • This really doesn't have the same meaning as the command the question was about. The question centers around checking whether or not you have an internet connection by sending a packet to Google and seeing if you get a response back. Your answer does not send any packets, nor does it say whether or not you have an Internet connection at all. So depending on what this needs to be used for, it could fool the system into failing by assuming an Internet connection is there, but it is really not. Ofcourse in practice [...]

      – jksoegaard
      May 28 at 18:07













    • [...] on home user systems, having google.com reachable usually means that they have an internet connection. But only usually.

      – jksoegaard
      May 28 at 18:09











    • @jksoegaard I so appreciate the comments. I’ll try and mess with this and wireshark to confirm no packets leave in a test with my setup. I’ve never caught scutil being wrong, it I haven’t tried to break it or really validate. Thanks for planting a bug!

      – bmike
      May 28 at 19:30






    • 2





      The way scutil reachability test works is specifically by not sending a packet out, but instead testing whether or not a packet would be sent out if a request was made. It is the same way the Reachability API works on iOS.

      – jksoegaard
      May 28 at 19:36











    • So I really need to edit my answer as part seems incorrect or misleading.

      – bmike
      May 28 at 19:48

















    This really doesn't have the same meaning as the command the question was about. The question centers around checking whether or not you have an internet connection by sending a packet to Google and seeing if you get a response back. Your answer does not send any packets, nor does it say whether or not you have an Internet connection at all. So depending on what this needs to be used for, it could fool the system into failing by assuming an Internet connection is there, but it is really not. Ofcourse in practice [...]

    – jksoegaard
    May 28 at 18:07







    This really doesn't have the same meaning as the command the question was about. The question centers around checking whether or not you have an internet connection by sending a packet to Google and seeing if you get a response back. Your answer does not send any packets, nor does it say whether or not you have an Internet connection at all. So depending on what this needs to be used for, it could fool the system into failing by assuming an Internet connection is there, but it is really not. Ofcourse in practice [...]

    – jksoegaard
    May 28 at 18:07















    [...] on home user systems, having google.com reachable usually means that they have an internet connection. But only usually.

    – jksoegaard
    May 28 at 18:09





    [...] on home user systems, having google.com reachable usually means that they have an internet connection. But only usually.

    – jksoegaard
    May 28 at 18:09













    @jksoegaard I so appreciate the comments. I’ll try and mess with this and wireshark to confirm no packets leave in a test with my setup. I’ve never caught scutil being wrong, it I haven’t tried to break it or really validate. Thanks for planting a bug!

    – bmike
    May 28 at 19:30





    @jksoegaard I so appreciate the comments. I’ll try and mess with this and wireshark to confirm no packets leave in a test with my setup. I’ve never caught scutil being wrong, it I haven’t tried to break it or really validate. Thanks for planting a bug!

    – bmike
    May 28 at 19:30




    2




    2





    The way scutil reachability test works is specifically by not sending a packet out, but instead testing whether or not a packet would be sent out if a request was made. It is the same way the Reachability API works on iOS.

    – jksoegaard
    May 28 at 19:36





    The way scutil reachability test works is specifically by not sending a packet out, but instead testing whether or not a packet would be sent out if a request was made. It is the same way the Reachability API works on iOS.

    – jksoegaard
    May 28 at 19:36













    So I really need to edit my answer as part seems incorrect or misleading.

    – bmike
    May 28 at 19:48





    So I really need to edit my answer as part seems incorrect or misleading.

    – bmike
    May 28 at 19:48













    4


















    Your problem is that you're using invalid options for the ping command. It seems likely that you have copied a command line intended for use on Linux, and tried to use it unmodified on macOS.



    The specific problem here is that Linux uses "-w" to specify timeouts, whereas macOS uses "-t". This means that your command line should instead be this:



    ping -q -t1 -c1 google.com &>/dev/null && echo online || echo offline





    share|improve this answer



























    • Shouldn't ping -c 3 www.google.com work in any case?

      – nohillside
      May 28 at 15:14











    • Well, he wrote that he tried it on a "different network". That network seems to not have an internet connection, or have only a firewall/filtered internet connection. I have corrected the mistake in the command line he's trying to use, so that's why I did not focus on helping him with his debug commands as well.

      – jksoegaard
      May 28 at 15:32











    • I have tried ping -q -t1 -c1 google.com &>/dev/null && echo online || echo offline, it also comes out as "offline".

      – Zeyan Zhong
      May 28 at 16:02






    • 1





      @ZeyanZhong Try it without redirecting output to /dev/null, so you can actually see what's happening: ping -q -t1 -c1 google.com

      – Gordon Davisson
      May 28 at 17:51











    • @GordonDavisson This is the output: PING google.com (74.125.193.101): 56 data bytes --- google.com ping statistics --- 1 packets transmitted, 0 packets received, 100.0% packet loss

      – Zeyan Zhong
      May 29 at 9:59
















    4


















    Your problem is that you're using invalid options for the ping command. It seems likely that you have copied a command line intended for use on Linux, and tried to use it unmodified on macOS.



    The specific problem here is that Linux uses "-w" to specify timeouts, whereas macOS uses "-t". This means that your command line should instead be this:



    ping -q -t1 -c1 google.com &>/dev/null && echo online || echo offline





    share|improve this answer



























    • Shouldn't ping -c 3 www.google.com work in any case?

      – nohillside
      May 28 at 15:14











    • Well, he wrote that he tried it on a "different network". That network seems to not have an internet connection, or have only a firewall/filtered internet connection. I have corrected the mistake in the command line he's trying to use, so that's why I did not focus on helping him with his debug commands as well.

      – jksoegaard
      May 28 at 15:32











    • I have tried ping -q -t1 -c1 google.com &>/dev/null && echo online || echo offline, it also comes out as "offline".

      – Zeyan Zhong
      May 28 at 16:02






    • 1





      @ZeyanZhong Try it without redirecting output to /dev/null, so you can actually see what's happening: ping -q -t1 -c1 google.com

      – Gordon Davisson
      May 28 at 17:51











    • @GordonDavisson This is the output: PING google.com (74.125.193.101): 56 data bytes --- google.com ping statistics --- 1 packets transmitted, 0 packets received, 100.0% packet loss

      – Zeyan Zhong
      May 29 at 9:59














    4














    4










    4









    Your problem is that you're using invalid options for the ping command. It seems likely that you have copied a command line intended for use on Linux, and tried to use it unmodified on macOS.



    The specific problem here is that Linux uses "-w" to specify timeouts, whereas macOS uses "-t". This means that your command line should instead be this:



    ping -q -t1 -c1 google.com &>/dev/null && echo online || echo offline





    share|improve this answer














    Your problem is that you're using invalid options for the ping command. It seems likely that you have copied a command line intended for use on Linux, and tried to use it unmodified on macOS.



    The specific problem here is that Linux uses "-w" to specify timeouts, whereas macOS uses "-t". This means that your command line should instead be this:



    ping -q -t1 -c1 google.com &>/dev/null && echo online || echo offline






    share|improve this answer













    share|improve this answer




    share|improve this answer










    answered May 28 at 15:07









    jksoegaardjksoegaard

    27.9k1 gold badge35 silver badges67 bronze badges




    27.9k1 gold badge35 silver badges67 bronze badges
















    • Shouldn't ping -c 3 www.google.com work in any case?

      – nohillside
      May 28 at 15:14











    • Well, he wrote that he tried it on a "different network". That network seems to not have an internet connection, or have only a firewall/filtered internet connection. I have corrected the mistake in the command line he's trying to use, so that's why I did not focus on helping him with his debug commands as well.

      – jksoegaard
      May 28 at 15:32











    • I have tried ping -q -t1 -c1 google.com &>/dev/null && echo online || echo offline, it also comes out as "offline".

      – Zeyan Zhong
      May 28 at 16:02






    • 1





      @ZeyanZhong Try it without redirecting output to /dev/null, so you can actually see what's happening: ping -q -t1 -c1 google.com

      – Gordon Davisson
      May 28 at 17:51











    • @GordonDavisson This is the output: PING google.com (74.125.193.101): 56 data bytes --- google.com ping statistics --- 1 packets transmitted, 0 packets received, 100.0% packet loss

      – Zeyan Zhong
      May 29 at 9:59



















    • Shouldn't ping -c 3 www.google.com work in any case?

      – nohillside
      May 28 at 15:14











    • Well, he wrote that he tried it on a "different network". That network seems to not have an internet connection, or have only a firewall/filtered internet connection. I have corrected the mistake in the command line he's trying to use, so that's why I did not focus on helping him with his debug commands as well.

      – jksoegaard
      May 28 at 15:32











    • I have tried ping -q -t1 -c1 google.com &>/dev/null && echo online || echo offline, it also comes out as "offline".

      – Zeyan Zhong
      May 28 at 16:02






    • 1





      @ZeyanZhong Try it without redirecting output to /dev/null, so you can actually see what's happening: ping -q -t1 -c1 google.com

      – Gordon Davisson
      May 28 at 17:51











    • @GordonDavisson This is the output: PING google.com (74.125.193.101): 56 data bytes --- google.com ping statistics --- 1 packets transmitted, 0 packets received, 100.0% packet loss

      – Zeyan Zhong
      May 29 at 9:59

















    Shouldn't ping -c 3 www.google.com work in any case?

    – nohillside
    May 28 at 15:14





    Shouldn't ping -c 3 www.google.com work in any case?

    – nohillside
    May 28 at 15:14













    Well, he wrote that he tried it on a "different network". That network seems to not have an internet connection, or have only a firewall/filtered internet connection. I have corrected the mistake in the command line he's trying to use, so that's why I did not focus on helping him with his debug commands as well.

    – jksoegaard
    May 28 at 15:32





    Well, he wrote that he tried it on a "different network". That network seems to not have an internet connection, or have only a firewall/filtered internet connection. I have corrected the mistake in the command line he's trying to use, so that's why I did not focus on helping him with his debug commands as well.

    – jksoegaard
    May 28 at 15:32













    I have tried ping -q -t1 -c1 google.com &>/dev/null && echo online || echo offline, it also comes out as "offline".

    – Zeyan Zhong
    May 28 at 16:02





    I have tried ping -q -t1 -c1 google.com &>/dev/null && echo online || echo offline, it also comes out as "offline".

    – Zeyan Zhong
    May 28 at 16:02




    1




    1





    @ZeyanZhong Try it without redirecting output to /dev/null, so you can actually see what's happening: ping -q -t1 -c1 google.com

    – Gordon Davisson
    May 28 at 17:51





    @ZeyanZhong Try it without redirecting output to /dev/null, so you can actually see what's happening: ping -q -t1 -c1 google.com

    – Gordon Davisson
    May 28 at 17:51













    @GordonDavisson This is the output: PING google.com (74.125.193.101): 56 data bytes --- google.com ping statistics --- 1 packets transmitted, 0 packets received, 100.0% packet loss

    – Zeyan Zhong
    May 29 at 9:59





    @GordonDavisson This is the output: PING google.com (74.125.193.101): 56 data bytes --- google.com ping statistics --- 1 packets transmitted, 0 packets received, 100.0% packet loss

    – Zeyan Zhong
    May 29 at 9:59











    0


















    Your command ping -c 3 www.google.com should have produced 3 internet response packets of the type ICMP ECHO REPLY. The ping command sends ECHO packets using the ICMP protocol, and the responses (if any) are ECHO REPLY packets. The curl command on the other hand, sends HTTP packets using the TCP protocol. Since the latter works and the former doesn't, there is probably something between your machine and www.google.com that blocks the ICMP protocol. A lot of misconfigured firewalls do this, so that is where I would start looking for the cause.



    Blocking ICMP is bad practice since it stops things like Path MTU Discovery from working (MTU = Maximum Transmission Unit size). This stops most traffic from working if the remote MTU is smaller than the local MTU. So it's an extremely bad idea to block ICMP in the firewall.






    share|improve this answer































      0


















      Your command ping -c 3 www.google.com should have produced 3 internet response packets of the type ICMP ECHO REPLY. The ping command sends ECHO packets using the ICMP protocol, and the responses (if any) are ECHO REPLY packets. The curl command on the other hand, sends HTTP packets using the TCP protocol. Since the latter works and the former doesn't, there is probably something between your machine and www.google.com that blocks the ICMP protocol. A lot of misconfigured firewalls do this, so that is where I would start looking for the cause.



      Blocking ICMP is bad practice since it stops things like Path MTU Discovery from working (MTU = Maximum Transmission Unit size). This stops most traffic from working if the remote MTU is smaller than the local MTU. So it's an extremely bad idea to block ICMP in the firewall.






      share|improve this answer





























        0














        0










        0









        Your command ping -c 3 www.google.com should have produced 3 internet response packets of the type ICMP ECHO REPLY. The ping command sends ECHO packets using the ICMP protocol, and the responses (if any) are ECHO REPLY packets. The curl command on the other hand, sends HTTP packets using the TCP protocol. Since the latter works and the former doesn't, there is probably something between your machine and www.google.com that blocks the ICMP protocol. A lot of misconfigured firewalls do this, so that is where I would start looking for the cause.



        Blocking ICMP is bad practice since it stops things like Path MTU Discovery from working (MTU = Maximum Transmission Unit size). This stops most traffic from working if the remote MTU is smaller than the local MTU. So it's an extremely bad idea to block ICMP in the firewall.






        share|improve this answer














        Your command ping -c 3 www.google.com should have produced 3 internet response packets of the type ICMP ECHO REPLY. The ping command sends ECHO packets using the ICMP protocol, and the responses (if any) are ECHO REPLY packets. The curl command on the other hand, sends HTTP packets using the TCP protocol. Since the latter works and the former doesn't, there is probably something between your machine and www.google.com that blocks the ICMP protocol. A lot of misconfigured firewalls do this, so that is where I would start looking for the cause.



        Blocking ICMP is bad practice since it stops things like Path MTU Discovery from working (MTU = Maximum Transmission Unit size). This stops most traffic from working if the remote MTU is smaller than the local MTU. So it's an extremely bad idea to block ICMP in the firewall.







        share|improve this answer













        share|improve this answer




        share|improve this answer










        answered May 29 at 18:12









        Cuspy CodeCuspy Code

        101




        101


















            Popular posts from this blog

            Færeyskur hestur Heimild | Tengill | Tilvísanir | LeiðsagnarvalRossið - síða um færeyska hrossið á færeyskuGott ár hjá færeyska hestinum

            He _____ here since 1970 . Answer needed [closed]What does “since he was so high” mean?Meaning of “catch birds for”?How do I ensure “since” takes the meaning I want?“Who cares here” meaningWhat does “right round toward” mean?the time tense (had now been detected)What does the phrase “ring around the roses” mean here?Correct usage of “visited upon”Meaning of “foiled rail sabotage bid”It was the third time I had gone to Rome or It is the third time I had been to Rome

            Slayer Innehåll Historia | Stil, komposition och lyrik | Bandets betydelse och framgångar | Sidoprojekt och samarbeten | Kontroverser | Medlemmar | Utmärkelser och nomineringar | Turnéer och festivaler | Diskografi | Referenser | Externa länkar | Navigeringsmenywww.slayer.net”Metal Massacre vol. 1””Metal Massacre vol. 3””Metal Massacre Volume III””Show No Mercy””Haunting the Chapel””Live Undead””Hell Awaits””Reign in Blood””Reign in Blood””Gold & Platinum – Reign in Blood””Golden Gods Awards Winners”originalet”Kerrang! Hall Of Fame””Slayer Looks Back On 37-Year Career In New Video Series: Part Two””South of Heaven””Gold & Platinum – South of Heaven””Seasons in the Abyss””Gold & Platinum - Seasons in the Abyss””Divine Intervention””Divine Intervention - Release group by Slayer””Gold & Platinum - Divine Intervention””Live Intrusion””Undisputed Attitude””Abolish Government/Superficial Love””Release “Slatanic Slaughter: A Tribute to Slayer” by Various Artists””Diabolus in Musica””Soundtrack to the Apocalypse””God Hates Us All””Systematic - Relationships””War at the Warfield””Gold & Platinum - War at the Warfield””Soundtrack to the Apocalypse””Gold & Platinum - Still Reigning””Metallica, Slayer, Iron Mauden Among Winners At Metal Hammer Awards””Eternal Pyre””Eternal Pyre - Slayer release group””Eternal Pyre””Metal Storm Awards 2006””Kerrang! Hall Of Fame””Slayer Wins 'Best Metal' Grammy Award””Slayer Guitarist Jeff Hanneman Dies””Bullet-For My Valentine booed at Metal Hammer Golden Gods Awards””Unholy Aliance””The End Of Slayer?””Slayer: We Could Thrash Out Two More Albums If We're Fast Enough...””'The Unholy Alliance: Chapter III' UK Dates Added”originalet”Megadeth And Slayer To Co-Headline 'Canadian Carnage' Trek”originalet”World Painted Blood””Release “World Painted Blood” by Slayer””Metallica Heading To Cinemas””Slayer, Megadeth To Join Forces For 'European Carnage' Tour - Dec. 18, 2010”originalet”Slayer's Hanneman Contracts Acute Infection; Band To Bring In Guest Guitarist””Cannibal Corpse's Pat O'Brien Will Step In As Slayer's Guest Guitarist”originalet”Slayer’s Jeff Hanneman Dead at 49””Dave Lombardo Says He Made Only $67,000 In 2011 While Touring With Slayer””Slayer: We Do Not Agree With Dave Lombardo's Substance Or Timeline Of Events””Slayer Welcomes Drummer Paul Bostaph Back To The Fold””Slayer Hope to Unveil Never-Before-Heard Jeff Hanneman Material on Next Album””Slayer Debut New Song 'Implode' During Surprise Golden Gods Appearance””Release group Repentless by Slayer””Repentless - Slayer - Credits””Slayer””Metal Storm Awards 2015””Slayer - to release comic book "Repentless #1"””Slayer To Release 'Repentless' 6.66" Vinyl Box Set””BREAKING NEWS: Slayer Announce Farewell Tour””Slayer Recruit Lamb of God, Anthrax, Behemoth + Testament for Final Tour””Slayer lägger ner efter 37 år””Slayer Announces Second North American Leg Of 'Final' Tour””Final World Tour””Slayer Announces Final European Tour With Lamb of God, Anthrax And Obituary””Slayer To Tour Europe With Lamb of God, Anthrax And Obituary””Slayer To Play 'Last French Show Ever' At Next Year's Hellfst””Slayer's Final World Tour Will Extend Into 2019””Death Angel's Rob Cavestany On Slayer's 'Farewell' Tour: 'Some Of Us Could See This Coming'””Testament Has No Plans To Retire Anytime Soon, Says Chuck Billy””Anthrax's Scott Ian On Slayer's 'Farewell' Tour Plans: 'I Was Surprised And I Wasn't Surprised'””Slayer””Slayer's Morbid Schlock””Review/Rock; For Slayer, the Mania Is the Message””Slayer - Biography””Slayer - Reign In Blood”originalet”Dave Lombardo””An exclusive oral history of Slayer”originalet”Exclusive! Interview With Slayer Guitarist Jeff Hanneman”originalet”Thinking Out Loud: Slayer's Kerry King on hair metal, Satan and being polite””Slayer Lyrics””Slayer - Biography””Most influential artists for extreme metal music””Slayer - Reign in Blood””Slayer guitarist Jeff Hanneman dies aged 49””Slatanic Slaughter: A Tribute to Slayer””Gateway to Hell: A Tribute to Slayer””Covered In Blood””Slayer: The Origins of Thrash in San Francisco, CA.””Why They Rule - #6 Slayer”originalet”Guitar World's 100 Greatest Heavy Metal Guitarists Of All Time”originalet”The fans have spoken: Slayer comes out on top in readers' polls”originalet”Tribute to Jeff Hanneman (1964-2013)””Lamb Of God Frontman: We Sound Like A Slayer Rip-Off””BEHEMOTH Frontman Pays Tribute To SLAYER's JEFF HANNEMAN””Slayer, Hatebreed Doing Double Duty On This Year's Ozzfest””System of a Down””Lacuna Coil’s Andrea Ferro Talks Influences, Skateboarding, Band Origins + More””Slayer - Reign in Blood””Into The Lungs of Hell””Slayer rules - en utställning om fans””Slayer and Their Fans Slashed Through a No-Holds-Barred Night at Gas Monkey””Home””Slayer””Gold & Platinum - The Big 4 Live from Sofia, Bulgaria””Exclusive! Interview With Slayer Guitarist Kerry King””2008-02-23: Wiltern, Los Angeles, CA, USA””Slayer's Kerry King To Perform With Megadeth Tonight! - Oct. 21, 2010”originalet”Dave Lombardo - Biography”Slayer Case DismissedArkiveradUltimate Classic Rock: Slayer guitarist Jeff Hanneman dead at 49.”Slayer: "We could never do any thing like Some Kind Of Monster..."””Cannibal Corpse'S Pat O'Brien Will Step In As Slayer'S Guest Guitarist | The Official Slayer Site”originalet”Slayer Wins 'Best Metal' Grammy Award””Slayer Guitarist Jeff Hanneman Dies””Kerrang! Awards 2006 Blog: Kerrang! Hall Of Fame””Kerrang! Awards 2013: Kerrang! Legend”originalet”Metallica, Slayer, Iron Maien Among Winners At Metal Hammer Awards””Metal Hammer Golden Gods Awards””Bullet For My Valentine Booed At Metal Hammer Golden Gods Awards””Metal Storm Awards 2006””Metal Storm Awards 2015””Slayer's Concert History””Slayer - Relationships””Slayer - Releases”Slayers officiella webbplatsSlayer på MusicBrainzOfficiell webbplatsSlayerSlayerr1373445760000 0001 1540 47353068615-5086262726cb13906545x(data)6033143kn20030215029