CentOS确认网口是否插入网线的办法

最近公司的机器存在网络问题, 部分网络总是不通, 比较奇怪. 最近一直想处理好. 

第一步: 先查看网口的设备信息

可以使用

ip link show 

可以讲网口信息都展示出来.

一般情况下  NO-CARRIER 的信息就意味着么有插入网线. 或许可以继续进行验证

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp39s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether b4:05:5d:b3:b1:fc brd ff:ff:ff:ff:ff:ff
3: enp39s0f1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP mode DEFAULT group default qlen 1000
    link/ether b4:05:5d:b3:b1:fd brd ff:ff:ff:ff:ff:ff
4: enp39s0f2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
    link/ether b4:05:5d:b3:b1:fe brd ff:ff:ff:ff:ff:ff
5: enp39s0f3: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
    link/ether b4:05:5d:b3:b1:ff brd ff:ff:ff:ff:ff:ff

这里需要说明一下网卡的命名问题

CentOS6 以及之前的命令 都是使用 eth0 eth1 这样类似的命名
很简单, 也不会出问题
CentOS7 之后的网卡, 虚拟机里面貌似都会是 ens192 类似的网口名字
s 应该是 插座的意思. 
如果是服务器
如果是板载的网卡 一把你是 ens开头.
如果是PCI-e插入的网卡一般是 enp 开头 p 应该是pluggable 的部分含义.

有时候需要统一网卡名字,便于处理. 
今天暂时不考虑这一块的操作. 

第二步: 先确认网口是否连接网线. 

使用的方式为 ethtool device_name 的方式. 

方法也很简单. 结果里面有一个 Speed 以及 Duplex 还有 Link Detected 

根据是否有值来判断是否可用.

[root@testsvr113 network-scripts]# ethtool enp39s0f2
Settings for enp39s0f2:
        Supported ports: [  ]
        Supported link modes:   1000baseT/Full
        Supported pause frame use: Symmetric Receive-only
        Supports auto-negotiation: Yes
        Supported FEC modes: Not reported
        Advertised link modes:  1000baseT/Full
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Advertised FEC modes: Not reported
        Speed: Unknown!
        Duplex: Unknown! (255)
        Auto-negotiation: off
        Port: Other
        PHYAD: 0
        Transceiver: internal
        Supports Wake-on: g
        Wake-on: g
        Current message level: 0x00000007 (7)
                               drv probe link
        Link detected: no
[root@testsvr113 network-scripts]# ethtool enp39s0f1
Settings for enp39s0f1:
        Supported ports: [ TP ]
        Supported link modes:   1000baseT/Full
        Supported pause frame use: Symmetric Receive-only
        Supports auto-negotiation: Yes
        Supported FEC modes: Not reported
        Advertised link modes:  1000baseT/Full
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Advertised FEC modes: Not reported
        Speed: 1000Mb/s
        Duplex: Full
        Auto-negotiation: on
        Port: Twisted Pair
        PHYAD: 0
        Transceiver: internal
        MDI-X: Unknown
        Supports Wake-on: g
        Wake-on: g
        Current message level: 0x00000007 (7)
                               drv probe link
        Link detected: yes

第三部分: 设置IP地址进行验证

建议可以使用 nmtui 或者是 cockpit 的方式进行IP地址的设置

其实改名的话 可以在nmtui 里面讲网卡名字改掉. 

注意设置完地址 需要外部进行ping 连接 如果机器设置的IP段与实际的IP地址段不一致, 那么是无法使用的. 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章