PAT is the most widely used form of NAT. Sometimes referred to as NAT overload, the PAT translation mechanism is dynamic and it applies to IPv4 addresses and to TCP or UDP port numbers. As far as the addresses are concerned, PAT maps multiple local addresses to a single global address or to a pool of global addresses. As far as port numbers are concerned, PAT maps multiple local port numbers to multiple global port numbers. Mappings that are created by PAT always specify pairs of values, consisting of an IPv4 address and a port number.
PAT 是最廣泛使用的 NAT 形式,有時也稱為 NAT 過載(NAT overload)。PAT 的轉換機制是動態的,同時套用於 IPv4 位址以及 TCP 或 UDP 連接埠號。就位址而言,PAT 會把多個本地位址對應到單一全域位址或一組全域位址;就連接埠號而言,PAT 會把多個本地連接埠號對應到多個全域連接埠號。PAT 建立的對應項目一律以「IPv4 位址與連接埠號」的配對來表示。
PAT allows multiple devices to share a single or a few inside global addresses. Most home routers operate in this way. Your ISP assigns one public address to your router, yet several members of your family can simultaneously surf the internet.
PAT 讓多部裝置共用單一或少數幾個內部全域位址。大多數家用路由器都是以這種方式運作:您的 ISP 只指派一個公開位址給您的路由器,但家中多位成員卻能同時上網。
PAT translates local IPv4 addresses to one or more global IPv4 addresses. In either case, PAT has to ensure that each connection is translated unambiguously. When only a single global IPv4 address is available, PAT will assign each translated packet the same global IPv4 address, but different port number. When all available port numbers are exhausted, the translations will not be possible, and no new connections would be created. The number of available port numbers determines the number of simultaneous outbound connections. Since the port numbers are not as scarce as global IPv4 addresses, PAT is very efficient and can accommodate many outbound connections.
PAT 會將本地 IPv4 位址轉換為一個或多個全域 IPv4 位址。不論哪種情況,PAT 都必須確保每個連線都能被明確地轉換。當只有單一全域 IPv4 位址可用時,PAT 會為每個經過轉換的封包指派相同的全域 IPv4 位址,但使用不同的連接埠號。當所有可用連接埠號都耗盡時,就無法再進行轉換,也無法建立新連線。可用連接埠號的數量決定了可同時進行的對外連線數量。由於連接埠號不像全域 IPv4 位址那樣稀少,PAT 相當有效率,能容納許多對外連線。
The mechanism of translating port numbers tries to preserve the original local port number, meaning that it tries to avoid port translation. If more than one connection uses the same original local port number, PAT will preserve the port number only for the first connection translated. All other connections will have the port number translated.
連接埠號轉換機制會嘗試保留原本的本地連接埠號,也就是盡量避免進行連接埠轉換。若多個連線使用相同的原始本地連接埠號,PAT 只會為第一個被轉換的連線保留該連接埠號,其餘連線的連接埠號都會被轉換。
As with dynamic NAT, all mappings created by PAT have a timeout. Once they expire, the mappings are deleted from the mapping table.
與動態 NAT 相同,PAT 建立的所有對應項目都有逾時時間。一旦逾時,對應項目就會從對應表中刪除。
When responses to the translated packets are received at the outside interface of the border device, the destination IPv4 address and destination port numbers are translated back from global to local values. For this "backward" translation to succeed, both destination IPv4 address and destination port number of the inbound packet must have entries in the mapping table. PAT can be implemented for both inside and outside addresses, but this course focuses only on inside PAT translations.
當邊界裝置的外部介面收到針對已轉換封包的回應時,目的 IPv4 位址與目的連接埠號會從全域值轉換回本地值。這種「反向」轉換要成功,進入封包的目的 IPv4 位址與目的連接埠號都必須在對應表中有對應項目。PAT 可以同時套用於內部與外部位址的轉換,但本課程只著重於內部 PAT 轉換。
Incoming packets from the outside network are delivered to the destination device on the inside network by looking for a match in the NAT-mapping table. This mechanism is called connection tracking.
來自外部網路的進入封包,是藉由在 NAT 對應表中尋找符合項目,才能送達內部網路上的目的裝置。這種機制稱為連線追蹤(connection tracking)。
The figure illustrates an example of using PAT. In the example, the R2 router is configured to perform only inside PAT. It initially has no mappings in its mapping table. This example shows the port preserving feature of PAT. There are two hosts on the inside network that access servers in the internet.
此圖示範了 PAT 的使用範例。在此範例中,R2 路由器只設定為執行內部 PAT,一開始其對應表中沒有任何對應項目。此範例展示了 PAT 保留連接埠號的特性。內部網路上有兩部主機會存取網際網路上的伺服器。
- Host 192.168.10.10 is first to initiate communication. It initiates an HTTP connection to SRV1, using source port number 1555.主機 192.168.10.10 是第一個發起通訊的裝置。它使用來源連接埠號 1555,向 SRV1 發起 HTTP 連線。
- When packets from 192.168.10.10 reach inside interface of the R2 router, it will make a lookup in its mapping table. Since the mapping table is empty at the beginning, it finds no entries for host 192.168.10.10.當來自 192.168.10.10 的封包到達 R2 路由器的內部介面時,R2 會在其對應表中查詢。由於對應表一開始是空的,因此找不到主機 192.168.10.10 的任何項目。
- Because it is configured to perform PAT, the R2 router creates a mapping in the mapping table. It enters values from the source fields of the packet, 192.168.10.10:1555, as inside local values. Values from the destination fields of the packet, 209.165.201.1:80, are entered as outside local values. Since the R2 router is configured to translate only inside addresses, it will enter the same outside local values as outside global ones. It allocates 209.165.200.226 IPv4 public address and chooses the same port number 1555 for the translation and it enters these values as inside global values.因為 R2 路由器設定為執行 PAT,它會在對應表中建立一筆對應項目。它把封包來源欄位的值 192.168.10.10:1555 輸入為內部本地值;把封包目的欄位的值 209.165.201.1:80 輸入為外部本地值。由於 R2 路由器只設定為轉換內部位址,所以它會把外部本地值直接當作外部全域值輸入。它配置了公開 IPv4 位址 209.165.200.226,並為此次轉換選用相同的連接埠號 1555,並將這些值輸入為內部全域值。
- The R2 router performs translation of source IPv4 address and source port number and forwards the packet to SRV1.R2 路由器會轉換來源 IPv4 位址與來源連接埠號,並將封包轉送給 SRV1。
- Host 192.168.10.11 now initiates communication with SRV2.主機 192.168.10.11 現在發起與 SRV2 的通訊。
- R2 receives the packet from 192.168.10.11 on its inside interfaces and performs a lookup in the mapping table. There is only one entry and its local inside values (192.168.10.10:1555) do not match the source field values of the packet (192.168.10.11:1331).R2 在其內部介面上收到來自 192.168.10.11 的封包,並在對應表中查詢。表中只有一筆項目,其內部本地值(192.168.10.10:1555)與封包的來源欄位值(192.168.10.11:1331)不相符。
- R2 creates a new mapping in the mapping table. It enters values from the source fields of the packet, such as 192.168.10.11:1331, as inside local values. Values from the destination fields of the packet, such as 209.165.202.129:80, are entered as outside local IPv4 address and port number. It enters the same IPv4 address and port number as outside global values. It allocates the same 209.165.200.226 IPv4 public address and chooses the port number 1331 chosen by the client. It enters 209.165.200.226:1331 as inside global values.R2 在對應表中建立一筆新的對應項目。它把封包來源欄位的值,例如 192.168.10.11:1331,輸入為內部本地值;把封包目的欄位的值,例如 209.165.202.129:80,輸入為外部本地 IPv4 位址與連接埠號。它把相同的 IPv4 位址與連接埠號輸入為外部全域值。它配置相同的公開 IPv4 位址 209.165.200.226,並選用用戶端所選的連接埠號 1331,將 209.165.200.226:1331 輸入為內部全域值。
- R2 performs translation of source IPv4 address and source port number and forwards the packet to SRV2.R2 會轉換來源 IPv4 位址與來源連接埠號,並將封包轉送給 SRV2。
- Both hosts next initiate communication to other outside servers (host 192.168.10.10 to SRV3 and host 192.168.10.11 to SRV4); both hosts use the same source port number. Packets from host 192.168.10.10 reach the router R2 inside interface first. Since there are no mappings for 192.168.10.10:1444 in the mapping table, the router creates a new one. The allocated global IPv4 address is the same as in other translations. Since port number 1444 is not yet mapped, the router will preserve the same port number 1444. The inside global entry will be 209.165.200.226:1444.兩部主機接下來都對其他外部伺服器發起通訊(主機 192.168.10.10 對 SRV3,主機 192.168.10.11 對 SRV4),且兩部主機都使用相同的來源連接埠號。來自主機 192.168.10.10 的封包先到達 R2 路由器的內部介面。由於對應表中沒有 192.168.10.10:1444 的對應項目,路由器會建立一筆新的項目。所配置的全域 IPv4 位址與其他轉換相同。由於連接埠號 1444 尚未被對應,路由器會保留相同的連接埠號 1444,內部全域項目為 209.165.200.226:1444。
- When packets from host 192.168.10.11 reach the R2 router, the router will perform the same actions as for packets from 192.168.10.10 host. When it creates the new mapping, it will find that port number 1444 is already mapped. Therefore, it chooses a different value, which is 1024 in the example. The mapping for host 192.168.10.11 cannot preserve the original port value.當來自主機 192.168.10.11 的封包到達 R2 路由器時,路由器會執行與處理 192.168.10.10 主機封包相同的動作。當它建立新的對應項目時,會發現連接埠號 1444 已被對應,因此會選擇不同的值,在此範例中為 1024。主機 192.168.10.11 的對應無法保留原始連接埠值。

