I want to check if a specified ethX is physically up or down. How do I do that with the command line?
10 Answers
$ 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 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
- 12/sys/class/net/eth0/carrier was the perfect answer to this question for me.Per Knytt– Per Knytt2011-04-29 15:32:30 +00:00Commented Apr 29, 2011 at 15:32
- Great answer. A small addendum: /run/network/ifstate have some useful information too.Paulo André Haacke– Paulo André Haacke2017-08-03 13:43:59 +00:00Commented Aug 3, 2017 at 13:43
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
- 6If 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– Jader Dias2009-05-30 19:37:01 +00:00Commented May 30, 2009 at 19:37
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.
- 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– user200102013-09-25 21:32:52 +00:00Commented Sep 25, 2013 at 21:32
- 4I 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– sed_and_done2015-10-08 17:15:18 +00:00Commented Oct 8, 2015 at 17:15
- 2I think @sed_and_done is right. On a Red Hat VM, if I disconnect the NIC, ethtool immediately shows
Link detected: noinstead ofLink detected: yes, and ip link show shows<NO-CARRIER,BROADCAST,MULTICAST,UP>instead of<BROADCAST,MULTICAST,UP,LOWER_UP>, but ifconfig -a showsUP BROADCAST MULTICAST MTU:1500 Metric:1, which is the same as when the NIC is connected.Adi Inbar– Adi Inbar2017-05-04 18:16:28 +00:00Commented May 4, 2017 at 18:16
dmesg | grep eth you should see all statuschanges
- This is the only one that works if one lacks admin privileges.Brian B– Brian B2013-03-20 15:30:03 +00:00Commented Mar 20, 2013 at 15:30
- dmesg requires root on Slackware 14.0AnonymousLurker– AnonymousLurker2013-08-30 14:20:33 +00:00Commented Aug 30, 2013 at 14:20
- No, it doesn't. I just checked — while it works for me on
eth0device, but it doesn't oneth2device.Hi-Angel– Hi-Angel2015-05-18 10:02:31 +00:00Commented May 18, 2015 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
- 5mii-tool is deprecated and does not work for GbE interfaces.Dave Cheney– Dave Cheney2009-05-31 03:59:10 +00:00Commented May 31, 2009 at 3:59
- 2@DaveCheney
# mii-tool eth0: negotiated 1000baseT-FD flow-control, link okstolsvik– stolsvik2011-07-21 11:00:55 +00:00Commented Jul 21, 2011 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– David Ramirez2014-07-09 22:44:50 +00:00Commented Jul 9, 2014 at 22:44
To quickly add to @goo's answer, you would interpret the ip link or ip link show INTERFACE as follows.
This is a port which is administratively up, but physically down:
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
In other words, the UP you can see indicates the system is configured to try and use the NIC for networking. The NO-CARRIER here tells you what the issue preventing networking from working is.
This is a port that is administratively down (its physical layer is 'up', technically - it is a VM):
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
Finally, this port is working normally:
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq state UP mode DEFAULT group default qlen 1000
It is administratively UP, the LOWER_UP indicates the physical layer is working (i.e. there is a carrier), and the second UP confirms (in effect) the IP layer is up.
You can have full details with below command
ethtool eth0 And if you just want to see link status the give below command
mii-tool eth0 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 netplugd is a service that can run program(s) when a cable is plugged in or a cable taken out. So the command line would be to grep /var/log/messages or dmesg for netplugd output.
- 1Well, not exactly the requested answer, but an interesting one to know. At least for me.Sopalajo de Arrierez– Sopalajo de Arrierez2014-10-28 23:44:44 +00:00Commented Oct 28, 2014 at 23:44