How to find the gateway IP address in Linux

What command can you use to find the Gateway IP Address (ie. home router address) for eth0 in Linux?

I need to get the IP address from a command line app to use in a shell script.


Solution 1:

To print out only the default gw IP:

route -n | grep 'UG[ \t]' | awk '{print $2}'

To print out route information on all interfaces:

route -n

or

netstat -rn

Solution 2:

ip route show 0.0.0.0/0 dev eth0 | cut -d\  -f3

is my entry :)