How to see if an interface is connected in Centos/Linux

88,679

Solution 1

You've asked two different questions. To check if it has an IP address, you can use:

ip addr ls dev eth0  # the new iproute tools
ifconfig eth0        # old ifconfig

A down interface can still have an IP address. To check if the Ethernet link is up, you can:

ip link ls dev eth0  # look for LOWER_UP
ethtool eth0         # look for Link detected: yes

Note that a port may be "down" in software as well, in which case it may not have a link, despite being plugged in. You can check for that with:

ip link ls dev etho  # look for UP
ifconfig eth0        # look for UP / RUNNING (on the same line as the other flags)

The ip command supports a lot of advanced networking configuration that ifconfig/route/etc. do not. You should generally prefer them on Linux, but sometimes they're not installed (especially on older releases). You can still use ifconfig, etc., but those simply fail to display all the information—e.g., may not display a secondary IP address, or a second routing table.

Solution 2

Ifconfig is an obsolete command. The iproute2 suite supersedes it, along with a large number of other utilities, including bridge-utils, route, and so on.

The correct command is

 ip addr show dev eth0

which shows whether eth0 (for instance) has an IP address assigned. You can check whether the interface is up with

 ip link show dev eth0

and so on.

Share:
88,679

Related videos on Youtube

Logan Williams
Author by

Logan Williams

I am a network engineer so in love with technology that I ventured into systems engineering and I'm loving it.

Updated on September 18, 2022

Comments

  • Logan Williams
    Logan Williams over 1 year

    With Centos installed on a server with 2 onboard ethernet ports, how can I check which port has an IP? In windows you can go to network & sharing center and you can see the network interface with a red X to show that the cable is unplugged. In Centos what command can I run to check which interface is connected or unplugged.