How do I find the network interface that's connected to the Internet?
This machine could typically be connected via {eth0,eth1,usb0,wlan0}
. The best I could think of is:
sudo route | grep default | awk '{print $NF}'
Update: My favoured solution is:
$(for i in `ip r`; do echo $i; done | grep -A 1 dev | tail -n1)
i think it will be better to use iproute2 instead old and bad-working route.
route -n | awk '$1 ~ /0.0.0.0/ {print $NF}'
will give you interface with default gateway which is most probably the interface through which you are accessing internet.