【问题标题】:Ping fails between two Linux systems via an intermediate linux [closed]通过中间 linux 在两个 Linux 系统之间 Ping 失败 [关闭]
【发布时间】:2016-02-10 11:48:45
【问题描述】:

我有一个简单的网络,包含三个运行 CentOS 2.6 的 Linux 系统。

Linux 1 (eth1: 192.138.14.1)----- (eth4:192.138.14.4) Linux 2 (eth2: 192.138.4.3)-----(eth3: 192.138.4.2) Linux 3

我无法从 Linux 1 ping Linux 3。我能够 ping 的是从 Linux 1 到 Linux 2 (eth2) 以及从 Linux 3 到 Linux 2 (eth4)。这意味着从 Linux 1 开始,我可以 ping 192.138.4.3 但不能 ping 192.138.4.2。

以下是Linux1中route -n命令的输出

Linux1# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.138.14.0    0.0.0.0         255.255.255.0   U     0      0        0 eth1
192.138.4.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1
10.135.18.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1003   0        0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U     1005   0        0 eth3
0.0.0.0         10.135.18.1     0.0.0.0         UG    0      0        0 eth0

在 Linux 2 中:

Linux2# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.138.15.0    0.0.0.0         255.255.255.0   U     0      0        0 eth1
192.138.14.0    192.138.14.4    255.255.255.0   UG    0      0        0 eth4
192.138.14.0    0.0.0.0         255.255.255.0   U     0      0        0 eth4
192.138.4.0     192.138.4.3     255.255.255.0   UG    0      0        0 eth2
192.138.4.0     0.0.0.0         255.255.255.0   U     0      0        0 eth2
10.135.18.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.138.16.0    0.0.0.0         255.255.255.0   U     0      0        0 eth3
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1003   0        0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U     1004   0        0 eth2 
169.254.0.0     0.0.0.0         255.255.0.0     U     1005   0        0 eth3
169.254.0.0     0.0.0.0         255.255.0.0     U     1006   0        0 eth4
0.0.0.0         10.135.18.1     0.0.0.0         UG    0      0        0 eth0

在 Linux 3 中:

Linux3# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.138.14.0    0.0.0.0         255.255.255.0   U     0      0        0 eth3
192.138.4.0     0.0.0.0         255.255.255.0   U     0      0        0 eth3
10.135.18.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1005   0        0 eth3
0.0.0.0         10.135.18.1     0.0.0.0         UG    0      0        0 eth0

我在 Linux 2 中启用了 IP 转发

Linux2# vi /etc/sysctl.conf
# Controls IP packet forwarding
net.ipv4.ip_forward = 1

Linux2#: sysctl -p 
sysctl -p
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_sack = 0
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296

Linux 2 中 iptables -L 的结果:

Linux2# iptables -L  
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            

要从 Linux 1 ping Linux3,我应该在 iptables 中为 icmp 添加特定规则吗?如果没有,我错过了什么?

【问题讨论】:

  • 这不是编程问题;试试superuser.com
  • @OleksandrKravchuk:谢谢,我明白了。 stackoverflow.com/questions/10039027/…> 让我觉得我可以从 stackoverflow 获得帮助

标签: linux networking ping


【解决方案1】:

我想问题是你不在同一个网络上。当 linux1 尝试向 192.138.4.2 发送数据包时,它会查看路由表并发现它应该发送到 eth1。但它也看到没有GW,所以它假设数据包在同一个网络上。因此它向 192.138.4.2 发送了一个 arp 请求,但没有收到任何答复。 您可以通过在 linux 1 上运行“tcpdump -i eth1 arp”来验证我的假设,然后查看您发送了请求但没有看到任何响应。您也可以只输入“arp”并查看您的条目不完整。 所以基本上你的路由表应该包括一个 GW 来路由数据包。 例如,而不是 192.138.4.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 它应该是这样的 192.138.4.0 192.138.14.4 255.255.255.0 UG 0 0 0 eth1 另一边也一样。

【讨论】:

  • 是的。这样可行。但是我一开始是如何 ping 192.138.4.3 的呢?它仍然在不同的网络中,但对于下一个设备来说是本地的。
  • 首先您可以返回设置并检查(听arps并了解发生了什么)。这两个接口是否可以桥接?您可以通过运行“brctl show”来检查。这可以解释(因为 arp 数据包在接口之间桥接)。
猜你喜欢
  • 2023-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-14
相关资源
最近更新 更多