Centos/Linux下如何查看接口是否连接

Pad*_*ton 2 centos interface

Centos 安装在带有 2 个板载以太网端口的服务器上,如何检查哪个端口有 IP?在windows中你可以进入网络和共享中心,你可以看到带有红色X的网络接口,表明电缆已拔下。在 Centos 中,我可以运行什么命令来检查连接或拔出哪个接口。

der*_*ert 12

你问了两个不同的问题。要检查它是否有IP 地址,您可以使用:

ip addr ls dev eth0  # the new iproute tools
ifconfig eth0        # old ifconfig
Run Code Online (Sandbox Code Playgroud)

关闭的接口仍然可以有一个 IP 地址。要检查以太网链路是否已启动,您可以:

ip link ls dev eth0  # look for LOWER_UP
ethtool eth0         # look for Link detected: yes
Run Code Online (Sandbox Code Playgroud)

请注意,软件中的端口也可能“关闭”,在这种情况下,尽管已插入,但它可能没有链接。您可以通过以下方式检查:

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

ip命令支持很多高级的网络配置中ifconfig/route的/ etc。不要。您通常应该在 Linux 上更喜欢它们,但有时它们没有安装(尤其是在旧版本上)。您仍然可以使用ifconfig等,但那些只是无法显示所有信息——例如,可能不显示辅助 IP 地址或第二个路由表。