You are on page 1of 60

Network Address Translation (NAT

)

1

Overview
Motivation  End-to-end principle  Role of IP addresses  Basic NAT types and their behaviors  NAT traversal: STUN

2

History

Early 1990s

IPv4 Address consumption concern Two approaches
• IPv6 and NAT

NATs were initially intended to allow devices to share an address pool dynamically
 

First RFC about NAT in 1994 NAT vs. DHCP? IETF hates NATs No standardization -> backfire

NAT goes against Internet end-to-end principle
 

3

there is extension Even multi-homing  ISP wants to save money   Changing next higher ISP becomes easier   Security: Inbound traffic filtering  stateful firewall 4 .Motivation  DSL and cable modem business model  Not simultaneous access. no servers In PSTNs.

Everything else should be done at the fringes. in such a way that the state can only be destroyed when the endpoint itself breaks (known as fatesharing).” 5 .. Such state should be maintained only in the endpoints.End-to-end principle  RFC 1958: “An end-to-end protocol design should not rely on the maintenance of state (i. An immediate consequence of this is that datagrams are better than classical virtual circuits. information about the state of the end-to-end communication) inside the network. The network's job is to transmit datagrams as efficiently and flexibly as possible.e.

L3. … explicit vs. optimizing routing vs. restart  Examples:            NATs SOCKS gateway IP tunnel endpoint Transport relay Load balancers Application firewalls Transcoders (RFC 3234) Proxies Caches Modified DNS servers Anonymizers 6 .Middle boxes        Middle box = “any intermediary device performing functions other than the normal. standard functions of an IP router on the datagram path between a source host and destination host” L2. L4. hard state fail-over vs. L7. processing soft vs. implicit functional vs.

255 172.0.168.0.31.0 – 10.16.255.255.Private Network   Private IP network is an IP network that is not directly connected to the Internet IP addresses in a private network can be assigned arbitrarily.168.255. private networks use addresses from the following experimental address ranges (non-routable addresses):    10.0.  Not registered and not guaranteed to be globally unique  Generally.0 – 192.0.255 7 .255.255 192.0 – 172.

0.3 10.1.1 10.168.4.3 10.0.0.1.1.119 128.Private Addresses H1 H2 H3 H4 10.71.1.112.1.0.2 10.1.1 Private network 1 Internet R1 128.21 Private network 1 R2 213.3 H5 8 .143.195.2 10.0.0.

Network Address Translation (NAT)    NAT is a router function where IP addresses (and possibly port numbers) of IP datagrams are replaced at the boundary of a private network NAT is a method that enables hosts on private networks to communicate with hosts on the Internet NAT is run on routers that connect private networks to the public Internet. to replace the IP address-port pair of an IP packet with another IP address-port pair.  Topology sensitive • inside (private) vs. outside (public) 9 .

Basic operation of NAT  NAT device has address translation table 10 .

Main uses of NAT   Pooling of IP addresses Supporting migration between network service providers   IP masquerading Load balancing of servers 11 .

the NAT device picks a public IP address from the address pool. manages a pool of public IP addresses When a host from the corporate network sends an IP datagram to a host in the public Internet. located at the boundary between the corporate network and the public Internet.Pooling of IP addresses   Scenario: Corporate network has many hosts but only a small number of public IP addresses NAT solution:    Corporate network is managed with a private address space NAT device. and binds this address to the private address of the host 12 .

168.71.21 Destination = 213.0.2 Destination = 213.Pooling of IP addresses Private network Source = 10.112.112.30 13 .1.143.0-128.168.1.2 public address: Internet Source = 128.3 H1 H5 Private Address 10.71.143.2 Public Address Pool of addresses: 128.1.168.143.3 private address: 10.3 NAT device public address: 213.112.71.0.0.

The migration is not noticeable to the hosts on the network. NAT solution: Assign private addresses to the hosts of the corporate network  NAT device has static address translation entries which bind the private address of a host to the public address. Note:  The difference to the use of NAT with IP address pooling is that the mapping of public and private IP addresses is static.Supporting migration between network service providers   Scenario: In CIDR. the IP addresses in a corporate network are obtained from the service provider. Changing the service provider requires changing all IP addresses in the network.  Migration to a new network service provider merely requires an update of the NAT device.  14 .

Supporting migration between network service providers 15 .

IP masquerading    Also called: Network address and port translation (NAPT) Scenario: Single public IP address is mapped to multiple hosts in a private network. NAT solution:   Assign private addresses to the hosts of the corporate network NAT device modifies the port numbers for outgoing traffic 16 .

IP masquerading

17

Load balancing of servers

Scenario: Balance the load on a set of identical servers, which are accessible from a single IP address NAT solution:
  

Here, the servers are assigned private addresses NAT device acts as a proxy for requests to the server from the public network The NAT device changes the destination IP address of arriving packets to one of the private addresses for a server A sensible strategy for balancing the load of the servers is to assign the addresses of the servers in a roundrobin fashion.

18

Load balancing of servers

19

Concerns about NAT  Performance:  Modifying the IP header by changing the IP address requires that NAT boxes recalculate the IP header checksum  Modifying port number requires that NAT boxes recalculate TCP checksum  Fragmentation  Care must be taken that a datagram that is fragmented before it reaches the NAT device. is not assigned a different IP address or different port numbers for each of the fragments. 20 .

the address-port mapping is maintained soft-state (in minutes) 21 . A host in the public Internet often cannot initiate communication to a host in a private network • Hamper peer-to-peer applications The problem is worse.Concerns about NAT  End-to-end connectivity:     NAT destroys universal end-to-end reachability of hosts on the Internet. when two hosts that are in a private network need to communicate with each other Typically.

if an IP address is detected in the applicationlayer header or the application payload. Some NAT devices inspect the payload of widely used application layer protocols and. translate the address according to the address translation table. 22 .Concerns about NAT  IP address in application data:   Applications that carry IP addresses in the payload of the application data generally do not work across a private-public network boundary.

NAT and FTP  Normal FTP operation 23 .

NAT and FTP  24 NAT device with FTP support .

NAT and FTP  25 FTP in passive mode and NAT. .

NAT Traversal 26 .

NAPT Traversal 27 .

NAT types Symmetric  Port restricted cone  Address restricted cone  Full cone  Hairpin  Different not only on a vendor-by-vendor basis but also on a model-by-model basis 28 .

Symmetric NAT 29 •NAT mapping btw src_addr/src_port and dest_addr/dest_port is fixed •The most restrictive form •It has been observed to be rare .

Full-cone NAT   The least restrictive form Binding of a local address/port can be used by any remote host 30 .

(Address) Restricted-cone NAT  NAT binding is accessible only by the destination host  different port can be used 31 .

Port-restricted-cone NAT   NAT binding is accessible by any remote host  But only same port should be used Typically. the internal host had previously sent a packet the remote host 32 .

Hairpin NAT D  33 A local host can direct a packet to the public address/port of an already mapped local host .

Nondeterministic NATs NATs change their types of behavior when a binding conflict occurs Example  Some NATs attempt to preserve the port number in the binding  If the port number is available. the NAT may change the type. the NAT behaves like a full-cone NAT  If that port is already occupied by other host. a symmetric NAT 34 .g. e.

 Protocols like SIP and applications like Google Talk use STUN to gather important information about the network configuration.  The protocol is defined in RFC 3489.What is STUN? Who uses it? STUN – Simple Traversal of User Datagram Protocol through Network Address Translators.  35 .

What does it do?    STUN is a client-server protocol that “allows entities behind a NAT to first discover the presence of a NAT and the type of NAT. and then to learn the addresses bindings allocated by the NAT.” In other words. it’s a means of discovering the public IP and port numbers that a NAT assigns to a node on a private LAN.ietf. STUN does not require any special network configuration and works with a variety of existing networks. In addition. *http://tools.org/html/rfc3489 36 . but not all.

STUN and NAT terminology A STUN Client is a node that generates the STUN requests.  NAT   usually part of a firewall or router 37 .  A STUN Server is a node that receives the STUN requests and generates the STUN responses.

A picture i worth 1000 words 38 .

The Client then waits for the Server to send a STUN response   STUN client is typically embedded in application STUN server has two IP addresses  The trick is to analyze the response from the server to determine the type of NAT router and the associated bindings the router has given to internal nodes.How STUN generally works  A STUN Client sends a STUN request to a STUN Server. 39 .

the public IP and port of the STUN client.  CHANGE-REQUEST : Found in STUN requests. It contains the IP address and port number of the STUN request. It contains flags for the IP address and port number of the server.. (We will see why later)  CHANGED-ADDRESS – Found in STUN responses. the client is asking the server to send the response from a different IP and port.The STUN Message  The following STUN attributes in the payload are especially important:  MAPPED-ADDRESS : Found in STUN responses. If set.e. I. It contains the alternate IP address and port number of the server due to CHANGE-REQUEST 40 .

NAT discovery (test 1)   To determine if a NAT router/firewall is present. Otherwise. it is behind a NAT router. then the client is NOT behind a NAT router. Wait for a response and analyze it. 41 . If the IP address and port number in the MAPPED-ADDRESS attribute of the payload in the STUN response equal the local IP address and port number that it bound to when sending the request. send a STUN request to the server.

NAT discovery – Full Cone (test 2)  Full Cone NAT router – The client sets the IP address and port number flags in the CHANGE-REQUEST of the STUN request. This causes the server to send the response from the alternate IP and port number. then the client is behind a full cone router. it is behind one of the other three NAT routers. 42 . Otherwise.   If the client receives the STUN response.

If they do match.NAT discovery – Symmetric (test 3)  Symmetric NAT – The client sends two STUN requests. 43 . then it is behind one of the remaining two NAT routers. and another to a server at IP address Y and port P.   If the IP addresses and ports from the MAPPED-ADDRESS attributes in the two responses do not match. One request is sent to a server at IP address X and port P. then it is behind a Symmetric NAT router.

This instructs the server to send a response from a different port. it is behind a port restricted NAT router.NAT discovery – Restricted (test 4)  Restricted NAT – The port flag in the CHANGE-REQUEST attribute of the request is set. it is behind a restricted NAT router. If no response is received. 44 .  If the response is received.

45 .

 STUNT and other proposals    Does not allow incoming UDP connections through a symmetric NAT STUN “is not a cure-all for the problems associated with NAT. the solution is to make the environment less hostile. However.Limitations of STUN  Does not address incoming TCP connections.” “The problems in STUN have to do with the lack of standardized behaviors and controls in NATs. which results in a proliferation of devices whose behavior is highly unpredictable. extremely variable. STUN provides a good short term solution given the terrible conditions under which it is forced to operate. until such time as that happens. and to introduce controls and standardized behaviors into NAT.” 46 . and uncontrollable. Ultimately.

NAT traversal 47 .

48 .

49 .

50 .

51 .

52 .

53 .

54 .

55 .

56 .

57 .

58 .

59 .

Other issues  Symmetric NATs The first packet for hole punching will be dropped  And the port number (for the other peer) is changed from the one for the server  Port prediction technique  • May not work  Nested NATs 60 .

70854380.4.9147.!.170.09 190!.3/54793:2-079./390$%&7085438006:.07  .0398 %-03/.%74:907  90780 98-03/.90 4.99 -4:3/9403803/390706:089 903 90.//7088.%74:907  ..997-:904190 5.$%&706:0899490807.3/54793:2-07390 !! #$$.3/.//7088.8 5708039 803/.3.

3/54793:2-071.4.1:.3/5479 3:2-07   190.039809890 !.0890$%&70854380  90390..8390  #"&$%4190$%&706:089  %8.43074:907 90780 98-03/430419049079700 %74:9078  .%/8.9073.:80890807.0794803/90 70854380174290.90!.0398-03/.07 :430 9089 :430%74:907 %0.03970.//7088.0.

07.3394%74:9078  .//7088.807.3/54798174290 !! #$$.07 $22097.039803/894 $%&706:0898  30706:0898803994.3490794.9!.997-:90839094 708543808/43492. 9089 $22097.4.//708808. 807.07. 90398-03/.//7088.%/8.3/ .9!.%74:907 190/42. 90398-03/4304190 702.9.3/5479 !   190!.3/5479! .% %0. $22097.9.

4.547970897.997-:904190 706:0898809 %83897:.90/% %054791.0.90/% 74:907  ./11070395479  19070854380870.07 #0897.0/ 98-03/. 70897.0794 803/.90/%74:907 134708543808 70.90/ 9089 #0897.%/8.9890807.0.390  #"&$%.0/ 98-03/.708543801742.

 .

43.:70 .-0 &92.094/4990..43974.90/9% %0574-0283$%&..-0 .4397483%8 .43/9438:3/07.574107.9438974:.3/943974/:..07 :398:.03 909077-0.29.94341 /0.-0 097020 .74320390884890 .708:983..9438  $%&%.423&!.0/944507.7/0/-0.943841$%& 408349.8 408349.439748.3/ 89./08..478.55038 $%&574.9.14790574-028.7/0/ -0.98147.3/.822097.3/:3.4330.44/8479907284:943.0 9003.7.//70883.3/.478:3570/.8 9.3/..0.4189.9.423%!.90  ..884.3/4907574548.90 9084:9438942.. % $%& 8349.478394% 40.08480-0..4330.920.

  .078..%97.

 .

 .

 .

 .

 .

 .

 .

 .

 .

 .

 .

 .

.30/17429043014790 807.94390.90788:08 $22097.34947 0890/%8  .%8 %017895.3 -0/74550/  3/9054793:2-07 147904907 5007 8.36:0  W .09147405:3..07  !479570/.