Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to check the change in the status of eth connection ( link up and link down ) by program ( using c or perl ). Now I using the keepalive way, but i sometime loose the notification. Inside the messages files I see the kernel notification of 'eth0 link down' and this note are always correct so I looking for a way, maybe a syscall, to check for the eth status.

share|improve this question
add comment

2 Answers

If you want to check the link status (carrier), you can check the file:

$ cat /sys/class/net/eth0/carrier

This will show 1 (link is up) or 0 (link is down).

share|improve this answer
    
thanks Khaled, I check your note on feodra 8, fedora 10 and redhat 7.3 your answer is ok for the kernel 2.6, but on redhat 7.3 , when I got the kernel 2.4 there isn't the directory /sys. On thi last distro, I look for similar files named carrier but i didn't found it. So my new question became, when to detect the line status on distro using kernel 2.4 ? –  enzo2 Dec 3 '10 at 6:58
    
I don't have any system with a 2.4 kernel. Anyway, I will try to find another way for such systems. –  Khaled Dec 3 '10 at 7:39
add comment

Just as a workaround for RH73 (please don't ask me why I have a bunch of RH73 boxes to hand, in 2010):

[madhatta@ms01 madhatta]$ cat /etc/redhat-release 
Red Hat Linux release 7.3 (Valhalla)
[madhatta@ms01 madhatta]$ uname -a
Linux ms01.company.com 2.4.20-30.7.legacysmp #1 SMP Fri Feb 20 10:12:55 PST 2004 i686 unknown
[madhatta@ms01 madhatta]$ sudo mii-tool eth0
eth0: negotiated 100baseTx-FD, link ok
[madhatta@ms01 madhatta]$ 
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.