How to tell an eth port has link?

This is a discussion on How to tell an eth port has link? within the Linux Networking forums, part of the Linux Forums category; There has to be a way to tell if the ethernet port has a cable plugged in. I see the ...


Go Back   Usenet Forums > Linux Forums > Linux Networking

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-02-2007
CptDondo
 
Posts: n/a
Default How to tell an eth port has link?

There has to be a way to tell if the ethernet port has a cable plugged in.

I see the kernel message go by telling me it has lost or established the
link when I plug the cable in... But I can't find anything that would
tell me the status from userspace.

I've been all through /proc and I don't see anything that would clue me
in....

So... How to tell if an ethX port has a valid hardware link? I need to
test this before networking comes up so I know if I should run DHCP or
not...

--Yan
Reply With Quote
  #2 (permalink)  
Old 04-02-2007
Ian Northeast
 
Posts: n/a
Default Re: How to tell an eth port has link?

On Mon, 02 Apr 2007 09:01:02 -0700, CptDondo wrote:

> There has to be a way to tell if the ethernet port has a cable plugged in.


Use ethtool and/or mii-tool. Depending on what type of card it is, one or
the other should work.

Regards, Ian
Reply With Quote
  #3 (permalink)  
Old 04-02-2007
Tauno Voipio
 
Posts: n/a
Default Re: How to tell an eth port has link?

CptDondo wrote:
> There has to be a way to tell if the ethernet port has a cable plugged in.
>
> I see the kernel message go by telling me it has lost or established the
> link when I plug the cable in... But I can't find anything that would
> tell me the status from userspace.
>
> I've been all through /proc and I don't see anything that would clue me
> in....
>
> So... How to tell if an ethX port has a valid hardware link? I need to
> test this before networking comes up so I know if I should run DHCP or
> not...
>
> --Yan



Maybe you like to have ifplugd?

--

Tauno Voipio
tauno voipio (at) iki fi
Reply With Quote
  #4 (permalink)  
Old 04-03-2007
Mark Hobley
 
Posts: n/a
Default Re: How to tell an eth port has link?

CptDondo <yan@nsoesipnaemr.com> wrote:

> I see the kernel message go by telling me it has lost or established the
> link when I plug the cable in


Is there a hook for this that can call a script, or trigger an initd event
that can be used to call a script?

I am curious, because on my network, if I have a power failure, the network
hubs lose their connections, but the computers continue to run from a UPS
supply. The loss of the network hubs is a sure signal to all computers that
the power is out.

I was hoping to hook a shutdown script to the loss of ethernet connection
event, that shuts the computers down, if the outage lasts more than a couple
of minutes.

Regards,

Mark.

--
Mark Hobley
393 Quinton Road West
QUINTON
Birmingham
B32 1QE

Telephone: (0121) 247 1596
International: 0044 121 247 1596

Email: markhobley at hotpop dot donottypethisbit com

http://markhobley.yi.org/

Reply With Quote
  #5 (permalink)  
Old 04-03-2007
CptDondo
 
Posts: n/a
Default Re: How to tell an eth port has link?

Mark Hobley wrote:
> CptDondo <yan@nsoesipnaemr.com> wrote:
>
>> I see the kernel message go by telling me it has lost or established the
>> link when I plug the cable in

>
> Is there a hook for this that can call a script, or trigger an initd event
> that can be used to call a script?
>
> I am curious, because on my network, if I have a power failure, the network
> hubs lose their connections, but the computers continue to run from a UPS
> supply. The loss of the network hubs is a sure signal to all computers that
> the power is out.
>
> I was hoping to hook a shutdown script to the loss of ethernet connection
> event, that shuts the computers down, if the outage lasts more than a couple
> of minutes.
>


If I understand ifplugd correctly from reading the manpage, it should
detect the other end losing power, as the link will drop.

I have not gotten into ifplugd yet - I'm still hoping to get dhclient to
do what I want - but it looks promising. For my purposes it's a bit of
overkill...

--Yan
Reply With Quote
  #6 (permalink)  
Old 04-03-2007
Mark Hobley
 
Posts: n/a
Default Re: How to tell an eth port has link?

CptDondo <yan@nsoesipnaemr.com> wrote:
> I have not gotten into ifplugd yet - I'm still hoping to get dhclient to
> do what I want - but it looks promising. For my purposes it's a bit of
> overkill...


Yeah for mine too really, I don't want to configure the network, that is
already done here, and my IP addresses are static, so I don't use dhclient. All
I want to do is hook the cable dead event, possibly through initd, if it
supports the incident.

Regards,

Mark.

--
Mark Hobley
393 Quinton Road West
QUINTON
Birmingham
B32 1QE

Telephone: (0121) 247 1596
International: 0044 121 247 1596

Email: markhobley at hotpop dot donottypethisbit com

http://markhobley.yi.org/

Reply With Quote
  #7 (permalink)  
Old 04-03-2007
CptDondo
 
Posts: n/a
Default Re: How to tell an eth port has link?

Mark Hobley wrote:
> CptDondo <yan@nsoesipnaemr.com> wrote:
>> I have not gotten into ifplugd yet - I'm still hoping to get dhclient to
>> do what I want - but it looks promising. For my purposes it's a bit of
>> overkill...

>
> Yeah for mine too really, I don't want to configure the network, that is
> already done here, and my IP addresses are static, so I don't use dhclient. All
> I want to do is hook the cable dead event, possibly through initd, if it
> supports the incident.


I think what I am going to do is:

on boot, run mii-tools to see if the cable is hooked up
if it is, run dhclient {
if dhclient gets an address {
set up for networked database
exit }
}

assume no network
set up for local database

I think you could run mii-tools/ethtools from a loop every so often
(minute?) and see if the link is dead.

--Yan
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:14 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0