如何解决 Linux 机器上 ping 路由器失败的问题?

如何解决 Linux 机器上 ping 路由器失败的问题?

我有一个家庭网络 192.168.0.x,我从中发布此消息,在此网络上我有一台 CentOS7 主机 192.168.0.3,它正在为网络运行 DNS 服务器。

我可以ssh进入 192.168.0.3 我可以nslookup获取远程计算机的 IP 地址,但我无法 ping 我的路由器。

[root@san ~]# ping -c3 192.168.0.1
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.

--- 192.168.0.1 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 1999ms

以下是arp报道内容

[root@san ~]# arp
Address                  HWtype  HWaddress           Flags Mask            Iface
192.168.0.8              ether   b8:8d:12:20:36:6c   C                     eno1
192.168.0.13             ether   c0:3f:d5:63:4e:1a   C                     eno1
192.168.0.10             ether   c0:3f:d5:63:52:06   C                     eno1
192.168.0.11             ether   c0:3f:d5:61:e8:54   C                     eno1
192.168.0.7              ether   00:50:56:61:2b:75   C                     eno1
192.168.0.12             ether   c0:3f:d5:63:19:71   C                     eno1
192.168.0.1              ether   c0:a0:bb:f8:1f:d4   C                     eno1

我可以 ping 通网络上的其他机器

[root@san ~]# ping -c3 192.168.0.13
PING 192.168.0.13 (192.168.0.13) 56(84) bytes of data.
64 bytes from 192.168.0.13: icmp_seq=1 ttl=64 time=0.248 ms
64 bytes from 192.168.0.13: icmp_seq=2 ttl=64 time=0.377 ms
64 bytes from 192.168.0.13: icmp_seq=3 ttl=64 time=0.366 ms

--- 192.168.0.13 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.248/0.330/0.377/0.060 ms

这是route打印的内容

[root@san ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.0.1     0.0.0.0         UG    1024   0        0 eno1
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eno1
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 enp0s20u4

这是ifconfig输出

[root@san ~]# ifconfig
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.3  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::c23f:d5ff:fe63:d1dd  prefixlen 64  scopeid 0x20<link>
        ether c0:3f:d5:63:d1:dd  txqueuelen 1000  (Ethernet)
        RX packets 6513  bytes 1321730 (1.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 15991  bytes 18326750 (17.4 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 20  memory 0xf7c00000-f7c20000  

enp0s20u4: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.4  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::224:9bff:fe0b:ddf2  prefixlen 64  scopeid 0x20<link>
        ether 00:24:9b:0b:dd:f2  txqueuelen 1000  (Ethernet)
        RX packets 469  bytes 36166 (35.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 21  bytes 4155 (4.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 0  (Local Loopback)
        RX packets 2122  bytes 642922 (627.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2122  bytes 642922 (627.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

即使名称解析有效,尝试 ping google.com 也会失败。

[root@san ~]# ping -c3 google.com
PING google.com (74.125.226.134) 56(84) bytes of data.

--- google.com ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 1999ms

可以从网络上的其他机器 ping 路由器,下面的输出来自我的 mac book pro 192.168.0.8

ping -c3 192.168.0.1
PING 192.168.0.1 (192.168.0.1): 56 data bytes
64 bytes from 192.168.0.1: icmp_seq=0 ttl=64 time=1.794 ms
64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=2.000 ms
64 bytes from 192.168.0.1: icmp_seq=2 ttl=64 time=1.986 ms

--- 192.168.0.1 ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 1.794/1.927/2.000/0.094 ms

我的网络中的路由器是 D-Link DIR-850L,我将其配置为指向 192.168.0.3 作为 192.168.0.x 网络的 DNS 服务器。我还将 192.168.0.3 上的 DNS 服务器配置为转发到 google DNS 服务器 8.8.8.8。

为什么我无法从 192.168.0.3 ping 192.168.0.1,即使 192.168.0.3 是我用来从我的 mac 192.168.0.8 发布此问题的主 DNS 服务器,它可以通过 192.168.0.3 浏览网络上的任何位置DNS,但是当我登录 192.168.0.3 时,我无法 ping 通 192.168.0.1 并且无法访问互联网上的任何地方?

答案1

我对 10.132.168.0.3 的路由表有疑问:

default         192.168.0.1     0.0.0.0         UG    1024   0        0 eno1
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eno1
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 enp0s20u4

如果主机不是路由器,我更喜欢路由表只有两行,顺序如下:

192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eno1
default         192.168.0.1     0.0.0.0         UG    1024   0        0 eno1

只需尝试删除旧路线并创建新路线即可。

答案2

原来是我的 DIR-850L 惹的祸,我已将其替换为华硕 RT-AC66R,现在一切正常,符合预期。

相关内容