I actually wanted to post the below as an answer to this question titled: ifup eth0 timeout during boot. But am not sure if this is right approach or it's a way of screwing up things badly.

We can actually check if the network cable is connected to the machine, or not, by running the command,

grep "" /sys/class/net/eth0/carrier

When the network cable is plugged in, the output would be 1 for the above command and when it is not plugged in, the output would be 0 for the above command. I tested the above part in my system and it worked fine as expected.

Now the question lies in how to include this condition on startup. We can include this in the network startup file, which can check this condition before bringing up the interfaces. In RHEL box the file /etc/sysconfig/network-scripts/ifcfg-eth0 is used to bring up the network interfaces.

So, If I change the file to look like,

cable=$(grep "" /sys/class/net/eth0/carrier)
if $cable -eq 1 then
   #rest of the /etc/sysconfig/network-scripts/ifcfg-eth0 as it is. 

However, before proposing this method, or even trying on my machine, my question is: When the services are being brought up will the /sys/class/net/eth0/carrier be ready and available? Assuming this approach works, if I decide to use wireless network will there be a problem?


1 Answer 1


Unfortunately, the interface has to be up for the above suggested method to work. I made the changes in my file as I suggested in the question and ended up receiving the error as "Invalid argument". So, I believe the interface should be up to query if the wired connection is available or not. I also found more useful information for this answer: How to detect the physical connected state of a network cable/connector?.

cat /sys/class/net/ethX is by far the easiest method.

The interface has to be up though, else you will get an invalid argument error.

So first:

ifconfig ethX up


cat /sys/class/net/ethX

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .