LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Routing Rule Explanation (https://www.linuxquestions.org/questions/linux-networking-3/routing-rule-explanation-4175659078/)

supermario18b 08-13-2019 12:44 PM

Routing Rule Explanation
 
Hi everyone,
I'm able to reach the 192.168.15.15 IP from my pc (192.168.1.10). I settled a routing rule on the router (a fritzbox).

On my Pc I have no routing rule because for the ip 192.168.15.15 will be used the default gateway and the fritzbox let me connect to it. It works and the routing table is:

Code:

default via 192.168.1.1 dev wlp0s20f0u3 proto dhcp metric 600
192.168.1.0/24 dev wlp0s20f0u3 proto kernel scope link src 192.168.1.10 metric 600


Now the question ;) when I add a new routing rule on my pc doesn't work anymore. The Rule is:

Code:

ip route add 192.168.15.0/24 dev wlp0s20f0u3
Now the routing table is:

Code:

default via 192.168.1.1 dev wlp0s20f0u3 proto dhcp metric 600
192.168.15.0/24 dev wlp0s20f0u3 scope link
192.168.1.0/24 dev wlp0s20f0u3 proto kernel scope link src 192.168.1.10 metric 600

Ok I know, there's no need to add this rule because the default gateway will be used without that and it works, but I don't understand why it doesn't work. If I add the IP of the fritzbox at this rule it works:

Code:

ip route add 192.168.15.0/24 via 192.168.1.1 dev wlp0s20f0u3
The routing table that works is then:

Code:

default via 192.168.1.1 dev wlp0s20f0u3 proto dhcp metric 600
192.168.15.0/24 via 192.168.1.1 dev wlp0s20f0u3 scope link
192.168.1.0/24 dev wlp0s20f0u3 proto kernel scope link src 192.168.1.10 metric 600


I don't understand why it doesn't work with the needless rule. Ok it is needless but it should work. And I don't understand why the needless rule with ip specified works. Only the device is not enough (the device is the fritbox).

Is anyone able to explain me that?

Thank you

supermario18b 08-13-2019 04:08 PM

Maybe the right question to simplify would be:

When is the "via" option of ”ip route” command obligatory/needed?

nini09 08-14-2019 02:52 PM

When you add route for 192.168.15.0/24 network, the gateway has to be added. Otherwise, the packet can't forward to gateway.

phil.d.g 08-14-2019 08:05 PM

Quote:

Originally Posted by supermario18b (Post 6024841)
When is the "via" option of ”ip route” command obligatory/needed?

It is only not needed when the two machines can communicate with each other at the ethernet (or whatever you are using under IP) layer. As soon as that is no longer true you need something to route the traffic at the IP layer, and you need to tell your machine where that router is. If you have a router to route to 192.168.15.0/24 that is different to your default gateway, but is still on the same ethernet network you can do something like:

Code:

# ip route add 192.168.15.0/24 via 192.168.1.12

supermario18b 08-15-2019 02:32 AM

Quote:

Originally Posted by phil.d.g (Post 6025231)
It is only not needed when the two machines can communicate with each other at the ethernet (or whatever you are using under IP) layer.

Thank for your reply.Last question... Why do we not need the "via" parameter for the LAN?. The PCs in LAN are not all directly connected but the routing rule is without "via":

Code:

192.168.1.0/24 dev wlp0s20f0u3 proto kernel scope link src 192.168.1.10 metric 600

nini09 08-15-2019 02:25 PM

If the two machines are in same network, not connected through a router, the gateway parameter isn't requested. But I guess these two machines are in different network and connect each other through a router.

supermario18b 08-15-2019 02:36 PM

Quote:

Originally Posted by nini09 (Post 6025484)
If the two machines are in same network, not connected through a router, the gateway parameter isn't requested

That's ok but I can't see that in the routing rule:

Code:

192.168.1.0/24 dev wlp0s20f0u3 proto kernel scope link src 192.168.1.10 metric 600
Here we have no gateway but all these machines are connected through a router. They all use the wireless interface.

Edit:
I mean, if pc1 (192.168.1.10) pings pc2 (192.168.1.20) the connection is through the router.

phil.d.g 08-15-2019 07:02 PM

It's time to read about the OSI model and how this stuff works.

Machines on the same LAN don't need to communicate via a router because they are connected directly, as far as IP and ethernet is concerned. The machine can resolve an IP address to a mac address, and send an ethernet frame to that mac address and the destination machine will receive it. If the machines are on different LANs, then they can't send each other ethernet frames. You can't route ethernet frames. The machine will send an ethernet frame containing the IP data for the destination machine to the router, it will extract the IP data and then construct another ethernet frame with the same IP data (with some minor amendments) and send the new ethernet frame on.

With respect to your wireless router. They do more than just routing. The routing function of your router isn't used to facilitate communication between machines on the same wireless network.

supermario18b 08-16-2019 02:59 AM

Thank you, now I got it :) I mark the thread as solved.


All times are GMT -5. The time now is 03:12 AM.