Subnetting, VLSM and Supernetting
In questa pagina 3
In questa pagina 3
This note uses prefix, mask, network and broadcast addresses as defined in Network Layer and IPv4 AddressingThe network layer delivers datagrams host to host through routers (encapsulation, routing, forwarding); an IPv4 address is 32 bits split into a network prefix and a host suffix, and modern classless addressing (CIDR) gives a block of 2^(32-n) addresses from a.b.c.d/n, with network and broadcast addresses computed through the netmask.Network Layer and IPv4 Addressing →. In classless addressing the NetID/HostID boundary can move in either direction: moving it right gives subnetting, moving it left gives supernetting.
Subnetting
Definition. An organisation (or ISP) given a block can divide it into subnets, and each subnet can be divided again. This adds a level of hierarchy: NetID, SubnetID, HostID. The subnet mask has more 1 bits than the original mask (bits borrowed from the HostID). Each subnet is a full CIDR block with its own network and broadcast addresses.
Formula. From a network with prefix , borrowing bits for the SubnetID gives new prefix , subnets, each with addresses, i.e. usable hosts.
Example. with mask (): , so up to subnets of hosts, instead of one network with hosts.
Worked examples.
- . First byte 100: class A, . The mask says 28, so only bits are real host bits ( hosts) and the SubnetID has bits ( subnets). : subnet , broadcast .
- Subnets of at least 500 hosts from (class B). , so 9 host bits; SubnetID bits (up to 128 subnets); mask has ones: ; hosts per subnet.
- At least 1000 subnets from (class B). , so bits; remaining host bits (62 hosts); mask has ones: . More subnets means fewer hosts per subnet, since the total is fixed.
Design rules (variable-length masks, VLSM)
- The number of addresses of each subnet is a power of 2: for hosts take the smallest power of 2 with (network and broadcast are lost).
- Prefix length .
- The start address of a subnet must be divisible by . To guarantee this, assign subnets from the largest to the smallest: each size divides all the previous ones, so the running sum of sizes is automatically a multiple of the next size. Starting from small subnets wastes addresses.
Formula. , , .
100 hosts: , , broadcast network . Read the text: "10 addresses" means ; "60 hosts" needs so 64; 63 hosts need 128 ().
Full design: into subnets for 120, 60 and 10 hosts (the block has 256 addresses). Start from the largest:
- 120 hosts: , : , broadcast .
- 60 hosts: , : ( is a multiple of 64), broadcast .
- 10 hosts: , : ( is a multiple of 16), broadcast .
- Free: to (48 addresses).
| prefix | mask | addresses | hosts |
|---|---|---|---|
| /20 | 255.255.240.0 | 4096 | 4094 |
| /21 | 255.255.248.0 | 2048 | 2046 |
| /22 | 255.255.252.0 | 1024 | 1022 |
| /23 | 255.255.254.0 | 512 | 510 |
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /29 | 255.255.255.248 | 8 | 6 |
| /30 | 255.255.255.252 | 4 | 2 |
A /30 is the typical choice for a point-to-point link between two routers (2 usable hosts, no waste); a /31 would have 0 hosts.
Supernetting
Definition. The dual of subnetting: several small contiguous blocks are merged into one larger block by shortening the prefix. In routing tables this is route aggregation.
Property. blocks of prefix can be replaced by one block of prefix if and only if they are (a) contiguous, (b) exactly in number, (c) the first address is a multiple of the aggregate size .
Example. , , , are contiguous, , and is a multiple of 4: they merge into (mask , addresses). In binary the third bytes are , so the two low bits become host bits.
Counterexample. and are contiguous but cannot become a /23: is not a multiple of 2 (the /23 blocks are - and -).
Example. and (, multiple of 128) merge into , from to (126 hosts).
With aggregation an ISP announces one line (e.g. ) instead of one per customer; routing still works thanks to the longest prefix match (Forwarding and Routing TablesForwarding moves each packet one hop at a time toward its destination; it is direct when the destination is on a local network (ARP gives its MAC) and indirect otherwise (the packet goes to the next hop or default gateway given by the routing table). With netmasks, delivery is direct on interface x if the destination AND the mask equals the interface address AND the mask; otherwise the table is scanned from the longest mask (longest prefix match) and the default route 0.0.0.0/0 always matches; route aggregation shortens tables.Forwarding and Routing Tables →).
Versione ripasso
Subnetting
- Block divided into subnets: NetID, SubnetID, HostID; mask gets more 1 bits.
Borrow bits: , subnets of addresses ( hosts).
- with : , 256 subnets of 254 hosts.
- : real host bits 4 (14 hosts), SubnetID 20 bits; subnet , broadcast .
- 500 hosts from : 512 addresses, 9 host bits, (), 510 hosts, 128 subnets.
- 1000 subnets from : , (), 62 hosts.
VLSM rules
- smallest with . 2. . 3. Start address divisible by : assign largest first.
, , broadcast network .
- for 120, 60, 10 hosts: (bc ), (bc ), (bc ); free -.
- Host versus address wording: 10 addresses ; 60 hosts ; 63 hosts .
- /30 for point-to-point links; /31 has 0 hosts. Sizes: /24 254, /25 126, /26 62, /27 30, /28 14, /29 6, /30 2 hosts.
Supernetting
- Merge contiguous blocks, shorten prefix (route aggregation).
blocks of prefix merge into prefix iff contiguous, exactly , first address multiple of the aggregate size.
- to gives (, 136 multiple of 4). plus do not make a /23. plus give .
- Typical errors: mixing hosts and addresses; forgetting the 2 reserved addresses; assigning small subnets first; aggregating unaligned blocks.