show gateway IP address when performing ifconfig command
Currently, when using the
ifconfigcommand, the following IP addresses are shown: own IP, broadcast and mask.
Is there a way to show the related gateway IP address as well (on the same screen with all the others, not by using 'route' command)?
You can with the
ipcommand, and given that
ifconfigis in the process of being deprecated by most distributions it's now the preferred tool. An example:
$ ip route show 22.214.171.124/28 dev eth0 proto kernel scope link src 126.96.36.199 default via 188.8.131.52 dev eth0
@Mayhem - Too bad "route -n" doesn't work for mac. Now "route -n get default" does work for showing the gateway on mac, but the one you suggested works on linux and not mac.
**For scripting:** `ip route show | sed 's/\(\S\+\s\+\)\?default via \(\S\+\).*/\2/p; d'`
"route -n get default", see here: https://stackoverflow.com/questions/6782658/how-to-get-default-gateway-in-mac-osx