Aaron's Blog logo Aaron's Blog

The main NIC will usually have a default route. So:

ip -o -4 route show to default

The NIC:

ip -o -4 route show to default | awk ‘{print $5}’

The gateway:

ip -o -4 route show to default | awk ‘{print $3}’