It has been a while since I looked into networks, but i'll give it a shot.
this you wrote here
"the modem will act as router (do switching)" is a nonsense you
should call it a router/switch/modem"
that is a complete nonsense
You can call the device a router/switch/modem, and when it acts as a router it's routing, when it acts as a switch it's switching, and when it acts as a modem it's acting as a modem(modeming is not a word, unfortunately, though you could invent it).
And you basically ask that for the on-link case, PC1 PC2 same subnet, does the routing table get checked. (Also bear in mind that the routing table you showed is that on PC1, not on the router. Also, PC1 isn't what most would consider to be a router, since it doesn't have data coming in one interface and out another). The packet will hit the switch part of the device first. The routing table on your router won't have PC2's IP address. The 'packet' from PC1 will first hit the switch, and then get redirected to PC2, and not hit the router. PC1 put PC2's MAC address in there, because PC1 checked whether PC2 was on te same subnet and since it was it put PC2's MAC in the 'packet'(or one might say, frame). If PC2 had not been on the same subnet then it would have put the router's MAC address in the 'packet'(Where I use the term packet in quotes, I mean the general sense, rather than the OSI ISO sense, so, I mean whatever field regardless of 'layer'). I think the case where it'd hit the router, would be, from PC1 to the internet or vice versa, or, consider a router with multiple interfaces, not just the two that a 'home/SOHO' one has, then if you sent a packet from one directly connected subnet to another, or a packet came from the internet to a directly connected subnet, then the packet would go past the switch, to the router, to e.g. a switch, then to the computer. But for PC1 to PC2, the routing table won't be used. The router part of the device won't be used.
You write
Am i right that when i run ping command on PC1 it directly communicate
with PC2 - it sends ARP datagram to PC2 to get it's MAC address?
Firstly, bare in mind that ping operates above IP, and ARP operates below IP.
So a ping can potentially hit a router.
And bare in mind that Ping is ICMP.
It will only do ARP if it doesn't have the MAC address.
Technically an ARP broadcast would hit every device, including the router. 'cos anything with a L3 address(e.g. IP) also has a L2 address(e.g. MAC). But ARP would never be routed.
The ARP request will hit the switch so I wouldn't call it going directly from PC1 to PC2.. Though PC1 will address PC2 using both the L3 address and the L2 address. So it will address PC2 directly.
You write
"What'll happen when i change the route's 192.168.0.11 Gateway to
192.168.0.1?"
Well, your PC1 has a routing table as you can see netstat -rn
shows a table like you see.. It does more if you were using it more like a router so having packets coming in and going out, rather than the perhaps only slightly routerish use of just packets going out.
That 192.168.0.11 is your PC1's IP.
And the column heading that you skipped out of your PC1's routing table is 'Interface'.
e.g. for me on my "PC1" (with a slight change to make my gatewy address the same as yours, for simplicity)
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.0.1 192.168.1.117 25
one wouldn't normally change that interface IP.. one might change one's IP though and then that should update. One could change it but if one did, one would change it for the IP of another directly connected interface of the device. So, not your gateway's IP. (gateway is another term for router..it's a slightly older term in the RFCs. ).
It'd just be a nonsense if you tried to change it to 192.168.0.1 because PC1 has no such interface. It's not its IP. Or an IP of any of its network interfaces.
So if you look throughout the interface column, you don't get any IP that is not associated with PC1. (I see a 169. address but that sometimes gets assigned when it can't get an IP. It's still an IP associated with the computer I ran the netstat -rn
command on)
And on a SOHO router with its two interfaces, you wouldn't get anything other than those, and the local interface of 127.0.0.1
added
I see I have this line too related to my interface 192.168.1.11. I'll show it here. And that second line relates to the one you showed in your question
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.0.1 192.168.1.117 25
192.168.1.117 255.255.255.255 On-link 192.168.1.117 281
Thx. for reply. I'm afraid you've misunderstood me. I talk about changing Gateway not Interface (question #3). In such a case am i right that PC1'll ask for the MAC address the router(192.168.0.1) instead of PC2? – Mulligan – 2016-05-31T06:49:55.353
@Mulligan In that table you showed, 192.168.0.11 is not a gateway. So I don't know what you mean when you refer to a "192.168.0.11 Gateway". It's an interface on PC1. – barlop – 2016-05-31T14:02:23.710
@Mulligan ah I see what you mean you mean the gateway for that route of 192.168.0.11/255.255.255.255 i'd have to think a bit 'cos it has been a while. – barlop – 2016-05-31T14:05:55.650
@Mulligan No it won't route it to PC2. That table in my answer is
netstat -rn
on my pc1. See where it says "network destination", if the destination IP is 192.168.1.117 then it will use that root where the network destination is 192.168.1.117 So that's for if I was to ping myself using that IP. But let's say I was to ping somebody else, then it won't use that route, it will use the 0.0.0.0 route. If you were from PC1, to ping PC2 then it would use the route with network destination of 0.0.0.0 You have not included that route in the table in your question. – barlop – 2016-05-31T14:14:53.073