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.
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:
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:
It can't forward the traffic to 10.1.16.189 (no MAC address). The proper way to handle is to use the command:
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.
You want to add a route to a host (9.36.204.4) via a gateway (10.1.16.189) that isn't local to your host (10.62.56.130), which can't be done. You can ping the proposed gateway (10.1.16.189) because your local gateway has a route to that gateway. You need to add a route for the other network through your local gateway.
In essence, you can't add a route using a remote gateway. You can only add a route using your local gateway.
Theo's answer is good. I just wanna add in case you have tried all answer in this thread but nothing happen, use syntax below. It works for me.
ip route add <target ip> via <your gateway>
Example
10.10.10.1 is your gateway.
10.128.1.145 is endpoint in another gateway