I'm trying to get the default gateway, using the destination 0.0.0.0
.
I used the command netstat -rn | grep 0.0.0.0
and it returned this list:
Destination Gateway Genmask Flags MSS Window irtt Iface
10.9.9.17 0.0.0.0 255.255.255.255 UH 0 0 0 tun0
133.88.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 133.88.31.70 0.0.0.0 UG 0 0 0 eth0
My goal here is to ping the default gateway using the destination 0.0.0.0
, which is 133.88.31.70
, but this one returns a list because of using grep
.
How do I get the default gateway only? I need it for my Bash script to determine whether the network connection is up or not.
ip route get
lets you pass the host and will do a lookup for you. – Macintosh