Networks vs Subnetworks
Asked Answered
P

3

13

Can a computer with an IP address of class C like 192.168.0.1 and subnet mask 255.255.255.0 communicate and share resources with another computer having the IP 192.168.1.1 and the same subnet mask 255.255.255.0 ? I'm asking this because the first 3 octets in this case tell us that these IPs are running on different networks (network 192.168.0.0 and network 192.168.1.0). Also, does "network" mean the same thing as "subnetwork" (or "subnet") in this context? Thank you!

Passerine answered 31/7, 2013 at 1:17 Comment(1)
Not really a StackOverflow question. You might do better on serverFaultLowdown
J
16

To fully understand how computer networks work, you need to take a look at OSI model (or in practice - TCP/IP or DoD model. For your question you need to look at first three layers: physical, data link and network.

Physical connection is self explanatory, and represents direct connection via some medium (copper, glass, air).

When a host A tries to send a packet to host B first thing it will do is look at the destination IP address and based on it's own IP configuration determine if host B is in the same subnet as a host A. This is done as Eugen Rieck explained to you already: subnet mask bits are used to mask the bits of the IP address (logical AND operation). Now, we have two cases:

  1. Host A and B are in the same subnet.
  2. Host A and B are not in the same subnet.

You should note that on layer 2, which network adapters use to send and receive frames, there is no IP addresses (which are present on layer 3) but instead the communication between devices is done by using MAC addresses. Because of that, host can directly communicate only with hosts in their subnet (1st scenario). For sending a frame host A needs the MAC address of host B. So host A first looks up the MAC address mapped to the IP address of host B in his ARP table. If he can't find it, it sends broadcast ARP request asking all host on the subnet who has that specific IP. If he gets a response it adds the MAC address of the host he got the reply from and builds a packet with destination MAC address of that host and IP address of that host.

If both hosts are not in the same subnet (2nd scenario) the packet is sent to default gateway which is responsible for finding a route to the destination. The crucial point to make here is that even if the destination MAC address in this case is the MAC address of the router (default gateway), the destination IP address is still the IP address of host B as in the first scenario. As the packet flows from router to router the source and destination MAC addresses will change, as they are locally significant, but the source and destination IP address will stay the same. This is how every layer provides a service (so to speak) to upper layers, and upper layers use it transparently without needing to know what is happening below.

So you have:

1st scenario.

----------------
L2:
Src MAC: host A
Dst MAC: host B
----------------
L3:
Src IP:  host A
Dst IP:  host B
----------------

2nd scenario:

----------------
L2:
Src MAC: host A
Dst MAC: router
----------------
L3:
Src IP:  host A
Dst IP:  host B
----------------

To sum it up (the answer @Eugen Rieck already gave you):

Two hosts which are not in the same subnet as in your example (192.168.0.1/24 and 192.168.1.1/24) will not be able to communicate on layer 2, and will require a L3 capable device such as router to act as a default gateway and to route the traffic between two networks (broadcast domains) for layer 3 connectivity.

Jaymie answered 31/7, 2013 at 16:57 Comment(2)
Thank you! Now I undestand why we need a router if we want to make 2 computers in different subnets communicate with each other. I also understand how to calculate the subnet ID. But how do we calculate the host ID? How do we get from the IP address only those bits which are set for the host ID? Or that isn't necessary, because the host is identified by using the whole IP address? (for example, the subnet ID is 192.168.0.0 and the host ID is 192.168.0.1 or the host ID is just "1" and the subnet ID is 192.168.0 ?).Passerine
Host will be 192.168.0.1, not just 1. Since the host is just one IP address you can also express it as a subnet with subnet mask of 255.255.255.255. Since the binary value of mask is all ones that subnet will have only one IP address (host IP) not the range. So they are actually calculated the same way.Jaymie
A
4

Yes and no:

Yes: Those two computers can communicate, if there is a (properly set up) router in between and both sides have knowledge of it.

No: Those two computers can not communicate, if simply wired to the same dumb switch.

Rule of thumb: IP & SNM must be identical for all participants to allow direct communication.

Appellative answered 31/7, 2013 at 1:22 Comment(7)
So they are on different networks and only a router can make them communicate. How can it do that? Just simply by setting the DHCP range to something like 192.168.0.1-192.168.1.255 ?Passerine
I am quite sure, you have a home router - which will most likely not allow that. The easiest way might be, to add a secondary IP address to one of the computers, e.g. add 192.168.1.2 to the computer having 192.168.0.1 . This is easy with all common operating systems.Appellative
This wasn't my point. I'm just trying to learn and understand some aspects about networking. This is a practical example of something I don't understand. The main question would be: what's that about networks and subnetworks? Why do we need different "networks"? For example, class C permits 2,097,152 networks!!Passerine
The definition of network and subnet are quite often not finely differentiated in language. It is really a hierarchy: network is commonly used as a domain boundary: Google's network or your network, which may consist of more than one subnet: In your example, your network consists of two subnets: 192.168.0.* and 192.168.1.* . Your network's subnets are connected by routers, and again connected to other networks (e.g. the internet) by routers (edge routers)Appellative
OK. And now having that in mind, those two IPs can't communicate with each other, correct? The condition for that to happen is that the two IPs should be from the same subnet, for example 192.168.0.1 and 192.168.0.2! This is what I understand! Is that correct?Passerine
They can communicate directly (i.e. without a router) only, if (bitwise) IP & SNM is identical, which is true for 192.168.0.1 and 192.168.0.2 . If you want to cross a subnet border, you need a router.Appellative
So what should be set for that at the router level?Passerine
L
3

You'd need to change the subnet mask to 255.255.254.0, or use a router or layer-3 switch to communicate.

Network generally means the whole network you're referring to, while subnet refers to a specific separate portion of it. However, the terminology is pretty loose.

Lowdown answered 31/7, 2013 at 1:20 Comment(2)
So they can't communicate if I'm using the 255.255.255.0 mask! I think that by using the 255.255.254.0 mask you were talking about, I'm giving an extra bit for the host and removing a bit from the network ID. I still don't get it. What are we talking about here? Different "networks" or different "subnets"?Passerine
You are correct: shortening the subnet mask effectively increases the host address size by one bit. Instead of two subnets in your network (192.168.0.0 and 192.168.1.0) you now have only one subnet in your network, but roughly twice the size. Rather than get inot an off-topic discussion here, take a look at this tutorial, then post any further questions on serverFaultLowdown

© 2022 - 2024 — McMap. All rights reserved.