When working with network interfaces in Linux, checking the physical connection state is a fundamental troubleshooting step. The physical status (whether the cable is connected and the link is active) is distinct from the administrative state (whether the interface is enabled in software).
The most reliable tool for checking physical port status is ethtool
. This utility provides detailed information about Ethernet device settings and statistics.
# Install ethtool if not present (Debian/Ubuntu)
sudo apt-get install ethtool
# Check link status for eth0
sudo ethtool eth0
Look for these key lines in the output:
Link detected: yes # Physical link is up
Link detected: no # Physical link is down
For a faster check without all the details:
ethtool eth0 | grep "Link detected"
While primarily for configuration, the ip
command can show link state:
ip link show eth0
Look for these indicators:
state UP # Interface is administratively up
LOWER_UP # Physical link is detected (carrier detected)
NO-CARRIER # No physical link detected
To check all Ethernet interfaces at once:
for intf in /sys/class/net/eth*; do
echo -n "${intf##*/}: "
cat $intf/operstate
done
For continuous monitoring of link state changes:
sudo ethtool --monitor eth0
Or using watch for periodic checks:
watch -n 1 "ethtool eth0 | grep 'Link detected'"
Possible states and their meanings:
- up/UP: Interface is administratively enabled
- LOWER_UP: Physical link is detected
- NO-CARRIER: No physical connection
- down/DOWN: Interface is administratively disabled
If you're getting unexpected results:
- Try a different Ethernet cable
- Test with another port on the switch
- Check switch/router configuration
- Verify NIC drivers are properly loaded (
lsmod | grep eth
)
Here's a bash function to check and report interface status:
check_eth_status() {
local iface=$1
if [ ! -d "/sys/class/net/$iface" ]; then
echo "Error: Interface $iface does not exist"
return 1
fi
local admin=$(cat /sys/class/net/$iface/operstate)
local carrier=$(ethtool $iface | grep "Link detected" | awk '{print $3}')
echo "Interface: $iface"
echo "Admin state: $admin"
echo "Physical link: $carrier"
}
Usage: check_eth_status eth0
When troubleshooting network connectivity in Linux, checking the physical state of an Ethernet port is one of the first diagnostic steps. The physical state (up/down) indicates whether the network interface has established a valid connection at the hardware level.
The most reliable way to check physical link status is using ethtool
, which directly queries the network interface hardware:
sudo ethtool eth0
Look for these key fields in the output:
Link detected: yes/no
Speed: 1000Mb/s
Duplex: Full
For systems without ethtool, try these commands:
ip link show
ip link show eth0
The output shows state UP
for administratively enabled interfaces and LOWER_UP
for physical link status.
sysfs Interface
cat /sys/class/net/eth0/operstate
Possible values: up
, down
, or unknown
.
For scripting purposes, use these one-liners:
# Using ethtool
ethtool eth0 | grep -q "Link detected: yes" && echo "UP" || echo "DOWN"
# Using ip command
ip -o link show eth0 | grep -q "LOWER_UP" && echo "UP" || echo "DOWN"
- If ethtool reports "No such device", check interface name with
ip a
dmesg | grep eth0
shows hardware-level connection events- For virtual interfaces, physical status may not be applicable