Why aren't public IP addresses always displayed with their subnet mask?

1

I've been told that a public ip address without its corresponding subnet mask is meaningless, because one couldn't know how to split the network id from the host id, which makes total sense to me.

However, most of the time I see ip addresses (DNS, findmyip.com etc.) it's only about ip without the cidr number. For example, I just fed a website just an ip address and it gave me back the right domain name.

What am I missing ? I'm guessing there are some other protocols that can only work with ip addresses but I haven't heard of those yet.

If my question reveals a lack of basic understanding of how networks work, ressources are much appreciates. I'm a developper teaching myself all of this stuff, and except 5-min-long tutorials or 1000+ obscure books (Hi TCP Illustrated), I can't find the material i'm looking for.

Radioreve

Posted 2017-10-04T10:25:13.340

Reputation: 111

1The effective subnet mask for an IP address outside your local network is always /32 (for IPV4; it's /128 for IPV6), so quoting it would be redundant – Mike Scott – 2017-10-04T10:51:36.583

Answers

4

All systems that use TCP/IP to talk to other systems consult a local "Fowarding Information Base" or local routing table which is maintained by the system.

A routing table entry basically looks like this:

Destination Network / Gateway / Destination Subnet Mask / Metric

Here's my current routing table:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    100    0        0 eth2
link-local      0.0.0.0         255.255.0.0     U     1000   0        0 eth2
172.16.160.0    0.0.0.0         255.255.255.0   U     0      0        0 vmnet8
192.168.2.0     0.0.0.0         255.255.255.0   U     100    0        0 eth2
192.168.87.0    0.0.0.0         255.255.255.0   U     0      0        0 vmnet1

Each time the system wants to send traffic out to an IP, it searches this table. If it finds a destination network that matches and fits within the subnet mask, it sends traffic out of the network adapter identified by Iface.

All of these network adapters are "directly connected" - so that's why you see 0.0.0.0 for gateway. This means if the system wants to send something to 192.168.2.80, for example, it can just send it directly to 192.168.2.80 via interface eth2.

However, because of the subnet mask, 192.168.87.80 would not go out through eth2, it would go out through vmnet1.

If an IP will fit in two entries, the one with the larger CIDR subnet mask (the "more specific one") is used. If there are two with the same subnet mask, the metric is used to break the tie, and if that's the time, the system may pick one and stick with it or load balance between them.

e.g.

192.168.2.0     0.0.0.0         255.255.255.0   U     100    0        0 eth2
192.168.2.0     0.0.0.0         255.255.255.240 U     100    0        0 ethX

255.255.255.240 is a CIDR /28, and 255.255.255.0 is a CIDR /24. So if the two entries existed, something going out to 192.168.2.1 would go out of interface ethX, but something going out to 192.168.2.241 would go out of interface eth2.

What if nothing matches? Then the default gateway is used. Notice it has the the "lowest" subnet mask of 0.0.0.0 (which is a slash /0).

So that's what the subnet is for. Telling the system which networks can be reached by which interface. Your system uses this when sending traffic out (to determine difference between Internet and local network) and routers use this to forward traffic.

Outside of those situations the subnet mask is not needed. It's not needed past the network routing layer, basically. HTTP is application layer.

LawrenceC

Posted 2017-10-04T10:25:13.340

Reputation: 63 487

3

The subnet mask is useful for the host itself and to the routing equipment.

Your PC doesn't need to know the subnet mask of a remote device, it only needs to know the address and comparing with its own address and its own subnet mask it will know if the address is local or remote.

If it's local then the packets will be sent directly, if it's remote the packets will be sent to the default gateway.

jcbermu

Posted 2017-10-04T10:25:13.340

Reputation: 15 868

0

Both the above answers are correct - here is a more detailed non technical one-

A computer only needs to know if an IP address belongs to a computer which connects directly to it - and computers going through a hub/switch/wifi in the same "lan") are considered directly connected.

For anything else, the computer only needs to know where to send the packet to next - ie the address of the router (which in turn knows where to send packets next). When you do a traceroute you are seeing this path.

The subnet mask is used to group machines which are directly connected - so for machines which are not directly connected a subnet mask is not required to reach them.

Notably a subnet mask can also be used by a firewall or other software to specify a group of IP addresses to be treated the same way - which is why they are sometimes relevant outside a LAN - but not necessary for generally communicating on the Internet.

davidgo

Posted 2017-10-04T10:25:13.340

Reputation: 49 152

1Formal note: any user (or guest) can change the order of answers (sorting by active, oldest, votes). The phrase "both the above answers" makes little sense then. – Kamil Maciorowski – 2017-10-04T15:46:25.130