1

Let's say I start a new company and lease a block of IP address 222.123.123.0/25 from Internet registry, so one of those IP address 222.123.123.4 is my main web server.

A customer from a different country wants to send a packet to this IP address, how does the the router (an ISP's router at his country) know what is the network prefix of this IP address 222.123.123.4? Because classful IP addressing is deprecated, when it comes to CIDR IP addresses, it can be 222.123.123.4/25, 222.123.123.4/26, 222.123.123.4/27 etc., and IP header certainly doesn't have a header called network prefix.

So how does the router determine the network prefix of an IP address?

7
  • why would an ISP router need the network prefix? Commented Jun 13, 2023 at 3:46
  • @JaromandaX then how does the ISP router know what is the network prefix of an ip address? or if ISP router has a routing table that contain the rules that how to route ip address with network prefix, then how does this rule (contain network prefix) populated from local Router up the way up to a different country's ISP router?
    – whoisit
    Commented Jun 13, 2023 at 4:15
  • BGP is complex. And you may be right, your 222.123.123.0/25 may well be one of the countless routes in the BGP tables somewhere Commented Jun 13, 2023 at 4:19
  • @JaromandaX thanks for your answer, and so when 222.123.123.0/25 is assigned to me, do I need to manually enter the network prefix "/25" info into the my localrouter? or my local router can somehow query Internet registry and get that "oh, 222.123.123.4 's network prefix is /25
    – whoisit
    Commented Jun 13, 2023 at 5:07
  • 1
    you configure it to be so Commented Jun 13, 2023 at 6:42

1 Answer 1

1

Your router knows the prefix length because you configure it. Whenever an interface is configured with an address, whether on a host or on a router, the prefix length (or the equivalent netmask) is entered alongside it.

It's functionally the same as IPv4 configuration for your Windows PC at home – the PC knows it's 192.168.1.x/24 because it has "Netmask: 255.255.255.0" filled in; the router knows it's .123.1/25 because you (or the ISP) had to specify the "/25" when doing ip addr add.

Distant routers either a) do not care or b) will learn a route towards your /25 as you advertise it via BGP to your upstream ISPs, and the same BGP advertisement includes the route prefix length together with the network address. All routing protocols in use today have been extended to carry the prefix length – that's the whole point of the "CIDR" effort.

Note however that distant routers only care about the route prefix, at most. They do not care about your subnet size – the BGP advertisement may cover multiple of your subnets (an aggregate route), or it may cover half a subnet, none of it makes any difference for the packet delivery.

Things like "reserved for broadcast" addresses do not enter into play here, so packets to ".0" and ".255" addresses will just be forwarded without any special treatment (the destination might not even be a broadcast-capable subnet at all; it might be a /31 or /32 PtP link where any address is valid).

(The decoupling of routes and subnets happened even before CIDR – it's literally why the "subnet mask" is called a sub-net mask; it used to be that BGP continued carrying only classful routes for quite a while even as the operators already had their classful networks internally subdivided into classless subnets.)

This means a host or a basic CPE router can just have a single 0.0.0.0/0 route (the "default" route) and will absolutely not care about whether some distant network is /25 or something else.

In most cases, ISPs will only advertise aggregate routes via BGP and not individual subnet routes – it's generally frowned upon to do otherwise, as the global BGP tables are already large. (In fact, you're not even allowed to advertise an IPv4 /25 on the public Internet; ISPs only accept advertisements for /24 or larger, or similarly /48 for IPv6.)

In other words, there's no "Network prefix" field in IP headers because the only device that needs to know it – the final router at your site – already has that information configured explicitly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .