Can't connect to Internet in bash using Mac OS
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&amp;A relating to scutil and checking resolution: 
nslookup &amp; dig fail; ping, traceroute, and scutil -r work