sds
sds

Reputation: 60004

How do I find out the gateway IP in shell?

How do I find out the IP address of the gateway using unix bash command line?

While usually it will be 192.168.1.1, it might occasionally be 192.168.0.1 or something else depending on what router I connect to.

Upvotes: 1

Views: 3055

Answers (1)

sds
sds

Reputation: 60004

Install ip on mac

brew install iproute2mac

Get the gateway IP address

ip route show | grep default | cut -d' ' -f 3

Check internet connection

for h in $(ip route show|grep default|cut -d' ' -f 3) google.com; do
  echo
  echo ===$h===
  ping -c 5 $h || break
done

Upvotes: 2

Related Questions