Ubuntu – How to find name of currently-active network interface


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?

Best Answer

Open a terminal and run the command:


The active interface will have an IP address and transmitted and received bytes. Here is an example:

eth0  Link encap:Ethernet  HWaddr xx:a8:6b:fe:06:xx
      inet addr:  Bcast:  Mask:
      inet6 addr: fe80::eea8:6bff:fefe:696/64 Scope:Link
      RX packets:449232 errors:0 dropped:0 overruns:0 frame:0
      TX packets:309483 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:633900275 (633.9 MB)  TX bytes:27944824 (27.9 MB)

Check if the ethernet interface is used:

ping -c3 -I eth0 www.google.com
ping: Warning: source address might be selected on device other than eth0.
PING www.google.com ( from eth0: 56(84) bytes of data.Wi-Fi
From Think410 ( icmp_seq=1 Destination Host Unreachable
From Think410 ( icmp_seq=2 Destination Host Unreachable
From Think410 ( icmp_seq=3 Destination Host Unreachable

Verify that the wireless interface is used:

ping -c3 -I wlan0 www.google.com
PING www.google.com ( from wlan0: 56(84) bytes of data.
64 bytes from iad23s17-in-f20.1e100.net ( icmp_seq=1 ttl=50 time=37.5 ms
64 bytes from iad23s17-in-f20.1e100.net ( icmp_seq=2 ttl=50 time=36.8 ms
64 bytes from iad23s17-in-f20.1e100.net ( icmp_seq=3 ttl=50 time=35.9 ms

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.

Related Question