How do I get the default gateway in Linux given the destination? May 29, 2023 by Tarik You can get the default gateway using ip command like this: IP=$(/sbin/ip route | awk '/default/ { print $3 }') echo $IP