Showing raw Markdown: the renderer could not load.
## Goal
You read your own computer's IPv4 configuration (address, prefix, gateway and where it came from), check the lesson's calculations with Python's `ipaddress` module, and write a small script that classifies addresses by purpose. Nothing on your network is changed.
## Objectives
- Find your IPv4 address, prefix length, subnet mask and default gateway on Linux, macOS or Windows.
- Tell whether your address was configured statically or by the Dynamic Host Configuration Protocol (DHCP).
- Calculate network address, broadcast address and usable host range, and confirm them with Python.
- Classify IPv4 addresses as private, public, shared (Carrier-Grade Network Address Translation, CGN), loopback, link-local, documentation, multicast or broadcast.
- Explain why Python's `is_private` flag is broader than "RFC 1918".
## Prerequisites
- A computer running Linux (with the `ip` command from iproute2), macOS, or Windows 10/11.
- Python 3.8 or later, standard library only. This lab was tested with Python 3.14.7 and 3.11.8. Check yours with `python3 --version` (on Windows: `py --version`).
- A text editor.
- No administrator rights: every command in this lab only reads configuration.
- [Lesson: IP Addressing](lesson.md) of this module.
> [!WARNING]
> Your own addresses, gateway and lease details describe your network. Don't post the output of these commands in public forums or screenshots. When you share results, replace the values with documentation addresses (`192.0.2.0/24`, `198.51.100.0/24`, `203.0.113.0/24`).
## Architecture
<figure class="diagram" style="--dg-w: 940px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 940 300" width="940" height="300" role="img" aria-labelledby="ip-lab-architecture-title ip-lab-architecture-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="ip-lab-architecture-title">Lab architecture: where each address lives</title>
<desc id="ip-lab-architecture-desc">Your computer has a private address such as 192.168.1.23/24 on your local network. Your router is its default gateway at 192.168.1.1, hands out addresses with DHCP and translates them with NAT. On its public side it connects to your Internet service provider with a public address, or with an address from 100.64.0.0/10 if the provider uses carrier-grade NAT, and from there to the Internet.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="939" height="299" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<g class="dg-l2"><rect class="dg-tint" x="20" y="20" width="470" height="260" rx="16" fill="#f1f7f3" stroke="#a1ccb1" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(36 33) scale(0.7500)" fill="none" stroke="#15803d" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="11" width="16" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></g>
<text x="62" y="47" font-size="13" class="dg-ink" fill="#15803d" font-weight="700">Your LAN · private addresses (RFC 1918)</text></g>
<g class="dg-l1"><rect class="dg-tint" x="500" y="20" width="420" height="260" rx="16" fill="#f0f6f9" stroke="#9ac3d9" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(516 33) scale(0.7500)" fill="none" stroke="#0369a1" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></g>
<text x="542" y="47" font-size="13" class="dg-ink" fill="#0369a1" font-weight="700">Public side</text></g>
<rect class="dg-card" x="44" y="90" width="200" height="130" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(60 106) scale(1.2500)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 16V7a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v9m16 0H4m16 0 1.28 2.55a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45L4 16"/></g>
<text x="102" y="127" font-size="15" class="dg-text" fill="#17171c" font-weight="700">Your computer</text>
<text x="62" y="158" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192.168.1.23/24</text>
<text x="62" y="178" font-size="13" class="dg-muted" fill="#5c5c68" font-weight="500">Private address</text>
<rect class="dg-card" x="300" y="70" width="172" height="190" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(316 86) scale(1.2500)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6.01 18H6"/><path d="M10.01 18H10"/><path d="M15 10v4"/><path d="M17.84 7.17a4 4 0 0 0-5.66 0"/><path d="M20.66 4.34a8 8 0 0 0-11.31 0"/></g>
<text x="358" y="107" font-size="15" class="dg-text" fill="#17171c" font-weight="700">Your router</text>
<text x="318" y="138" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192.168.1.1</text>
<g class="dg-l3"><rect class="dg-solid" x="318" y="152" width="132" height="26" rx="13" fill="#b45309"/><text x="384" y="169.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">Default gateway</text></g>
<g class="dg-l7"><rect class="dg-solid" x="318" y="184" width="103" height="26" rx="13" fill="#6d28d9"/><text x="369.5" y="201.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">DHCP server</text></g>
<g class="dg-l4"><rect class="dg-solid" x="318" y="216" width="46" height="26" rx="13" fill="#c2410c"/><text x="341" y="233.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">NAT</text></g>
<rect class="dg-card" x="540" y="80" width="220" height="150" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(556 96) scale(1.2500)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4.9 16.1C1 12.2 1 5.8 4.9 1.9"/><path d="M7.8 4.7a6.14 6.14 0 0 0-.8 7.5"/><circle cx="12" cy="9" r="2"/><path d="M16.2 4.8c2 2 2.26 5.11.8 7.47"/><path d="M19.1 1.9a9.96 9.96 0 0 1 0 14.1"/><path d="M9.5 18h5"/><path d="m8 22 4-11 4 11"/></g>
<text x="598" y="117" font-size="15" class="dg-text" fill="#17171c" font-weight="700">Your ISP</text>
<text x="558" y="148" font-size="13" class="dg-muted" fill="#5c5c68" font-weight="500">Internet service provider</text>
<text x="558" y="168" font-size="13" class="dg-muted" fill="#5c5c68" font-weight="500">Public address</text>
<g class="dg-warn"><rect class="dg-tint" x="558" y="186" width="182" height="26" rx="13" fill="#f8e8e8" stroke="#e09999" stroke-width="1.2"/><text x="649" y="203.5" font-size="12" class="dg-ink" fill="#b91c1c" font-weight="700" text-anchor="middle">or 100.64.0.0/10 (CGN)</text></g>
<circle class="dg-card" cx="852" cy="150" r="40" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(834 132) scale(1.5000)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></g>
<text x="852" y="214" font-size="14" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Internet</text>
<path class="dg-line" d="M244 155H296" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M289 149l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M472 155H536" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M529 149l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M760 155H808" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M801 149l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
</svg></figure>
*Figure 1. Where each address lives. Everything on the left is your private network; the router translates between it and the public side. The example values are typical of a home network; yours may differ.*
*You inspect only the left-hand box. The values shown are examples; yours will differ.*
## Steps
### Step 1 — Create a working folder
You'll write two small scripts. Keep them in one folder so cleanup is a single command.
Linux and macOS:
```bash
mkdir -p ~/ip-lab && cd ~/ip-lab
```
Windows (PowerShell):
```powershell
New-Item -ItemType Directory -Force "$HOME\ip-lab"; Set-Location "$HOME\ip-lab"
```
No output means success (PowerShell prints the new folder's details).
### Step 2 — Find your address, prefix and gateway
These are the four values every host needs. Run the commands for your operating system and fill in the table at the end of this step.
**Linux.** Show IPv4 addresses, then the default route:
```bash
ip -4 addr show
ip route show default
```
Expected output (your interface names and values differ):
```text
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
inet 192.168.1.23/24 brd 192.168.1.255 scope global dynamic noprefixroute eth0
valid_lft 86077sec preferred_lft 86077sec
default via 192.168.1.1 dev eth0 proto dhcp src 192.168.1.23 metric 100
```
The `inet` line gives address and prefix together (`192.168.1.23/24`). Ignore `lo`: that is the loopback interface. The `default via` line gives the gateway.
**macOS.** Find the interface that carries the default route, then its address:
```bash
route -n get default
ifconfig en0 | grep "inet "
```
Expected output (abbreviated; replace `en0` with the `interface` value from the first command):
```text
route to: default
destination: default
mask: default
gateway: 192.168.1.1
interface: en0
…
inet 192.168.1.23 netmask 0xffffff00 broadcast 192.168.1.255
```
macOS shows the mask in hexadecimal: `0xffffff00` is `ff.ff.ff.00` = `255.255.255.0` = `/24`.
**Windows (PowerShell).**
```powershell
ipconfig /all
Get-NetRoute -DestinationPrefix 0.0.0.0/0
```
Expected output (abbreviated):
```text
Ethernet adapter Ethernet:
…
DHCP Enabled. . . . . . . . . . . : Yes
IPv4 Address. . . . . . . . . . . : 192.168.1.23(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Lease Obtained. . . . . . . . . . : Wednesday, 4 November 2026 08:12:40
Lease Expires . . . . . . . . . . : Thursday, 5 November 2026 08:12:40
Default Gateway . . . . . . . . . : 192.168.1.1
DHCP Server . . . . . . . . . . . : 192.168.1.1
DNS Servers . . . . . . . . . . . : 192.168.1.1
ifIndex DestinationPrefix NextHop RouteMetric ifMetric PolicyStore
------- ----------------- ------- ----------- -------- -----------
12 0.0.0.0/0 192.168.1.1 0 25 ActiveStore
```
`0.0.0.0/0` is the default route: "every destination not matched by a more specific route."
> [!NOTE]
> Exact wording, column spacing and date formats vary with the operating system version and display language. If you see several adapters (Wi-Fi, Ethernet, VPN, virtual machine adapters), use the one whose gateway matches the default route.
Record your values:
| Value | Yours |
|---|---|
| IPv4 address | `<address>` |
| Prefix length / mask | `<prefix>` / `<mask>` |
| Default gateway | `<gateway>` |
| Interface | `<interface>` |
### Step 3 — Find out where the address came from
A DHCP address has a lease that expires; a static address doesn't. Knowing which one you have tells you where to look when something breaks.
- **Linux:** the `inet` line from Step 2 contains `dynamic` and a finite `valid_lft` (for example `86077sec`) for a DHCP address. A static address shows `valid_lft forever` and no `dynamic`. `proto dhcp` on the default route confirms it.
- **Windows:** `DHCP Enabled. . . : Yes` plus the `Lease Obtained` / `Lease Expires` and `DHCP Server` lines.
- **macOS:** print the DHCP lease for the interface:
```bash
ipconfig getpacket en0
```
Expected output (abbreviated):
```text
op = BOOTREPLY
…
yiaddr = 192.168.1.23
…
subnet_mask (ip): 255.255.255.0
router (ip_mult): {192.168.1.1}
lease_time (uint32): 0x15180
server_identifier (ip): 192.168.1.1
```
`yiaddr` ("your IP address") is the address the server gave you. `0x15180` is 86,400 seconds: a 24-hour lease. No output means the interface wasn't configured by DHCP.
Write down: static or DHCP? Which device is the DHCP server? On most home networks it is the same device as the gateway.
### Step 4 — Check the lesson's calculation with Python
Start an interactive Python session with `python3` (Windows: `py`) and type the lines after `>>>`. You'll confirm the `192.0.2.130/26` example from the lesson's How it works section.
```python
>>> import ipaddress
>>> iface = ipaddress.ip_interface("192.0.2.130/26")
>>> iface.network
>>> iface.netmask
>>> iface.network.broadcast_address
>>> iface.network.num_addresses
>>> list(iface.network.hosts())[0]
>>> list(iface.network.hosts())[-1]
```
Expected output, line by line:
```text
IPv4Network('192.0.2.128/26')
IPv4Address('255.255.255.192')
IPv4Address('192.0.2.191')
64
IPv4Address('192.0.2.129')
IPv4Address('192.0.2.190')
```
64 addresses, minus network and broadcast, leaves the 62 usable hosts from the lesson. Now check the quick-check answer and peek at IPv6:
```python
>>> ipaddress.ip_address("198.51.100.200") in ipaddress.ip_network("198.51.100.192/27")
>>> ipaddress.ip_interface("2001:db8:0:10::82/64").network
```
```text
True
IPv6Network('2001:db8:0:10::/64')
```
Exit with `exit()`.
> [!TIP]
> `ipaddress.ip_network("192.0.2.130/26")` raises `ValueError: 192.0.2.130/26 has host bits set`, because a network must be written with its network address. Use `ip_interface()` for "this address on that network", or pass `strict=False`.
### Step 5 — Write an address calculator
A script lets you repeat the calculation for any address, including your own. Save this as `ipcalc.py` in your `ip-lab` folder:
```python
"""Show the network facts for an IPv4 address with a prefix, e.g. 192.0.2.130/26."""
import ipaddress
import sys
def dotted_binary(addr):
return ".".join(f"{int(octet):08b}" for octet in str(addr).split("."))
iface = ipaddress.IPv4Interface(sys.argv[1] if len(sys.argv) > 1 else "192.0.2.130/26")
net = iface.network
print(f"Address {iface.ip}")
print(f" in binary {dotted_binary(iface.ip)}")
print(f"Prefix /{net.prefixlen} ({net.prefixlen} network + {32 - net.prefixlen} host bits)")
print(f"Subnet mask {net.netmask}")
print(f" in binary {dotted_binary(net.netmask)}")
print(f"Network {net.network_address}")
print(f"Broadcast {net.broadcast_address}")
if net.prefixlen <= 30:
print(f"First host {net.network_address + 1}")
print(f"Last host {net.broadcast_address - 1}")
print(f"Usable hosts {net.num_addresses - 2} (2^{32 - net.prefixlen} - 2)")
else:
print("Special case: /31 and /32 have no separate network and broadcast addresses (see module 06).")
```
Run it without arguments (the lesson example), then with the lesson's `/20` pitfall:
```bash
python3 ipcalc.py
python3 ipcalc.py 172.20.13.77/20
```
On Windows, use `py` instead of `python3`. Expected output:
```text
Address 192.0.2.130
in binary 11000000.00000000.00000010.10000010
Prefix /26 (26 network + 6 host bits)
Subnet mask 255.255.255.192
in binary 11111111.11111111.11111111.11000000
Network 192.0.2.128
Broadcast 192.0.2.191
First host 192.0.2.129
Last host 192.0.2.190
Usable hosts 62 (2^6 - 2)
Address 172.20.13.77
in binary 10101100.00010100.00001101.01001101
Prefix /20 (20 network + 12 host bits)
Subnet mask 255.255.240.0
in binary 11111111.11111111.11110000.00000000
Network 172.20.0.0
Broadcast 172.20.15.255
First host 172.20.0.1
Last host 172.20.15.254
Usable hosts 4094 (2^12 - 2)
```
Now run it on your own address from Step 2:
```bash
python3 ipcalc.py <address>/<prefix>
```
`<address>/<prefix>` is your IPv4 address and prefix length, for example `192.168.1.23/24`. If you only have a dotted mask (Windows, macOS), Python accepts that too: `192.168.1.23/255.255.255.0`.
Check: is your default gateway between `First host` and `Last host`? It must be.
### Step 6 — Classify addresses by purpose
Python's `ipaddress` objects have flags such as `is_private`, `is_global`, `is_loopback`, `is_link_local` and `is_multicast`. This script compares them with an explicit table of special-purpose blocks from the lesson. Save it as `classify.py`:
```python
"""Classify IPv4 addresses by purpose and compare with Python's ipaddress flags."""
import ipaddress
import sys
# Special-purpose blocks (RFC 6890 and the IANA IPv4 Special-Purpose Address Registry).
# Checked in order: the first match wins, so 255.255.255.255 comes before 240.0.0.0/4.
BLOCKS = [
("0.0.0.0/8", "This network (RFC 791)"),
("10.0.0.0/8", "Private (RFC 1918)"),
("100.64.0.0/10", "Shared / CGN (RFC 6598)"),
("127.0.0.0/8", "Loopback (RFC 1122)"),
("169.254.0.0/16", "Link-local (RFC 3927)"),
("172.16.0.0/12", "Private (RFC 1918)"),
("192.0.2.0/24", "Documentation (RFC 5737)"),
("192.168.0.0/16", "Private (RFC 1918)"),
("198.51.100.0/24", "Documentation (RFC 5737)"),
("203.0.113.0/24", "Documentation (RFC 5737)"),
("224.0.0.0/4", "Multicast (RFC 5771)"),
("255.255.255.255/32", "Limited broadcast (RFC 919)"),
("240.0.0.0/4", "Reserved (RFC 1112)"),
]
BLOCKS = [(ipaddress.IPv4Network(net), label) for net, label in BLOCKS]
SAMPLES = [
"192.168.1.10", "10.20.30.40", "172.20.1.5", "172.32.1.5", "100.64.12.34",
"127.0.0.1", "169.254.17.3", "192.0.2.130", "198.51.100.7", "203.0.113.250",
"224.0.0.251", "255.255.255.255", "0.0.0.0",
]
def purpose(addr):
for net, label in BLOCKS:
if addr in net:
return label
if addr.is_global:
return "Public (global unicast)"
return "Other special (see IANA)"
def mark(flag):
return "yes" if flag else "-"
print(f"{'Address':<16} {'Purpose':<28} {'private':>7} {'global':>6} {'loopbk':>6} {'link-l':>6} {'mcast':>5}")
for text in sys.argv[1:] or SAMPLES:
a = ipaddress.IPv4Address(text)
print(f"{text:<16} {purpose(a):<28} {mark(a.is_private):>7} {mark(a.is_global):>6} "
f"{mark(a.is_loopback):>6} {mark(a.is_link_local):>6} {mark(a.is_multicast):>5}")
```
Run it on the built-in samples:
```bash
python3 classify.py
```
Expected output:
```text
Address Purpose private global loopbk link-l mcast
192.168.1.10 Private (RFC 1918) yes - - - -
10.20.30.40 Private (RFC 1918) yes - - - -
172.20.1.5 Private (RFC 1918) yes - - - -
172.32.1.5 Public (global unicast) - yes - - -
100.64.12.34 Shared / CGN (RFC 6598) - - - - -
127.0.0.1 Loopback (RFC 1122) yes - yes - -
169.254.17.3 Link-local (RFC 3927) yes - - yes -
192.0.2.130 Documentation (RFC 5737) yes - - - -
198.51.100.7 Documentation (RFC 5737) yes - - - -
203.0.113.250 Documentation (RFC 5737) yes - - - -
224.0.0.251 Multicast (RFC 5771) - yes - - yes
255.255.255.255 Limited broadcast (RFC 919) yes - - - -
0.0.0.0 This network (RFC 791) yes - - - -
```
Read the table carefully. Four results surprise most people:
- **`172.32.1.5` is public.** The RFC 1918 block `172.16.0.0/12` ends at `172.31.255.255`.
- **`is_private` is not "RFC 1918".** Python marks an address private when the IANA registry says it is *not globally reachable*. That includes loopback, link-local, documentation, `0.0.0.0` and broadcast. To test for RFC 1918 specifically, check the three blocks yourself, as `BLOCKS` does.
- **`100.64.12.34` is neither private nor global.** Python treats the CGN shared space (RFC 6598) as a special case: it isn't reachable from the Internet, but it isn't yours to use either.
- **`224.0.0.251` is "global".** `is_global` comes from the special-purpose registry, and multicast isn't listed there (it has its own registry). `is_global` does not mean "public unicast address you can ping".
> [!NOTE]
> Python 3.12.4 and 3.13 corrected the tables behind `is_private` and `is_global` to match the IANA registry (CVE-2024-4032; the fix was also backported to security releases of some older branches). For every address in `SAMPLES` the output above is identical on Python 3.14.7 and on 3.11.8, which predates the fix. Results differ on some addresses inside `192.0.0.0/24`: for example, `192.0.0.100` is `global` on 3.11.8 and `private` on 3.14.7. If you rely on these flags in real code, check your Python version.
### Step 7 — Classify your own addresses
Pass your address and gateway from Step 2 as arguments:
```bash
python3 classify.py <address> <gateway>
```
For the example values (`192.168.1.23`, gateway `192.168.1.1`) the output is:
```text
Address Purpose private global loopbk link-l mcast
192.168.1.23 Private (RFC 1918) yes - - - -
192.168.1.1 Private (RFC 1918) yes - - - -
```
Most home and office computers get a private address and reach the Internet through the router's Network Address Translation (NAT). If your address is public, your network assigns public addresses directly (some universities and data centres do). If it is link-local (`169.254.x.x`), DHCP failed: see Troubleshooting.
## Verification
You have completed the lab if you can answer "yes" to each check:
| Check | How to confirm |
|---|---|
| You recorded address, prefix, gateway and interface | The table from Step 2 is filled in |
| You know whether your address is static or DHCP | Step 3: `dynamic` / `DHCP Enabled: Yes` / `ipconfig getpacket` output |
| Python agrees with the lesson | Step 4 prints `192.0.2.128/26`, `192.0.2.191` and 64 addresses |
| Your gateway is inside your own network | `python3 ipcalc.py <address>/<prefix>` shows the gateway between `First host` and `Last host` |
| You can explain `is_private` vs RFC 1918 | `python3 classify.py` shows `yes` under `private` for `192.0.2.130` although it isn't RFC 1918 |
## Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| `python3: command not found` (or the Microsoft Store opens on Windows) | Python is not installed, or on Windows it is installed as `py` | Use `py` on Windows, or install Python 3 from python.org or your package manager |
| `ip: command not found` on Linux | Minimal system without iproute2 | Install the `iproute2` package, or use `hostname -I` for addresses only |
| Several addresses and adapters listed | Virtual private network (VPN), Docker, virtual machine or Wi-Fi and Ethernet both active | Use the interface named in the default route (`ip route show default`, `route -n get default`, `Get-NetRoute`) |
| Your address starts with `169.254.` and there is no gateway | No answer from a DHCP server (RFC 3927 fallback) | Check the cable or Wi-Fi connection, then renew the lease (for example, reconnect to the network). Don't set a static address to "fix" it |
| `ipconfig getpacket en0` prints nothing on macOS | The interface isn't `en0`, or it wasn't configured by DHCP | Use the interface from `route -n get default` |
| `AddressValueError` or `NetmaskValueError` from a script | Typo, IPv6 address, or missing prefix | Pass an IPv4 address like `192.168.1.23/24`; the scripts handle IPv4 only |
## Challenge (optional)
1. Find your router's outside (wide area network, WAN) address in its administration page. Use `classify.py` on it. If it is in `100.64.0.0/10`, your ISP uses Carrier-Grade NAT: what does that mean for hosting a service at home?
2. Extend `classify.py` to accept IPv6 addresses too (`ipaddress.ip_address()` returns either type), and classify `::1`, `fe80::1` and `2001:db8::1`. Compare what you find with [module 07](../07-ipv6/README.md).
3. Run `python3 ipcalc.py 192.0.2.130/<n>` for every prefix from `/24` to `/30`. Write down how the network and broadcast addresses move. You'll use this pattern in [module 06](../06-subnetting/README.md).
## Cleanup
The lab only created the `ip-lab` folder and its two scripts. Remove them.
Linux and macOS:
```bash
cd ~ && rm -r ~/ip-lab
```
Windows (PowerShell):
```powershell
Set-Location $HOME; Remove-Item -Recurse -Force "$HOME\ip-lab"
```
No network settings were changed, so there is nothing else to undo.
## What you learned
- Every host needs an address, a prefix (or mask), a default gateway and Domain Name System (DNS) servers, and you can read all of them with built-in commands on any operating system.
- A DHCP address shows a lease and a DHCP server; a static one shows neither.
- Network, broadcast and host range follow directly from the prefix, and Python's `ipaddress` module is a reliable way to check your arithmetic.
- "Private" has two meanings: RFC 1918 blocks, and Python's broader "not globally reachable". Know which one your tool uses.
- Your gateway must always be inside your own network.