How To Find Out The Connected State Of A Network Cable In Linux

  In this brief tutorial, we are going to learn how to find out whether the network cable is connected or not with the Network interface card. You can directly go and check the physical network slot on the back of your system to find if the cable is connected or not, but it is not necessary though. We can do this using simple commands from where you are. There could be plenty of ways to do this. However, I find the following methods are way easier than others. If you ever wondered how to find out the connected state of a network cable, here is how you can do it on Unix-like operating systems.

  Also read – How to configure Static IP address in Linux and Unix

  To find out the connected state of a network cable in Linux, just run:

  $ cat /sys/class/net/enp5s0/carrier

  Sample output:

  1

  If you got output as “1” (Number one), It means that the network cable is connected with the network card.

  Also, you can do this with the following command too:

  $ cat /sys/class/net/enp5s0/operstate

  Sample output:

  up

  As you in the above outputs, the network cable is connected with the Lan adapter.?Here,?”enp5s0″ is my network card name. You can find out the name of your network card using “ifconfig” or “ip addr” commands. For more details to know the list of available network interfaces, check the following guide.

  How To Find Available Network Interfaces On Linux

  Not only wired network card, we can also find the state of a wireless network card too.

  To do so, run:

  $ cat /sys/class/net/wlp9s0/carrier

  Sample output:

  1

  Or,

  $ cat /sys/class/net/wlp9s0/operstate

  Sample output:

  up

  

  

  Now, just disconnect the network cable and check what would be the output.

  $ cat /sys/class/net/enp5s0/carrier

  Sample output:

  0

  Or,

  $ cat /sys/class/net/enp5s0/operstate

  Sample output:

  down

  See? We got results as “0” (zero) and “down”, which means that the cable is not connected.?It doesn’t matter whether you configured the IP address to the network card or not. You can easily find out if the cable is connected or not using the above commands.

  Don’t miss – Assign multiple IP addresses to single Network card in Linux

  In case the above commands doesn’t help, there is another tool called “ethtool” to help you. ethtool is used to query and control network device driver and hardware?settings, particularly for wired Ethernet devices.

  Run the following command to find out the connected state of a network cable:

  $ sudo ethtool enp5s0

  Sample output:

  Settings for enp5s0:

  Supported ports: [ TP MII ]

  Supported link modes: 10baseT/Half 10baseT/Full

  100baseT/Half 100baseT/Full

  Supported pause frame use: No

  Supports auto-negotiation: Yes

  Advertised link modes: 10baseT/Half 10baseT/Full

  100baseT/Half 100baseT/Full

  Advertised pause frame use: Symmetric Receive-only

  Advertised auto-negotiation: Yes

  Link partner advertised link modes: 10baseT/Half 10baseT/Full

  100baseT/Half 100baseT/Full

  Link partner advertised pause frame use: Transmit-only

  Link partner advertised auto-negotiation: Yes

  Speed: 100Mb/s

  Duplex: Full

  Port: MII

  PHYAD: 0

  Transceiver: internal

  Auto-negotiation: on

  Supports Wake-on: pumbg

  Wake-on: g

  Current message level: 0x00000033 (51)

  drv probe ifdown ifup

  Link detected: yes

  

  To find out the state of wireless network card:

  $ sudo ethtool wlp9s0

  Sample output:

  Settings for wlp9s0:

  Link detected: yes

  

  

  Let us disconnect the cable, and see what happens.

  $ sudo ethtool enp5s0

  Sample output:

  Settings for enp5s0:

  Supported ports: [ TP MII ]

  Supported link modes: 10baseT/Half 10baseT/Full

  100baseT/Half 100baseT/Full

  Supported pause frame use: No

  Supports auto-negotiation: Yes

  Advertised link modes: 10baseT/Half 10baseT/Full

  100baseT/Half 100baseT/Full

  Advertised pause frame use: Symmetric Receive-only

  Advertised auto-negotiation: Yes

  Link partner advertised link modes: 10baseT/Half 10baseT/Full

  100baseT/Half 100baseT/Full

  Link partner advertised pause frame use: Transmit-only

  Link partner advertised auto-negotiation: Yes

  Speed: 100Mb/s

  Duplex: Full

  Port: MII

  PHYAD: 0

  Transceiver: internal

  Auto-negotiation: on

  Supports Wake-on: pumbg

  Wake-on: g

  Current message level: 0x00000033 (51)

  drv probe ifdown ifup

  Link detected: no

  

  As you see in the above output, the network cable is not plugged in.

  Download your free EBook – Free eBook: “Network and Computer Systems Administrators – Occupational Outlook”

  Another good method suggested by one of our readers is using “ip” command.

  $ ip a

  Sample output would be:

  1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000

  link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

  inet 127.0.0.1/8 scope host lo

  valid_lft forever preferred_lft forever

  inet6 ::1/128 scope host

  valid_lft forever preferred_lft forever

  2: enp5s0: mtu 1500 qdisc noop state DOWN group default qlen 1000

  link/ether 24:b6:fd:37:8b:29 brd ff:ff:ff:ff:ff:ff

  3: wlp9s0: mtu 1500 qdisc noqueue state UP group default qlen 1000

  link/ether c0:18:85:50:47:4f brd ff:ff:ff:ff:ff:ff

  inet 192.168.43.192/24 brd 192.168.43.255 scope global wlp9s0

  valid_lft forever preferred_lft forever

  inet6 fe80::c218:85ff:fe50:474f/64 scope link

  valid_lft forever preferred_lft forever

  That’s all for now. Got any other methods in mind to find out the connected state of a network cable? Feel free to let us know in the comment section below. I will check and update this list accordingly.

  More good stuffs to come. Stay tuned!

  Cheers!

Leave a Comment