Linux: Detect physical network cable connection

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....
Post Reply
User avatar
^rooker
Site Admin
Posts: 1483
Joined: Fri Aug 29, 2003 8:39 pm

Linux: Detect physical network cable connection

Post by ^rooker »

[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:

Code: Select all

cat /sys/class/net/eth0/carrier
If the result is "1" it's connected - and "0" if it's not.
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply