5

Let us say, i have two computers (hosts) A and B. Where A has been assigned an IP address of 192.168.1.10/24 and host B has been assigned an IP address of 192.168.2.11/24. And both of them has been connected to each other over a Ethernet cross-over cable.

Now I see that both the computers can't communicate with each other! Ping fails from either sides. I am simulating this using Cisco Packet Tracer.

Could someone explain why there is a problem here? Why can't two hosts communicate here?


To give more clarity to the question i am adding the visualization.

enter image description here

Default gateway address is set to 192.168.1.1 and 192.168.2.1 respectively on host A and host B


PS: After seeing lot of answer my fellow community members' response, i would like to make it clear that - I understand placing a router between the 2 hosts would make it work. However I was looking for a technical reason why the networked system with the above mentioned topology fail to work! I was looking at what are all the protocol that are triggered in this scenario for the communication between the hosts A and B and which protocol would fail and for what reason.

  • @RonMaupin This I understand and knew. What you are telling is HOW could you solve the problem. I'm looking for WHY the problem is happening. I want to understand what is happening under the hood. – Darshan L Mar 17 '18 at 18:44
  • As I tried to explain before, under the hood of a host (PC/server/VM) is the OS, and what a host OS does, or does not do, is off-topic here. – Ron Maupin Mar 17 '18 at 18:52
  • In your example, there are two hosts, each with one NIC, with the IP settings as described? And no other NICs ? – Criggie Mar 17 '18 at 20:00
  • "However I was looking for a technical reason why the networked system with the above mentioned topology fail to work!" I explained that in my answer. A host knows that the destination address is on a different network, so it will not try to send it to the destination host, but to a router, and you don't have a router. It's pretty simple. – Ron Maupin Mar 18 '18 at 3:42
  • @RonMaupin You are right. As a human by looking at the topology i could say there is no router. From the machine perspective, I was wondering how the host would figure out that there is no router. What protocol it would use, is what i was looking for. Anyways, i figured it out. And i have written it down as answer below. – Darshan L Mar 18 '18 at 3:58
6

A host knows if the destination address is on a different network (the same way that you do, by masking the host and destination addresses with the host mask). If the destination is on the same network, then it will send the layer-3 packet in a layer-2 frame directly to the destination, otherwise it will send the layer-3 packet in a layer-2 frame directly to its router. Routers are what route packets between networks. For a host on one network to reach a host on a different network requires a router to route the packets between networks.

A router will look at the destination layer-3 address, and it will look in its routing table to see if it has a path to the destination network. If it does not, it drops the packet, otherwise, it forwards the packet out the interface toward the destination.

  • Yes, so it needs to send the frame to its router. And it gets its router information/IP address through default gateway address configured in the host. (assume that i had configured my host's default gateway address to say, 192.168.1.1). But in our case, there is no router physically placed between the 2 hosts, so how does the network discover that there is no router? Would that be using ARP protocol? – Darshan L Mar 17 '18 at 19:01
  • For IPv4 and ethernet, then the host may use ARP. The network does not discover that there is no router. – Ron Maupin Mar 17 '18 at 19:04
  • With IPv4 there's usually no router discovery. Most often, the default gateway is either configured by DHCP or statically on the host. With no gateway, no remote subnet can be communicated with. – Zac67 Mar 17 '18 at 19:11
3

Well, figured out the problem with this topology - WHY part of the question.

When the host A identifies that the destination IP address 192.168.2.2/24 is in a different network (since its own (source) IP address is 192.168.1.2/24). It decides to send the data through the default gateway (DG). Host A has been statically configured to reach DG at 192.168.1.1 (even though it doesn't physically exists). Now host A tries to find the MAC of DG by sending an ARP request (to forward the Ethernet frame). Since there is no DG, there won't be an ARP reply. Hence host A can't even take the first step of forwarding the data to the DG and as a result host A can't reach host B at all in this case.

  • 1
    I recognize that image =). But yes, you are correct. Because the IP addresses are in different networks, Host A will attempt to send a packet to Host B via a Default Gateway -- if no DG exists (as detected by the failed ARP attempt), then Host A will never no way of speaking to any IP on a foreign network, despite being directly connected to its intended target. For more info on ARP, check out this video. If you're content with your answer, mark it as the accepted answer. – Eddie Mar 18 '18 at 18:53
  • @Eddie Thanks for sharing that link. Worth having a look. – Darshan L Mar 19 '18 at 2:25
  • 1
    @Eddie I tried accepting, but it says 48 hours should have elapsed to accept. – Darshan L Mar 19 '18 at 2:27
2

Whether the two hosts are in the same layer 2 segment (by switch or direct link) or not is not important - if they are in separate layer 3 subnets they require a router to talk to each other.

When A (192.168.1.1/24) wants to send a packet to B (192.168.2.1/24) it first has to find out which interface as has to use, and whether a router is required (and which one).

For this, A tries to find the destination IP address in its local routing table:

192.168.1.0/24 -> 192.168.1.1

If there was a default gateway entry (e.g. 0.0.0.0/0 -> 192.168.1.254) that entry would ultimately match any destination address. But there isn't.

A can't find any route to the destination and has no other choice than drop the packet. It returns a no route to host error back to the application and that's it.

Only when they are in the same subnet they'll attempt using their common L2 segment to talk to each other. Put in another way: A and B don't know that they have a common link because their L3 subnets tell them otherwise.

Unless you trick them into thinking they're using a router when they're actually not or you decrease the network mask size to put the into the same subnet, they need to have a router that's connected to each of their subnets.

1

There are many ways to make this work. Here's a list, with a short explanation.

  • Expand the netmask for both sides. This will allow the other host to be in the local network, and not require routing via the default gateway. This is easiest and the smallest change.
  • Move one host to the same IP network as the other. That means changing the .1. host to .2. or vise versa. Downside here is that a host will change IP which may not suit you.
  • You could add a second NIC to each host, connect them, and give new IP addressing that is unrelated. IE host1 could have 192.168.234.1/29 and host2 could have 192.168.234.2/29 There is no default gateway set on this new network, so it will only route IPs in the IP network range.
  • Proxy ARP on the default gateway for both devices might fix this, but its a poor solution and not recommended. This will allow whatever device is the default gateway for both 192.168.1.0/24 and 192.168.2.0/24 to "lie" and present its own MAC address to an ARP request. Assumes that there is a default GW and its the same device for both networks. Not really recommended.

IPv6 won't help you - it will suffer from the same conditions that stopped IPv4 working, unless the network matches one of the changes above.

Did I miss any other "fixes" ? Feel free to comment.

  • Apparently, he doesn't want to solve the problem, he just wants to know why there is a problem. See the first comment under the question. – Ron Maupin Mar 17 '18 at 20:19
  • 3
    @RonMaupin fair point - that's why I included the "why this change would solve the problem" bit. SE is about building long-term useful answers, just chatting with OP about their question isn't really long-term useful to others. – Criggie Mar 17 '18 at 20:39
  • 1
    I think that something like that will work as well : add a static route to 192.168.2.0/24 with an exit interface + add static ARP for 192.168.2.2 - and wise-versa – sergeyrar Mar 19 '18 at 9:13
  • @sergeyrar Honestly? I dunno, but its totally worth trying. I'm not sure if an existing record in the ARP table trumps the default gateway. You'd have to do the inverse on the other machine as well. – Criggie Mar 19 '18 at 9:46
  • 2
    @Criggie, I don't know about ARP, but 192.168.2.0/24 sure is more specific than the default route. – sergeyrar Mar 19 '18 at 11:50
1

IP (or more precisely, ICMP, the protocol used by ping) and Ethernet are two completely different protocols on completely different layers of the networking stack.

They can talk to each via Ethernet (because they are in the same broadcast domain), for example using the ARP protocol, but they can not talk to each other via IP (because they are in separate subnets), for example using the ICMP protocol.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.