Split the address space by hand
Goal
Dividing up address ranges is one of the hardest decisions to reverse. Here you divide ranges not with a calculator but by boundaries and lengths, and at the end you use that calculation to solve an incident in which one wrong prefix number isolated a single server.
Why it matters
The range of a VPC cannot be reduced after it is created, and a subnet cannot be deleted if it has resources in it. What you decide in the first 30 minutes lasts for years. And when a range calculation is wrong, the symptom arrives not as "the calculation is wrong" but as "only that server is acting strange", because the prefix decides whom that device considers its neighbors. Only if you can do the calculation by hand can you trace back from that symptom to the cause.
Materials
/opt/lab/netplan/allocations.txt 사내 대역 배정표
/opt/lab/netplan/routes.txt 어느 라우터의 표
Create the working directory /root/netplan, copy the two files there, and work inside it.
Steps
- This Pod's address, prefix, and default route, and what that prefix means →
/root/netplan/01-here.txt - A plan dividing
10.20.0.0/16into four/18s →/root/netplan/02-split.txt - Pairs in the allocation table that overlap each other →
/root/netplan/03-overlap.txt - The route and next hop that each of three destinations chooses →
/root/netplan/04-longest.txt - The number of addresses actually usable for each size →
/root/netplan/05-usable.txt - The ranges of private address space, which one each allocation belongs to, and places to avoid →
/root/netplan/06-private.txt - Incident
nw-neighbor: fix the isolated server's configuration and record the cause in/root/incident/nw-neighbor/report.txt
Notes
- Python's
ipaddressmodule is the basic tool for range calculations (ip_network,subnets,overlaps,in). - Incident tools:
incident list,incident nw-neighbor(raises the incident; raising it again returns it to its original state), andincident show nw-neighbor(shows the report again). The report is three lines:cause:,host:, andevidence:. - The lab Pod cannot change its routing table, so the incident's LAN is stood in for by configuration files and
nw-lan.nw-lanperforms exactly the calculations the kernel does (directly connected range, gateway check, longest prefix).
Where am I now
Create the working directory /root/netplan and copy the two material files (/opt/lab/netplan/allocations.txt and routes.txt) into it. Then save this Pod's IPv4 address, prefix, and default route to /root/netplan/01-here.txt, and write one line on what that prefix means.
Use ip -4 -o addr show and ip route.
If the prefix is /32, it means there is not a single neighbor in the same range. Even so, it can get out because there is a separate scope link route.
Divide along the boundaries
Divide 10.20.0.0/16 into four /18s and assign the first three to three AZs. In each AZ, take the first /24 as the public subnet. Leave the fourth /18 unused, and write why you leave it. Save the result in /root/netplan/02-split.txt.
Dividing a /16 into /18s uses 2 more bits, so you get four blocks, and one block is 2^(32-18) addresses, which is 64 at a time in the third octet. Work out the boundaries by hand, then check them with subnets(new_prefix=…) from Python's ipaddress.
For each /18, its first /24 is that /18's starting address with /24 attached.
Write why you leave the fourth one. A VPC range is cumbersome to expand later, and if there is no room to attach when an AZ is added or a new purpose arises, you have to pull in another range.
Find the overlapping pairs
Find all the pairs of ranges that overlap each other in allocations.txt and write them in /root/netplan/03-overlap.txt, and add one line on what is blocked when they overlap.
Two ranges overlap if one's start-to-end span overlaps the other's even a little; the most common case is a large range swallowing a small one whole. Check every pair in the allocation table without missing any (network objects in Python's ipaddress have a method that asks about overlap).
There are two overlapping pairs. You must not include ones that do not overlap: if you report an overlap where there is none, you end up re-planning perfectly good ranges.
Length decides, not order
Look at routes.txt and write in /root/netplan/04-longest.txt which route each of 10.20.4.200 · 10.20.9.5 · 172.20.1.1 goes out by. Include the next hop address as well.
The kernel does not look at the order of the table. If several routes match, it picks the one with the longest prefix.
10.20.4.200 matches both /24 and /25. 10.20.9.5 matches a scope link route, which means it does not go through a gateway.
How many you can actually use
For each of /24 · /25 · /26 · /28, write in /root/netplan/05-usable.txt, as a table, the total number of addresses and the number actually usable after the cloud reserves five, and add one line on where those five go.
The total is 2^(32-프리픽스) (where the Korean word means "prefix"). Most clouds take five per subnet: the network address, the gateway, DNS, a spare, and the broadcast.
The smaller the subnet, the larger the proportion of this loss. In a /28, five of the 16 disappear.
How far the usable space extends
Write all the ranges usable as private in /root/netplan/06-private.txt, and mark which private range each range in allocations.txt falls into. Then add one line on which places to avoid.
RFC 1918 defines three, and in addition there is one more range defined by RFC 6598. It is not private, but it is not routed over the Internet, so you can use it internally.
Also write down the places to avoid. 10.0.0.0/16 and 192.168.0.0/24 are ranges that everyone picks first, so they have the highest probability of overlapping with a peer you will someday need to connect.
Incident: of three machines, only one cannot talk to its neighbors
Running incident nw-neighbor leaves one of the three servers on the office LAN (10.40.1.0/24, gateway 10.40.1.1) unable to communicate with any neighbor server, the gateway, or db. This Pod cannot change a real routing table, so fix the three servers' configuration files /root/incident/nw-neighbor/lan/<web1|web2|web3>.conf, and check with nw-lan (check, show <호스트> (host), ping <호스트> <대상> (host, target)), which reads the configuration and does the same calculation as the kernel. You must not change the addresses (IPs) of the three servers; after the fix, every field of nw-lan check must be ok, and each server's range must also match the LAN design.
In /root/incident/nw-neighbor/report.txt, write cause: <코드> (code), host: <고장 난 호스트> (the broken host), and evidence: <nw-lan 출력 한 줄> (one line of nw-lan output). The candidate codes are duplicate-ip (two machines use the same address), gateway (the gateway address is wrong), overlap (a route overlapping the LAN intercepts traffic meant for neighbors), and prefix (the address's prefix differs from the LAN).
Direction: "who is my neighbor" is decided not by the other side but by the prefix of my own address. If the FAILs in the result table are concentrated in one host's row, put that host's configuration side by side with the other two and find the field that differs.
Tools: nw-lan's result table and per-host view, and the Python range calculation module you used in steps 3 and 4 (which calculates whether an address falls within a range).
Concretely: look at the address/prefix line in the per-host view and the directly connected route line (scope link) in the routing table, and calculate whether the neighbors (10.40.1.11, 10.40.1.12) and the gateway (10.40.1.1) fall inside that directly connected range. Nexthop has invalid gateway in the boot log means "the gateway is outside the directly connected range, so the default route could not be added". Before trusting that message and fixing the gateway line, first compare whether that line really differs from the other two.