0

I was so confused with my configuration.

In my server I have 2 interfaces:

eth0: 192.168.1.22  gw 192.168.1.1
eth2: 10.2.1.6 gw 10.2.1.1

I wrote a static route:

ip r a 8.8.8.8 via 192.168.1.1
 worked great!!

then I deleted it and
ip r a 8.8.8.8 dev eth0
 From 192.168.1.22 icmp_seq=1 Destination Host Unreachable

Why?????

bing0
  • 1
  • 2

2 Answers2

1

In the second form (ip r a 8.8.8.8 dev eth0) you did not specify a gateway, so to which router the packet should be forwarded to? Not knowing any gateways, your server simple replies with "Destination Host Unreachable".

Specifying an interface can be useful for two reasons:

  • if a remote host is routed via the same gateway, itself reachable on two different interfaces, you can create two different routes with distinct dev for the same gateway. You can then prioritize between the two routes via metric or use ECMP routing to achieve some sort of load balancing;
  • for point-to-point interfaces (think VPN or tun interfaces), where all traffic is "captured" by the specified interface (the gateway being unimportant)
shodanshok
  • 47,711
  • 7
  • 111
  • 180
0

ip r a 8.8.8.8 dev eth0 means "8.8.8.8 is directly connected to eth0 interface". Linux kernel tries to resolve MAC address of 8.8.8.8 with arp request, receives no answer and reports "Destination Host Unreachable" error

R3d3
  • 56
  • 1