A network designer is giving 50 security cameras a subnet of their own. Policy asks for as few spare addresses as possible, so that no unknown device can join quietly.
IPv4 addresses, subnets and address translation
Every device on a network needs an address, as every house needs one for post to arrive. An IPv4 address has two parts: one names the network and one names the device. Most organisations use private addresses inside and share a few public ones through a method called address translation. No background is assumed. Reading an address correctly is the first step in most network security decisions.
By the end of this unit you will be able to:
- Explain the network part and the host part of an IPv4 address, and what a subnet mask does
- Calculate how many devices a subnet holds from its /number
- Tell apart public, private, loopback and self-assigned addresses on sight
- Tell apart static NAT, dynamic NAT and PAT
- Explain why address translation is not a security control
One laptop the library Wi-Fi would not serve
An illustrative example
A village library offers free Wi-Fi. On a wet Tuesday everyone is online except one visitor. Her laptop says it is connected, yet no page opens.
The librarian has seen this before and asks to look at the laptop's network settings. Every other device in the room has an address beginning 192.168.1. Hers reads 169.254.17.9. The librarian switches the laptop's Wi-Fi off and on again. The address changes to 192.168.1.44, and the pages open.
What did an address beginning 169.254 tell the librarian before anything else was tried?
An address has a network part and a host part
An IP address works like a postal address with a street name and a house number. One part names the network, as the street does. The other part names one device on that network, as the house number does.
Internet Protocol version 4 (IPv4) addresses are 32 bits long. A bit is a single one or zero. For people, the 32 bits are written as four numbers from 0 to 255 with dots between them, such as 192.168.10.37. Each number stands for 8 bits and is called an octet. This way of writing is dotted decimal.
The subnet mask says where the network part ends. A mask of 255.255.255.0 means the first three numbers are the network and the last is the device, which is called the host. The same split is written more briefly as /24: the first 24 bits are the network part. The short form is Classless Inter-Domain Routing (CIDR) notation.
A subnet is one network's block of addresses. Devices in the same subnet send to each other directly. For any other destination a device hands the to its default gateway, which is the router's address on its own subnet.
Two addresses in every subnet are reserved. The first, with the host part all zeros, is the network address and names the subnet itself. The last, with the host part all ones, is the broadcast address: a packet sent to it goes to every device on the subnet.
Usable addresses in a subnet
Usable addresses = 2^h − 2
- h
- The number of host bits: 32 minus the number after the slash.
A /24 leaves 8 host bits: 2^8 − 2 = 254 devices. A /26 leaves 6 host bits: 2^6 − 2 = 62 devices.
Address classes A to E
Before CIDR, the first number of an address fixed where the network part ended. That scheme is classful addressing. Addresses are no longer handed out by class, but the class names are still used.
| Class | First number | Network part | Used for |
|---|---|---|---|
| A | 1 to 126 | The first number (/8) | Very large networks |
| B | 128 to 191 | The first two numbers (/16) | Medium networks |
| C | 192 to 223 | The first three numbers (/24) | Small networks |
| D | 224 to 239 | Not split | Multicast: one sender to a group of receivers |
| E | 240 to 255 | Not split | Reserved, and not given to ordinary devices |
By its bits, class A runs from 0 to 127. A first number of 0 means 'this network', and 127 is kept for loopback, described below. Neither is given to devices, so usable class A addresses begin with 1 to 126.
Private, loopback and self-assigned addresses
Some ranges have a fixed meaning that every device honours.
| Range | Name | Meaning |
|---|---|---|
| 10.0.0.0 to 10.255.255.255 (10.0.0.0/8) | Private | Free for any organisation to use inside its own network |
| 172.16.0.0 to 172.31.255.255 (172.16.0.0/12) | Private | The same |
| 192.168.0.0 to 192.168.255.255 (192.168.0.0/16) | Private | The same |
| 127.0.0.0/8, usually seen as 127.0.0.1 | Loopback | The computer itself. Traffic sent here never leaves the machine |
| 169.254.0.0/16 | Link-local | Chosen by a device for itself when none was handed out. Never forwarded by a router |
| 255.255.255.255 | Limited broadcast | Every device on the local network |
Private addresses are not carried across the public internet. Thousands of organisations use 10.0.0.0/8 at the same time without clashing, because those addresses mean something only inside each network. An address that can be reached across the internet is a public address.
A device normally receives its address from a server on the network when it joins. If no server answers, many devices give themselves a link-local address beginning 169.254. Microsoft calls this Automatic Private IP Addressing (APIPA). Such an address is a symptom: the device is connected but was never given a working address.
The library laptop
The visitor's laptop joined the and received no address, so it chose 169.254.17.9 for itself. Its neighbours held 192.168.1 addresses, so it shared no subnet with the router. The fault lay in handing out addresses, not in the internet line.
NAT and PAT: private addresses behind a public one
A device with a private address cannot be answered from the internet, because no router outside knows the way back to it. Network address translation (NAT) solves this. A router or at the edge of the network rewrites the addresses in packets as they pass.
- Static NAT
- One private address is always translated to the same public address. It suits a server that must be reachable from outside at a fixed address.
- Dynamic NAT
- A private address borrows a public address from a pool when it needs one and gives it back afterwards.
- Port address translation (PAT)
- Many private addresses share one public address at the same time. It is also called overload, or network address and port translation (NAPT).
PAT works by changing the port number as well as the address. A port is a number in the transport header that identifies one conversation or service. The translating device gives each outgoing conversation its own port on the public address and keeps a table, so that each reply is matched to the right inside device.
| Inside address and port | Translated to | Destination |
|---|---|---|
| 10.20.30.25, port 51514 | 198.51.100.2, port 40001 | 203.0.113.20, port 443 |
| 10.20.30.31, port 51514 | 198.51.100.2, port 40002 | 203.0.113.20, port 443 |
| 10.20.30.40, port 49200 | 198.51.100.2, port 40003 | 192.0.2.80, port 443 |
Common misconception
“NAT protects a network, because outsiders cannot see or reach the private addresses.”
Hiding addresses is a side effect of translation, which is a routing function. An outsider cannot start a connection through PAT, but a firewall that tracks connections gives the same protection by design, with rules that can be reviewed. NAT does not replace a firewall.
Two header fields: time to live and fragmentation
Two fields in the header matter for security. The time to live (TTL) is a counter set by the sender. Every router that forwards the packet lowers it by one, and a router that finds it at zero discards the packet. A packet caught in a loop between wrongly configured routers therefore dies instead of circling for ever.
The second is fragmentation. An IPv4 packet may be up to 65,535 bytes long, where a byte is 8 bits. Each link has a smaller limit, its maximum transmission unit (MTU). A router may split a packet that is too large into fragments, and the destination puts them back together. Deliberately malformed fragments have been used to crash the computer that reassembles them.
Worked example: Same subnet, or through the gateway?
A laptop has the address 192.168.10.37 with the mask 255.255.255.0. Its default gateway is 192.168.10.1. It needs to reach a printer at 192.168.10.200 and a payroll server at 192.168.20.5.
- The mask 255.255.255.0 is /24, so the first three numbers are the network part. The laptop's network is 192.168.10.
- The printer's first three numbers are 192.168.10. They match, so the printer is on the laptop's own subnet and the laptop sends to it directly.
- The payroll server's first three numbers are 192.168.20. They differ, so the laptop sends that packet to its default gateway, 192.168.10.1, which routes it onward.
- The subnet has 8 host bits, so it holds 2^8 − 2 = 254 devices. Its network address is 192.168.10.0 and its broadcast address is 192.168.10.255.
- All three addresses begin 192.168, so all are private. To reach the internet their traffic must pass through NAT.
One comparison of network parts decides whether a router is involved at all. A wrong mask or a wrong gateway setting breaks that decision, so both are checked first when a device can reach its neighbours and nothing else.
A question, worked through
An auditor asks how a small firm's office network is protected from the internet. The contractor who installed the router replies that it uses port address translation, so the internal addresses are hidden, and that the router's firewall feature was left switched off to keep the set-up simple. The security manager must respond to the audit point.
What is the BEST response?
Decide on your answer, then open the reasoning
- The question is what protects the office from the internet. The answer on offer is address translation alone.
- Rule out c: static NAT gives each computer a fixed public address, which makes every computer reachable from outside. It increases exposure.
- Rule out d: public addresses on every computer remove even the side effect of PAT and add no control.
- Between a and b: PAT does stop outsiders starting connections, which makes a tempting. But translation has no rules to review, keeps no record of refused traffic and does nothing about what leaves the office.
- A manager needs a control that was designed for the purpose and can be shown to the auditor. That is the firewall, so b.
Answer: B. Enable the firewall, because translation is not a security control
Choosing between good answers
- An address begins 10, 172.16 to 172.31, or 192.168
- treat it as private: it needs NAT to reach the internet and cannot be reached from the internet directly.
- A device shows an address beginning 169.254
- it was not given an address when it joined. Look at the service that hands out addresses, not at the internet line.
- Many inside devices share one public address
- the answer is PAT. When one server needs a fixed public address, the answer is static NAT.
- NAT and a firewall are both offered as the protection for a network
- choose the firewall. NAT hides addresses as a side effect and is not a security control.
Check your understanding
3 questions on this unit, easiest first. Confirm an answer to see the reasoning for it, then the right answer, the other options and the rule to reuse. Your answers are kept in this browser and feed readiness and review.
These questions are drafts that no named reviewer has approved yet.
Question 1 of 3
What to remember
- An IPv4 address is 32 bits, written as four numbers from 0 to 255. The subnet mask, or the /number, says how much of it is the network part.
- Devices on the same subnet talk directly. Everything else goes to the default gateway.
- The private ranges are 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. Loopback is 127.0.0.0/8. A self-assigned address begins 169.254.
- Class A begins 1 to 126, class B 128 to 191 and class C 192 to 223. Class D is multicast and class E is reserved.
- Static NAT maps one address to one, dynamic NAT lends from a pool, and PAT shares one public address by changing port numbers.
- NAT is a routing function. It does not replace a firewall.
Say it from memory
How many usable addresses does a /26 subnet hold, and which two addresses in every subnet are reserved?
A /26 leaves 6 host bits, so 2^6 − 2 = 62 usable addresses. The first address, with the host part all zeros, is the network address and names the subnet itself. The last, with the host part all ones, is the broadcast address.
What first numbers mark IPv4 address classes A to E, and what are classes D and E used for?
Class A is 1 to 126, class B 128 to 191 and class C 192 to 223. Class D, 224 to 239, is multicast: one sender to a group of receivers. Class E, 240 to 255, is reserved and not given to ordinary devices.
What are the three private IPv4 ranges, and what does an address beginning 169.254 tell you?
The private ranges are 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. An address beginning 169.254 is link-local, which Microsoft calls APIPA. The device chose it for itself because no server handed out an address, so it is connected but was never given a working address.
How do static NAT, dynamic NAT and port address translation differ?
Static NAT always translates one private address to the same public address, which suits a server reachable from outside. Dynamic NAT lends a public address from a pool and takes it back afterwards. Port address translation lets many private addresses share one public address at once, by changing the port number as well as the address.
What does the time to live field do, and what is the maximum transmission unit?
The time to live (TTL) is a counter set by the sender. Every router lowers it by one and discards the packet at zero, so a packet caught in a loop dies. The maximum transmission unit (MTU) is a link's size limit; a router may split a larger packet into fragments.
Sources
- RFC 791: Internet Protocol, IETFIPv4 addresses are 32 bits; classes A, B and C by their leading bits; the time to live field; the 65,535 octet limit on a datagram.
- RFC 4632: Classless Inter-domain Routing, IETFClassless prefixes written as a slash and the number of network bits.
- RFC 1918: Address Allocation for Private Internets, IETFThe three private blocks 10/8, 172.16/12 and 192.168/16.
- RFC 3927: Dynamic Configuration of IPv4 Link-Local Addresses, IETF169.254/16 is for self-assigned link-local addresses, and a router must not forward packets that carry them.
- RFC 6890: Special-Purpose IP Address Registries, IETFLoopback 127.0.0.0/8, limited broadcast 255.255.255.255, 0.0.0.0/8 as this network, and 240.0.0.0/4 as reserved.
- RFC 5771: IANA Guidelines for IPv4 Multicast Address Assignments, IETFIPv4 multicast addresses run from 224.0.0.0 to 239.255.255.255.
- RFC 3022: Traditional IP Network Address Translator, IETFBasic NAT translates addresses; NAPT also translates transport ports so that many private hosts share one registered address.
- RFC 2663: IP Network Address Translator (NAT) Terminology and Considerations, IETFStatic and dynamic address assignment in NAT.
- NIST SP 800-41 Rev. 1: Guidelines on Firewalls and Firewall Policy, NISTNAT is a routing technology and not part of a firewall's security function; a stateful firewall gives the same protection against unsolicited inbound connections.
- 1998 CERT Advisories, Software Engineering Institute, Carnegie Mellon UniversityAn IP broadcast address has the host portion set to all ones, and a packet sent to it is delivered to every machine on that network.