CentOS: 网络连接故障排除

Posted isme-zjh

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS: 网络连接故障排除相关的知识,希望对你有一定的参考价值。

yum不能正常动作,惯性认为是需要替换BaseURL,结果后来才发现是Gateway不知什么时候被错误设定了,memo如下。

现象
表现于yum不能正常动作,确认ping的操作,发现是不能解析DNS

[root@liumiaocn ~]# ping www.baidu.com
^C 长时间等待 ctrl + C退出
[root@liumiaocn ~]#

确认DNS设定
    [root@liumiaocn ~]# cat /etc/resolv.conf
    # Generated by NetworkManager
    nameserver 8.8.8.8
    nameserver 8.8.4.4
    [root@liumiaocn ~]#

DNS正常设定,表明问题更加基础,应该在于网络完全没有被正确设定。果然8.8.8.8无法ping通

    [root@liumiaocn ~]# ping -w1 8.8.8.8
    PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.

    --- 8.8.8.8 ping statistics ---
    1 packets transmitted, 0 received, 100% packet loss, time 0ms

    [root@liumiaocn ~]#

 


自身连接确认没有问题

    [root@liumiaocn ~]# ping -w1 192.168.32.123
    PING 192.168.32.123 (192.168.32.123) 56(84) bytes of data.
    64 bytes from 192.168.32.123: icmp_seq=1 ttl=64 time=0.023 ms
    64 bytes from 192.168.32.123: icmp_seq=2 ttl=64 time=0.059 ms

-    -- 192.168.32.123 ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 999ms
    rtt min/avg/max/mdev = 0.023/0.041/0.059/0.018 ms
    [root@liumiaocn ~]#

 


网关连接确认

    PING 192.168.32.2 (192.168.32.2) 56(84) bytes of data.
    64 bytes from 192.168.32.2: icmp_seq=1 ttl=128 time=0.334 ms

    --- 192.168.32.2 ping statistics ---
    1 packets transmitted, 1 received, 0% packet loss, time 0ms
    rtt min/avg/max/mdev = 0.334/0.334/0.334/0.000 ms
    [root@liumiaocn ~]#


    ip addr
ip addr确认网络状况,状态如下

    [root@liumiaocn ~]# ip addr
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
    valid_lft forever preferred_lft forever
    2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:9d:48:21 brd ff:ff:ff:ff:ff:ff
    inet 192.168.32.123/24 brd 192.168.32.255 scope global eno16777736
    valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe9d:4821/64 scope link
    valid_lft forever preferred_lft forever
    [root@liumiaocn ~]#

 


设定确认
CentOS和RHEL的网络设定文件都位于/etc/sysconfig/network-scripts下,当前设定确认如下:

    [root@liumiaocn ~]# cat /etc/sysconfig/network-scripts/ifcfg-eno16777736
    TYPE="Ethernet"
    BOOTPROTO="none"
    DEFROUTE="yes"
    IPV4_FAILURE_FATAL="no"
    IPV6INIT="yes"
    IPV6_AUTOCONF="yes"
    IPV6_DEFROUTE="yes"
    IPV6_FAILURE_FATAL="no"
    NAME="eno16777736"
    UUID="56975740-33eb-4306-9ecf-f7d62745c3a0"
    DEVICE="eno16777736"
    ONBOOT="yes"
    IPADDR="192.168.32.123"
    PREFIX="24"
    GATEWAY="192.168.32.31"
    DNS1="8.8.8.8"
    DNS2="8.8.4.4"
    IPV6_PEERDNS="yes"
    IPV6_PEERROUTES="yes"
    IPV6_PRIVACY="no"
    [root@liumiaocn ~]#


立即确认出GATEWAY设定有误

对应方式
修正后重启即可

修正

    [root@liumiaocn ~]# diff /etc/sysconfig/network-scripts/ifcfg-eno16777736 /etc/sysconfig/network-scripts/ifcfg-eno16777736.bak
    15c15
    < GATEWAY="192.168.32.2"
    ---
    > GATEWAY="192.168.32.31"
    [root@liumiaocn ~]#

ifdown

[root@liumiaocn ~]#
[root@liumiaocn ~]# ifdown eno16777736


ifup

如果ifdown是使用终端来做的话,此条命令执行之后自然会关掉当前终端,在能够直接连接地方使用ifup启动即可 
技术图片

 

 

 

结果确认

重新通过终端连接,确认结果, 可以正常动作了

 

PING www.a.shifen.com (14.215.177.37) 56(84) bytes of data.
64 bytes from 14.215.177.37: icmp_seq=1 ttl=128 time=164 ms

--- www.a.shifen.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 164.538/164.538/164.538/0.000 ms
[root@liumiaocn ~]#
[root@liumiaocn ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:9d:48:21 brd ff:ff:ff:ff:ff:ff
inet 192.168.32.123/24 brd 192.168.32.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe9d:4821/64 scope link
valid_lft forever preferred_lft forever
[root@liumiaocn ~]#

总结

超级简单的一个问题,但却是头疼医脚的结果。RCA告诉我们,问题出现的地方,并不一定是需要动刀的地方,经验主义经常会浪费掉我们宝贵的时间。



原文链接:https://blog.csdn.net/liumiaocn/article/details/60467892

以上是关于CentOS: 网络连接故障排除的主要内容,如果未能解决你的问题,请参考以下文章

2020-12-08centos 出现ssH不能连接的故障排除

ssh远程连接centos7故障排除

022-请你说一说PC网络故障,以及如何排除障碍

Centos7网络异常

1周第2课 Linux 配置ip 网络故障排除 Centos7

【干货】这16款网络故障排查工具,总有你用的到的