I need to get the name of the network interface (e.g. eth0, wlan0) that is the currently-active one, the one sending and receiving traffic at the moment. When it's connected to WiFi, it would be wlan0 but when it's connected directly it would be eth0. Or something else, depending on the network devices on the system and which one is active. How can I find this out?
Open a terminal and run the command:
The active interface will have an IP address and transmitted and received bytes. Here is an example:
Check if the ethernet interface is used:
Verify that the wireless interface is used:
So, obviously, internet traffic is currently routed through wlan0, my wireless interface.
It is possible to have both ethernet and wireless connected simultaneously. Normally, Network Manager will disallow it, preferring ethernet over wireless because it is generally faster and more secure. If one wanted to use ethernet for the LAN and wireless for the WAN (internet), one would typically remove NM and set all the details manually in /etc/network/interfaces.
No need for
You can have two or more external interfaces with LOWER-UP but generally a bad idea. Here's my laptop with loopback (notice LOWER_UP), down ethernet, wlan0 up and generating a signal, wlan4 (USB wifi) UP but NOT generating a signal, wlan4.mon monitor mode sniffing all stations on BSS (notice LOWER-UP). wlan4.mon does not transmit.
If you want a little more detail try jnettop this tool shows you detailed traffic monitoring in the terminal.
sudo apt-get install jnettop
once installed simply type jnettop in the terminal