Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to check if a specified ethX is physically up or down. How do I do that with the command line?

share|improve this question
up vote 40 down vote accepted

$ ethtool <eth?>

For example:

$ ethtool eth0

provides:

Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: on
        Supports Wake-on: pumbg
        Wake-on: g
        Current message level: 0x00000001 (1)
        Link detected: yes
share|improve this answer

ethtool [interface]

last line shows what you want:

# ethtool eth0
Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Full 
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Full 
        Advertised auto-negotiation: Yes
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: g
        Wake-on: d
        Current message level: 0x00000037 (55)
        Link detected: yes
share|improve this answer
3  
If you check this: en.wikipedia.org/wiki/OSI_model . You will see that the last line is about another layer: the link layer. I just tested this. With a bad cable the physical layer was up, but not the link layer. Then I switched to another cable and all layers came up. – Jader Dias May 30 '09 at 19:37

Check /sys/class/net/eth0/operstate and other files in this directory

As far as I know this is specific to Linux 2.6 but provides a clean interface to the kernel driver.

share|improve this answer
8  
/sys/class/net/eth0/carrier was the perfect answer to this question for me. – Per Knytt Apr 29 '11 at 15:32
ip link show

is another. Good old

ifconfig dev_name

or

ifconfig -a

will also tell you if the interface is up

share|improve this answer
    
I think this was the best answer - ethtool isn't standard in my Ubuntu distibution, so it doesn't help if on a box not connected to the net. – user20010 Sep 25 '13 at 21:32
    
I believe ifconfig will sometimes show out of date data. It can show UP when the link is down, but ethtool interface will always show the right info AFAIK. – sed_and_done Oct 8 '15 at 17:15
dmesg | grep eth

you should see all statuschanges

share|improve this answer
    
This is the only one that works if one lacks admin privileges. – Brian B Mar 20 '13 at 15:30
    
dmesg requires root on Slackware 14.0 – AnonymousLurker Aug 30 '13 at 14:20
    
No, it doesn't. I just checked — while it works for me on eth0 device, but it doesn't on eth2 device. – Hi-Angel May 18 '15 at 10:02

You can also use mii-tool to see if the link is up and check the negotiated speed.

# mii-tool
eth0: negotiated 100baseTx-FD, link ok

share|improve this answer
4  
mii-tool is deprecated and does not work for GbE interfaces. – Dave Cheney May 31 '09 at 3:59
2  
@DaveCheney # mii-tool eth0: negotiated 1000baseT-FD flow-control, link ok – stolsvik Jul 21 '11 at 11:00
    
The man page for mii-tool suggests using ethtool. However, mii-tool keeps doing its job, more useful if given the -v (verbose) option. – David Ramirez Jul 9 '14 at 22:44

netplugd is a service that can run program(s) when a cable is plugged in or a cable taken out.

share|improve this answer
    
Well, not exactly the requested answer, but an interesting one to know. At least for me. – Sopalajo de Arrierez Oct 28 '14 at 23:44

If your system is using ifplugd (e.g. on a Raspberry Pi with Raspbian) then you can use the associated status tool ifplugstatus to obtain the link status of all interfaces:

ifplugstatus

or a specific interface (e.g. eth0):

ifplugstatus eth0
share|improve this answer

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.