Test connection

2 snippets in Bash & Linux

SHBash & Linux

Test Network Connectivity

SH · Networking
syntax
ping [options] host
example
ping -c 5 google.com
ping -c 3 192.168.1.1
output
64 bytes from 142.250.80.46: icmp_seq=1 ttl=118 time=11.2 ms
--- google.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss

Note -c limits the number of pings (without it, Linux pings forever; macOS defaults to unlimited too). High time values indicate latency; packet loss indicates connectivity problems.

Netcat: Network Swiss Army Knife

SH · Networking
syntax
nc [options] host port
example
nc -zv server.example.com 443
echo 'PING' | nc -w 2 redis.local 6379
nc -l 9090
output
Connection to server.example.com 443 port [tcp/https] succeeded!

Note -z scans without sending data (port check). -v is verbose. -w sets a timeout in seconds. -l listens on a port (useful for quick debugging). Netcat is invaluable for testing whether a port is open from a particular host.