大网数据广告活动
服务器运维问答

Gateway can be pinged, but fail to add route with it

· 52CE 我爱测

I want to use 10.1.16.189 as gateway to access 9.36.204.4 both on redhat 6.4. here is the network configuration of my machine: eth0 Link encap:Ethernet HWaddr 06:FB:C1:7B:19:FD inet addr:10.62.56.130 Bcast:10.62.56.255 Mask:255.2…

问题原文

原帖链接 · che yang · CC BY-SA 3.0

I want to use 10.1.16.189 as gateway to access 9.36.204.4 both on redhat 6.4. here is the network configuration of my machine:

      eth0      Link encap:Ethernet  HWaddr 06:FB:C1:7B:19:FD
      inet addr:10.62.56.130  Bcast:10.62.56.255  Mask:255.255.255.128
      inet6 addr: fe80::4fb:c1ff:fe7b:19fd/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:435639 errors:0 dropped:0 overruns:0 frame:0
      TX packets:13729 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:46426471 (44.2 MiB)  TX bytes:1502807 (1.4 MiB)
      Interrupt:32

The network configuration of the machine I want to use as gateway:

      eth0      Link encap:Ethernet  HWaddr 52:54:00:EA:31:A2
      inet addr:9.42.27.23  Bcast:9.42.27.255  Mask:255.255.252.0
      inet6 addr: 2002:92a:111:430:5054:ff:feea:31a2/64 Scope:Global
      inet6 addr: fe80::5054:ff:feea:31a2/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:53655370 errors:0 dropped:0 overruns:0 frame:0
      TX packets:21812264 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:30987415175 (28.8 GiB)  TX bytes:27696977107 (25.7 GiB)

      tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
      inet addr:10.1.16.44  P-t-P:1.1.1.1  Mask:255.255.255.255
      UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1450  Metric:1
      RX packets:480532 errors:0 dropped:0 overruns:0 frame:0
      TX packets:887766 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:500
      RX bytes:70276913 (67.0 MiB)  TX bytes:1234059626 (1.1 GiB)

And here are my operations

route add -host 10.1.16.189 dev eth0 gw 10.62.56.129

add the way to access host 9.36.204.4 through 10.1.16.189

route  add -host 9.36.204.4  gw 10.1.16.189
SIOCADDRT: Network is unreachable

But I'm able to ping and traceroute 10.1.16.189.

ping 10.1.16.189
PING 10.1.16.189 (10.1.16.189) 56(84) bytes of data.
64 bytes from 10.1.16.189: icmp_seq=1 ttl=54 time=76.2 ms
64 bytes from 10.1.16.189: icmp_seq=2 ttl=54 time=75.4 ms
64 bytes from 10.1.16.189: icmp_seq=3 ttl=54 time=75.5 ms

So I want to know why it reported the network is unreachable but I can ping and access it, I even can ssh it. And how to configure it to access 9.36.204.4(which can be reached in 10.1.16.189). And how to determine a gateway is reachable. thanks.

已采纳解答

原帖链接 · Theo · CC BY-SA 3.0

You can only add routes to a server where it knows how to reach that gateway. When you first configure 10.62.56.130/25, it can only reach addresses 10.62.56.128 through 10.62.56.128. By contrast, it can find any of the MAC addresses (Layer 2) for those machines by using ARP.

Then, once this route is added:

route add -host 10.1.16.189 dev eth0 gw 10.62.56.129

It knows it can also reach 10.1.16.189 by sending the traffic to 10.62.56.129. It cannot find the MAC address of 10.1.16.189, but will send to 10.62.56.129 in hopes of reaching 10.1.16.189.

So when you try:

route add -host 9.36.204.4 gw 10.1.16.189

It can't forward the traffic to 10.1.16.189 (no MAC address). The proper way to handle is to use the command:

route add -host 9.36.204.4 gw 10.62.56.129

And to make sure 10.62.56.129 will route to 10.1.16.189--who will route to possible next destination (and so on) eventually reaching 9.36.204.4.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-01-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。