LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 08-13-2019, 12:44 PM   #1
supermario18b
LQ Newbie
 
Registered: Sep 2018
Posts: 14

Rep: Reputation: Disabled
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
 
Old 08-13-2019, 04:08 PM   #2
supermario18b
LQ Newbie
 
Registered: Sep 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
Maybe the right question to simplify would be:

When is the "via" option of ”ip route” command obligatory/needed?
 
Old 08-14-2019, 02:52 PM   #3
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,719

Rep: Reputation: 143Reputation: 143
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.
 
Old 08-14-2019, 08:05 PM   #4
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,265

Rep: Reputation: 139Reputation: 139
Quote:
Originally Posted by supermario18b View Post
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
 
Old 08-15-2019, 02:32 AM   #5
supermario18b
LQ Newbie
 
Registered: Sep 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by phil.d.g View Post
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
 
Old 08-15-2019, 02:25 PM   #6
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,719

Rep: Reputation: 143Reputation: 143
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.
 
Old 08-15-2019, 02:36 PM   #7
supermario18b
LQ Newbie
 
Registered: Sep 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by nini09 View Post
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.

Last edited by supermario18b; 08-15-2019 at 02:40 PM.
 
Old 08-15-2019, 07:02 PM   #8
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,265

Rep: Reputation: 139Reputation: 139
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.
 
Old 08-16-2019, 02:59 AM   #9
supermario18b
LQ Newbie
 
Registered: Sep 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
Thank you, now I got it I mark the thread as solved.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[HOWTO] A quick explanation of routing setup with OpenVPN tunnels sundialsvcs Linux - Networking 1 11-29-2016 10:58 AM
I have to know the Explanation for DoS IPtables Rule.? Ganeshgm7 Linux - Security 4 08-24-2015 05:59 AM
iptables: rule with RETURN target just after a rule with ACCEPT target Nerox Linux - Networking 6 09-04-2011 03:33 PM
[SOLVED] Snort - DynamicPlugin: Rule [##] not enabled in configuration, rule will not be used mhollis Linux - Software 3 08-29-2011 06:06 PM
Routing route and iptables [need explanation] Hyakutake Linux - Networking 4 03-09-2011 11:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration