Salta al contenuto
Note per Studenti NAT and Private Addresses Report

NAT and Private Addresses

In questa pagina 4

IPv4 addresses are scarce (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 →). Besides CIDR and subnetting (Subnetting, VLSM and SupernettingSubnetting splits an address block into smaller subnets by lengthening the mask (2^s subnets when s bits are borrowed), supernetting does the opposite by shortening the prefix to merge contiguous blocks; design rules for variable-size subnets are power-of-two sizes M with M at least hosts plus 2, prefix 32 minus log2 M, and start addresses divisible by M (largest subnet first), while 2^j blocks of prefix n aggregate into one block of prefix n minus j only if contiguous and aligned.Subnetting, VLSM and Supernetting →), a short-term remedy is to use private addresses and translate them when needed: NAT.

Private networks

Definition (intranet). A private network using the TCP/IP stack, connected to the Internet or not, never crossed by outside traffic. Internal gateways (IG) connect the subnets and an external gateway (EG) connects it to the Internet. Private addresses are used inside, public addresses outside.

Definition (private addresses). Three blocks reserved and never routed in the public network:

class range addresses mask host bits
A 10.0.0.010.0.0.0 - 10.255.255.25510.255.255.255 16 777 21616\,777\,216 255.0.0.0255.0.0.0 (/8/8) 24
B 172.16.0.0172.16.0.0 - 172.31.255.255172.31.255.255 1 048 5761\,048\,576 255.240.0.0255.240.0.0 (/12/12) 20
C 192.168.0.0192.168.0.0 - 192.168.255.255192.168.255.255 65 53665\,536 255.255.0.0255.255.0.0 (/16/16) 16

For the B block, 172.16.0.0/12172.16.0.0/12 covers second bytes from 00010000=1600010000=16 to 00011111=3100011111=31: 16⋅216=22016\cdot2^{16}=2^{20} addresses.

Is an address private? Use IP AND mask\text{IP}\ \text{AND}\ \text{mask}. 172.20.5.1172.20.5.1: second byte 20=0001010020=00010100, AND 11110000=1611110000=16, giving 172.16.0.0172.16.0.0: private. 172.32.5.1172.32.5.1: 32=0010000032=00100000, AND 11110000=3211110000=32, giving 172.32.0.0≠172.16.0.0172.32.0.0\neq172.16.0.0: public.

Different intranets can reuse the same private addresses (uniqueness is needed only inside one intranet). Advantage: more hosts than the public addresses available to the ISP. Drawback: Internet access still needs a public address. A point-to-point link between internal routers can use a private /30, e.g. 10.0.0.0/3010.0.0.0/30 (hosts 10.0.0.110.0.0.1 and 10.0.0.210.0.0.2, broadcast 10.0.0.310.0.0.3), saving public addresses: assign private addresses wherever possible.

Packets with private addresses are dropped by border routers. To reach the Internet or offer public services: application proxy, NAT or NAPT.

Application proxy

All requests go to the proxy, which forwards them with its own public IP: two TCP connections (client-proxy and proxy-server). Drawback: one proxy per application.

NAT

A Network Address Translator behaves as a standard router and in addition maps private addresses to public ones, using a pool of public addresses; some requests may be blocked if the pool is empty. Example: the pool includes 131.175.13.55131.175.13.55; host 10.24.1.17710.24.1.177 contacts 145.13.2.34145.13.2.34; the NAT replaces the source with 131.175.13.55131.175.13.55.

NAT table. Bidirectional communication needs a reversible mapping, recorded in the NAT table: the row (10.24.1.177↔131.175.13.55)(10.24.1.177\leftrightarrow131.175.13.55) lets the reply to 131.175.13.55131.175.13.55 be converted back to destination 10.24.1.17710.24.1.177.

  • Static mapping: a host always has the same public address; impractical (one public address per host, nothing saved).
  • Dynamic mapping: based on sessions: when the first packet of a host is intercepted the NAT creates a session and binds the private address to a public one; at the end the binding is released and the public address returns to the pool.

Properties: translation is transparent to hosts and to routing algorithms; ICMP packets must be translated too (they carry IP addresses in the body: ICMP, Ping and TracerouteICMP adds to IP the error reporting and queries it lacks; its messages travel inside IP datagrams with Protocol 1 and are either errors (destination unreachable type 3, time exceeded 11, redirect 5, parameter problem 12), always sent to the original source with the original IP header plus 8 bytes of data, or queries (echo request 8 and reply 0, timestamp 13 and 14); ICMP only reports and never corrects errors, and it supports ping (RTT), path MTU discovery with the D bit (maximum payload 1500-20-8=1472 bytes) and traceroute (TTL increasing, n+1 probes for n routers), but also attacks such as smurf and fake redirects.ICMP, Ping and Traceroute →).

traditional NAT bidirectional NAT
Basic NAT Twice NAT
NAPT

Traditional (outbound) NAT

Supports only connections started from the intranet.

Basic NAT translates only the private IP address, one to one for the whole session; if public addresses are fewer than hosts, some sessions cannot start.

NAPT (Network Address Port Translation) also translates the port: [private IP, source port] ⟶ [public IP, NAT source port].[\text{private IP},\ \text{source port}]\ \longrightarrow\ [\text{public IP},\ \text{NAT source port}]. The NAT port is chosen among the free ports of the gateway (Transport Layer - Ports and MultiplexingThe transport layer provides logical end-to-end communication between application processes on different hosts and exists only in end hosts; the network layer delivers to the right computer (IP address) and transport to the right process (16-bit port number, 0 to 65535); an IP address plus a port is a socket and the four-tuple of IPs and ports identifies a connection, with multiplexing and demultiplexing done by UDP on the destination socket and by TCP on the whole four-tuple, and the protocols are UDP (connectionless, unreliable), TCP (connection-oriented, reliable) and SCTP.Transport Layer - Ports and Multiplexing →). One public IP serves many sessions, even to the same external host, if the ports differ.

Example. NAT public address 131.175.13.55131.175.13.55. Two internal hosts open connections to 145.13.2.34145.13.2.34 port 80, both from source port 5000:

private (IP, port) public (IP, NAT port) destination
10.0.0.210.0.0.2, 50005000 131.175.13.55131.175.13.55, 4000140001 145.13.2.34145.13.2.34, 8080
10.0.0.310.0.0.3, 50005000 131.175.13.55131.175.13.55, 4000240002 145.13.2.34145.13.2.34, 8080

Step by step for 10.0.0.310.0.0.3:

  1. Outbound. The segment leaves 10.0.0.3:500010.0.0.3{:}5000; no row exists, so the NAT creates one with a free port (4000240002) and rewrites the source to 131.175.13.55:40002131.175.13.55{:}40002. It must also recompute the IP checksum and the TCP/UDP checksum (which includes the IP addresses and ports).
  2. Why the port. Without it both replies would reach 131.175.13.55131.175.13.55 and the NAT could not tell which host they belong to. The two internal ports coincide (5000), hence the NAT must pick different external ports.
  3. Inbound. The reply to 131.175.13.55:40002131.175.13.55{:}40002 is matched in the table and the destination is rewritten to 10.0.0.3:500010.0.0.3{:}5000.
  4. How many sessions. Ports are 16-bit: 216=65 5362^{16}=65\,536; excluding the 1024 well-known ones about 64 51264\,512 per public address.

Limit. A connection started from outside towards 131.175.13.55:40002131.175.13.55{:}40002 with no row in the table is dropped; for internal servers static mappings or Twice NAT are needed.

Bidirectional NAT: Twice NAT

Supports sessions started from either side. Problem: how can an outside host start a session with an intranet host without knowing a public address for it? Solution with the DNS (DNS - Domain Name SystemDNS translates names such as www.amazon.com into IP addresses; it is a distributed hierarchical database (an inverted tree of up to 128 levels, with 13 root servers and domains registered through ICANN-accredited registrars), each ISP has a local DNS whose address the host gets from DHCP, the host asks it (usually over UDP) and it queries root, top-level and organisation servers, every server caches what it learns marking answers as non-authoritative until the TTL expires, records are (name, type, value, class, TTL), with NAT the DNS must return the public address, and there are four types of attack including cache poisoning.DNS - Domain Name System →) inside the intranet: the DNS returns the (private) address of the server, the NAT translates it to a public one, and the public address is returned to the client in the DNS reply; the DNS must be inside the intranet and statically mapped to a public address. Later packets use that public address and traditional NAT does the translation.

Example. Client 204.51.16.12204.51.16.12 asks for myserver.com, private address 10.0.0.20710.0.0.207. The intranet DNS yields 10.0.0.20710.0.0.207; the NAT maps it to 194.54.21.6194.54.21.6 (row 10.0.0.207↔194.54.21.610.0.0.207\leftrightarrow194.54.21.6); the DNS reply gives 194.54.21.6194.54.21.6; the client sends there and the NAT delivers to 10.0.0.20710.0.0.207.

An addressing plan case

Two routers joined by a point-to-point link: the link needs no public addresses, so assign a private /30: interfaces 10.0.0.1/3010.0.0.1/30 and 10.0.0.2/3010.0.0.2/30, network 10.0.0.0/3010.0.0.0/30, broadcast 10.0.0.3/3010.0.0.3/30. Public addresses are reserved for what must be reachable from the Internet.

Versione ripasso

Private addresses

NAT

Teoria collegata