When you have two or more interfaces you want to know what is the default interface used to connect outside world. Here are the commands to help you found the default outbound interface and ip address.

To list all your interfaces

ip a

ip route command is part of iproute2 suite of tools for IP management, ip route provides management tools for displaying routes or the routing cache, adding routes, deleting routes, modifying existing routes, and fetching a route and clearing an entire routing table or the routing cache.

Its simulating a request for the specified destination, ip route get causes the routing selection algorithm to be run.

ip route get 8.8.8.8

This will print

8.8.8.8 via 192.168.1.1 dev wlan0  src 192.168.1.101
  cache

In this

192.168.1.1 is gateway ip wlan0 is interface name 192.168.1.101 interface address

To get outbound ip address

ip route get 8.8.8.8 | awk 'NR == 1 {print $NF}'

To get outbound interface name

ip route get 8.8.8.8 | awk 'NR == 1 {print $5}'
SHARE
Previous article Adblock using pi-hole
Next article How to install NodeJS