How do i get the default gateway in LINUX given the destination?

Posted by Suezy on Stack Overflow See other posts from Stack Overflow or by Suezy
Published on 2009-07-30T05:35:29Z Indexed on 2011/01/02 0:54 UTC
Read the original article Hit count: 245

Filed under:

Good day!

I'm trying to get the default gateway, using the destination 0.0.0.0

i used this command: netstat -rn | grep 0.0.0.0

and it returns 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 destination 0.0.0.0; thus, that is "133.88.31.70"; but this one returns a list because of using 'grep'.

Question is: How do i get the default gateway only? I will need it for my bash script to identify if net connection is up or not.

Any answers will be much appreciated. =)

© Stack Overflow or respective owner

Related posts about gateway