Linux: Detect physical network cable connection
Posted: Thu Jul 28, 2011 3:41 pm
[PROBLEM]
I had a server with several network cards, and it wasn't trivial to figure out which physical RJ45 port belonged to which eth device. Even knowing the individual mac addresses didn't help in this case.
And since it's a server, it's of course running GNU/Linux commandline-only without any GUI.
[SOLUTION]
Simply take a look at the "carrier" file of the network adapter(s) in question in "/sys/class/net".
For example, to figure out the physical cable connection state of "eth0", type:
If the result is "1" it's connected - and "0" if it's not.
I had a server with several network cards, and it wasn't trivial to figure out which physical RJ45 port belonged to which eth device. Even knowing the individual mac addresses didn't help in this case.
And since it's a server, it's of course running GNU/Linux commandline-only without any GUI.
[SOLUTION]
Simply take a look at the "carrier" file of the network adapter(s) in question in "/sys/class/net".
For example, to figure out the physical cable connection state of "eth0", type:
Code: Select all
cat /sys/class/net/eth0/carrier