Linux Basics: How To Check The State Of A Network Interface Card

Normally, we can easily check the state of a network interface card like whether the cable plugged in to the slot or the network card is up or down in Graphical mode. What if you have only command line mode? Ofcourse, you can turn around the system and check for the cable is properly plugged in, or you can do the same easily from your Terminal. Here is how to do that. This method is almost same for Debian and RPM based systems.

Check Network Card State

I have two ethernet cards on my laptop. One, eth0,  is wired, And another, wlan0, is wireless.

Let us check the state of the eth0.

cat /sys/class/net/eth0/carrier

Sample output:

0

Or, use the following command to check the status.

cat /sys/class/net/eth0/operstate

Sample output:

down

As you see in the above results, the NIC is down or cable is not connected.

Let me plug a network cable to the eth0 slot, and check again.

After plugged in the cable, I executed the above commands:

cat /sys/class/net/eth0/carrier

Sample output:

1

Or,

cat /sys/class/net/eth0/operstate

Sample output:

up

Voila, the eth0 is up or the cable is connected to eth0.

Be mindful, it doesn’t mean that the IP address has been assigned to the eth0. The cable is just connected to that slot. That’s all.

Let us check for the wlan0 state.

cat /sys/class/net/wlan0/carrier

Sample output:

1

The result is 1, which means the wlan0 is up and connected.

Or,

cat /sys/class/net/wlan0/operstate

Sample output:

up

Likewise, you can check all the network cards on your machine.

What If I don’t know the correct name of the installed interfaces?

One of the issue is, you may not know the names of the interfaces. In that case, run the following command. It will show all the installed interfaces, they generally follow the rule that wired interfaces start with the letter “e” and wireless start with a letter “w”.

Ex:

ls /sys/class/net/

Sample output:

eth0  lo  wlan0

As you see above, I have two NICs, one is wired(eth0) and the other is wireless(wlan0).

Thanks for the above tip to one of the valuable reader of Unixmen Mr.Wogster.

Cheers!