Score:0

What is the difference between route add x.x.x.x via gatewayip and route add dev interface?

cn flag

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?????

Score:1
ca flag

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)
Score:0
np flag

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

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.