0

I have some practice with networks, but not much theory. I saw in this question that netmask is not stored in the TCP/IP packet.

However, from my experience if I:

  • connect machine A to port 1 of router. Connect machine B to port 2 of router;
  • configure machine A IP to X.X.X.1/30 (If I'm thinking correctly, that subnet has IPs X.X.X.0-3 in it, 0 being the gateway and 3 being the broadcast);
  • configure machine B IP to x.x.x.2/24;
  • from machine A, ping machine B.

The machines won't be able to communicate. If however I put both netmasks on /30 they will be able to communicate.

My question is: does the packet from A arrives at B or is it filtered in the router? If it's filtered in the router (router knows netmasks), how does the router know about A's and B's netmasks?

If it arrives on B (router doesn't know about netmasks), this means that I can have multiple identical IP's and different subnets in the same router (for example, X.X.X.2/30 and X.X.X.2/24) but then this would mean that the router delivers the packet to both identical IP's and the machines themselves decide what to filter, which... feels wrong (at least it's a super usage of resources).

What am I understanding wrong?

1 Answer 1

1

netmask is not stored in the TCP/IP packet.

No, it's not. The netmask is a parameter of an interface binding, so it's stored in its config, in either router or host.

A netmask are also part of a routing table entry where it defines the prefix length. For directly attached networks that netmask is taken from the interface config.

configure machine A IP to x.y.z.1/30 [...] configure machine B IP to x.y.z.2/24

That would incidentally work because x.y.z.1 is part of x.z.y.0/24, and x.y.z.2 is part of x.y.z.0/30.

From either machine's perspective, the other one is within its own subnet. They can talk to each other locally and communication is possible.

However, x.y.z.1/30 could not talk to x.y.z.4/24 because that's not part of its x.y.z.0/30 subnet, requiring the use of a gateway. If there was a gateway, because routers usually don't forward packets back out of their ingress interface, that gateway would require explicit configuration.

router knows netmasks

All L3 nodes know netmasks. Each one needs to make a routing decision when sending (or possibly forwarding) a packet. After all, a host can be multi-homed, ie. attached to multiple networks, and needs to decide where and how to send a packet at hand.

this means that I can have multiple identical IP's and different subnets in the same router (for example, X.X.X.2/30 and X.X.X.2/24

That's not possible. You can't have a subnet x.y.z.0/30 when there's already a subnet x.y.z.0/24 because they overlap. If you try to configure that, the router won't accept it.

This excellent Q&A might also be useful to you.

2
  • Thanks so much for the answer. In this case, how does the router knows about the netmask? I understand that the router sends ARP requests and the machines answer these with their IPs. Does the answer also contain the netmask? Commented Jun 14 at 12:29
  • The router knows netmasks a) from its local interface configuration, b) from static routes configured by the admin, and c) from dynamic routes learned through a routing protocol like OSPF. ARP replies do not carry any netmask information nor would that be useful.
    – Zac67
    Commented Jun 14 at 13:08

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