How to know if eth0 is up?

Discussion in 'Linux Networking' started by Guest, Mar 30, 2012.

  1. Guest

    Guest Guest

    Hello.

    I'd like to know if there is a command line instruction or a /proc/
    entry that tells reliably if a cable is hooked in an ethernet port
    (typically, to know at boot if I must use my dhcp client on eth0, or
    look for a WIFI cell).

    I have found /proc/net/dev but it shows eth0 even though no cable is
    plugged in.

    Thanks.
     
    Guest, Mar 30, 2012
    #1
    1. Advertisements

  2. Guest

    Chris Davies Guest

    Either mii-tool or ethtool.
    Chris
     
    Chris Davies, Mar 30, 2012
    #2
    1. Advertisements

  3. Guest

    Bit Twister Guest

    Hi. You know if you were to read
    http://www.catb.org/~esr/faqs/smart-questions.html
    it suggest giving meaningful information pertinent to your setup.

    At a minimum I would suggest which linux distribution, release, and
    Ethernet card. That kind of information might get you some exact answers.

    NIC may dictate which tool (ethtool, or mii-tool).

    Distribution might get you what net function can be used to make you code
    much more maintainable as time goes by.

    On my distribution, carrier status is found over in /sys/class/net and
    the network-functions script has a check_link_down function to do
    all the dirty work.

    Based on the lack of any detailed information, I can only suggest
    trying something like parsing the output from something like

    LC_ALL=C ip link show dev eth0
     
    Bit Twister, Mar 30, 2012
    #3
  4. Guest

    J G Miller Guest

    Which is quite a different thing to your "subject" which could be
    answered perhaps with

    ifconfig eth0 | egrep 'UP' | egrep 'RUNNING'

    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

    As others have suggested perhaps

    ethtool eth0 | egrep "Link detected"

    Link detected: yes
     
    J G Miller, Mar 30, 2012
    #4
  5. Guest

    Jorgen Grahn Guest

    ....

    A general answer is more enlightening for the rest of us, though.

    ....
    ....

    .... like this one. I know kernel interfaces change now and then, but
    I'd like to see one modern distribution which didn't enable that one.
    (Thanks, by the way!)

    /Jorgen
     
    Jorgen Grahn, Mar 31, 2012
    #5
  6. Guest

    Mark Evans Guest

    Have you looked at ifplugd?
     
    Mark Evans, Apr 5, 2012
    #6
  7. Guest

    sreeramabs

    Joined:
    May 7, 2012
    Messages:
    3
    Likes Received:
    0
    Hi,
    'ethtool' shows 'Link Detected: yes' when the ethernet cable was plugged in and network was up and running. Then I removed the cable and issued 'ethtool'. It still showed 'Link Detected: yes'.
    So, I feel this tools is not dynamic enough to give us to most recent information. Probably, it may be showing up cached information.
    Is there a way/options in this tool to get the most recent status?

    Regards,
    Sreeram
     
    sreeramabs, May 8, 2012
    #7
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.