How to check the physical status of an ethernet port in Linux?

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


Solution 1:

$ 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

Solution 2:

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 it provides a clean interface to the kernel driver.

Full documentation for this part of the sys file system can be found here:

https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net

Solution 3:

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

Solution 4:

ip link show

is another. Good old

ifconfig dev_name

or

ifconfig -a

will also tell you if the interface is up. NOTE: Use caution with these methods since they can show out of date information regarding the link's state.

Solution 5:

dmesg | grep eth

you should see all statuschanges