In NAT terminology, addresses are categorized into two types. All classifications described apply to the border device that performs translations.
在 NAT 術語中,位址分為兩種類型。以下所有分類都是就執行轉譯的邊界裝置而言。
The first classification divides addresses based on where they exist in the network:
第一種分類依位址在網路中的所在位置區分:
- Inside addresses are addresses that belong to the network in question, such as addresses of devices internal to the network. The inside network is the set of networks that are subject to translation.內部位址(Inside addresses)是屬於所討論網路的位址,例如網路內部裝置的位址。內部網路(inside network)是指受轉譯影響的一組網路。
- Outside addresses are all addresses that do not belong to the network in question. The outside network refers to all other addresses.外部位址(Outside addresses)是所有不屬於所討論網路的位址。外部網路(outside network)是指其他所有位址。
The second classification divides addresses based on where they are "viewed:"
第二種分類依位址被「觀察」的角度區分:
- Local addresses are address values that are "seen" by a local device or, in other words, address values that are intended to be used by the devices in the local (inside) network.本地位址(Local addresses)是本地裝置「看到」的位址值,換句話說,就是要供本地(內部)網路裝置使用的位址值。
- Global addresses are address values as seen globally or, in other words, address values meant be used by the devices in external (outside) networks. You can also think of a global address as the address seen or used by devices in the internet, when they refer to an inside device. However, remember that NAT can also translate between private only address realms. Devices in the internet always see public addresses.全域位址(Global addresses)是全域可見的位址值,換句話說,就是要供外部(outside)網路裝置使用的位址值。也可以把全域位址想成外部網路裝置在指涉某個內部裝置時所看到或使用的位址。不過請記住,NAT 也可以在僅限私有位址領域之間進行轉譯。網際網路上的裝置一律只看到公有位址。
These are the most important types of addresses in NAT:
以下是 NAT 中最重要的位址類型:
- Inside local: Host address on the inside network內部本地(Inside local):內部網路上主機的位址
- Inside global: Translated inside local address內部全域(Inside global):轉譯後的內部本地位址
In NAT terminology, the inside network is the set of networks that are subject to translation. The outside network refers to all other addresses. Usually, these other addresses are valid addresses that are located on the Internet.
在 NAT 術語中,內部網路(inside network)是指受轉譯影響的一組網路。外部網路(outside network)是指其他所有位址。通常這些其他位址是位在網際網路上的有效位址。
Cisco defines these NAT terms:
Cisco 對這些 NAT 術語的定義如下:
- Inside local address: The IP address assigned to a host on the inside network. This is the address configured as a parameter of the computer OS or received via dynamic address allocation protocols such as DHCP. The address is likely not a legitimate IP address assigned by the Network Information Center (NIC) or service provider. The IP ranges here are typically those from the private IP address ranges described in RFC 1918. In this example, when PC1 sends packets to SRV1, PC1 uses the 192.168.10.10 as source IPv4 address, which is indicated as the inside local address in the mapping table.內部本地位址(Inside local address):指派給內部網路上主機的 IP 位址。這是設定在電腦作業系統中的參數,或透過 DHCP 等動態位址配置協定取得的位址。此位址通常不是由網路資訊中心(NIC)或服務供應商指派的合法 IP 位址。這裡的 IP 範圍通常取自 RFC 1918 所述的私有 IP 位址範圍。在此範例中,當 PC1 傳送封包給 SRV1 時,PC1 使用 192.168.10.10 作為來源 IPv4 位址,此位址在對映表中標示為內部本地位址。
- Inside global address: The translated inside local address. It is typically a public IPv4 address. For example, when PC1 sends packets to SRV1, its inside local address is translated to an inside global address, which is 209.165.200.5. In typical NAT implementations, where only inside NAT is performed, the inside global IPv4 address is a public IPv4 address.內部全域位址(Inside global address):轉譯後的內部本地位址,通常是公有 IPv4 位址。例如,當 PC1 傳送封包給 SRV1 時,其內部本地位址會被轉譯為內部全域位址 209.165.200.5。在僅執行內部 NAT 的典型實作中,內部全域 IPv4 位址是公有 IPv4 位址。
- Outside global address: The IPv4 address that the host owner assigns to a host on the outside network. The outside global address is allocated from a globally routable address or network space. This address is the address that the device owner assigns to the device for the "external" use. As far as the NAT device is concerned, this is the source IPv4 address the NAT device sees in the packets arriving on its outside interface. In this example, that is the SRV1’s IPv4 address 209.165.201.1.外部全域位址(Outside global address):由主機擁有者指派給外部網路上主機的 IPv4 位址。外部全域位址是從全域可路由的位址或網路空間中配置的。此位址是裝置擁有者指派給裝置作「外部」使用的位址。就 NAT 裝置而言,這是 NAT 裝置在其外部介面收到封包時看到的來源 IPv4 位址。在此範例中,即為 SRV1 的 IPv4 位址 209.165.201.1。
- Outside local address: The IPv4 address of an outside host as it appears to the inside network. Not necessarily public, the outside local address is allocated from a routable address space on the inside. Since only inside NAT is performed in this example, the outside local IPv4 address is the SRV1’s IPv4 address 209.165.201.1 (which is the same as its outside global address).外部本地位址(Outside local address):外部主機在內部網路眼中所呈現的 IPv4 位址。外部本地位址不一定是公有位址,它是從內部的可路由位址空間中配置的。由於此範例只執行內部 NAT,外部本地 IPv4 位址即為 SRV1 的 IPv4 位址 209.165.201.1(與其外部全域位址相同)。
A good way to remember what is local and what is global is to add the word visible. An address that is locally visible normally implies a private IP address, and an address that is globally visible normally implies a public IP address. The rest is simple. Inside means internal to your network, and outside means external to your network. So, for example, an inside global address means that the device is physically inside your network and has an address that is visible from the Internet. It could be a web server, for instance.
記住哪個是本地、哪個是全域的一個好方法,是加上「可見」這個詞。本地可見的位址通常代表私有 IP 位址,全域可見的位址通常代表公有 IP 位址。其餘就很簡單了:內部(inside)表示在你的網路內部,外部(outside)表示在你的網路外部。舉例來說,內部全域位址表示該裝置實體上位於你的網路內部,但擁有一個從網際網路可見的位址,例如它可能是一台網頁伺服器。
To classify NAT, it is important to clarify which header fields can be the subject of translation first. So far, the NAT explanation focused on IPv4 address fields. But NAT implementations can also translate port numbers.
要對 NAT 進行分類,首先必須釐清哪些標頭欄位可能是轉譯的對象。到目前為止,NAT 的說明都聚焦在 IPv4 位址欄位。但 NAT 實作也可以轉譯連接埠號。
Depending on the scope of translation (only IPv4 address or both IPv4 address and port number) and depending on the translation mechanism details, there are these NAT implementations:
依轉譯範圍(僅 IPv4 位址,或 IPv4 位址與連接埠號皆有)以及轉譯機制細節的不同,NAT 有以下幾種實作方式:
- Static NAT maps a local IPv4 address to a global IPv4 address (one to one). Port numbers are not translated. Static NAT is particularly useful when a device must be accessible from an external network, such as when a device must have a static, unchanging address accessible from the internet. Static NAT is usually used when a company has a server that must be always reachable, from both inside and outside networks. Both server addresses, local and global, are static. So the translation is also always static. The server's local IPv4 address will always be translated to the known global IPv4 address. This fact also implies that one global address cannot be assigned to any other device. It is an exclusive translation for one local address. Static translations last forever.靜態 NAT(Static NAT)將本地 IPv4 位址對映到全域 IPv4 位址(一對一)。連接埠號不會被轉譯。靜態 NAT 特別適用於裝置必須能從外部網路存取的情況,例如裝置必須擁有一個從網際網路可存取、固定不變的位址。當公司有一台必須隨時可被內部與外部網路連線的伺服器時,通常會使用靜態 NAT。伺服器的本地與全域位址都是靜態的,因此轉譯也一律是靜態的。伺服器的本地 IPv4 位址永遠會被轉譯為已知的全域 IPv4 位址。這也表示該全域位址不能再指派給任何其他裝置,它是專屬於某個本地位址的獨佔轉譯。靜態轉譯會永久存在。
- Dynamic NAT maps local IPv4 addresses to a pool of global IPv4 addresses. When an inside device accesses an outside network, it is assigned a global address that is available at the moment of translation. The assignment follows a first-come first-served algorithm, there are no fixed mappings; therefore, the translation is dynamic. The number of translations is limited by the size of the pool of global addresses. When using dynamic NAT, make sure that enough global addresses are available to satisfy the needed number of user sessions. Dynamic translations usually have a limited duration. After this time elapses, the mapping is no longer valid and the global IPv4 address is made available for new translations. An example of when dynamic NAT is used is a merger of two companies that are using the same private address space. Dynamic NAT effectively readdresses packets from one network and is an alternative to complete readdressing of one network.動態 NAT(Dynamic NAT)將本地 IPv4 位址對映到一個全域 IPv4 位址集區(pool)。當內部裝置存取外部網路時,會被指派一個當下可用的全域位址。此指派遵循先到先得的演算法,沒有固定對映,因此稱為動態轉譯。轉譯數量受限於全域位址集區的大小。使用動態 NAT 時,務必確保有足夠的全域位址可滿足所需的使用者連線數量。動態轉譯通常有一段有限的存續時間,時間一到,該對映就不再有效,全域 IPv4 位址便可供新的轉譯使用。動態 NAT 常見的使用情境是兩家使用相同私有位址空間的公司合併時。動態 NAT 能有效地重新定址其中一個網路的封包,是完全重新定址另一個網路的替代方案。
- Network Address and Port Translation (NAPT) or Port Address Translation (PAT) maps multiple local IPv4 addresses to just a single global IPv4 address (many to one). This process is possible because the source port number is translated also. Therefore, when two local devices communicate to an external network, packets from the first device will get the global IPv4 address and a port number X, and the packets from the second device will get the same global IPv4 address but a different port number Y. PAT is also known as NAT overloading, because you overload one global address with ports until you exhaust available port numbers. The mappings in the case of PAT have the format of local_IP:local_port " global_IP:global_port. PAT enables multiple local devices to access the internet, even when the device bordering the ISP has only one public IPv4 address assigned. PAT is the most common type of network address translation.網路位址與連接埠轉譯(NAPT)或連接埠位址轉譯(PAT)將多個本地 IPv4 位址對映到單一個全域 IPv4 位址(多對一)。這是因為來源連接埠號也一併被轉譯。因此,當兩台本地裝置與外部網路通訊時,第一台裝置的封包會取得全域 IPv4 位址及連接埠號 X,第二台裝置的封包則取得相同的全域 IPv4 位址,但使用不同的連接埠號 Y。PAT 也稱為 NAT 過載(NAT overloading),因為你會用連接埠號不斷疊加使用同一個全域位址,直到用盡可用的連接埠號為止。PAT 的對映格式為 local_IP:local_port=global_IP:global_port。PAT 讓多台本地裝置即使在面向 ISP 的邊界裝置只有一個公有 IPv4 位址時,也能存取網際網路。PAT 是最常見的網路位址轉譯類型。
The inside and outside definition is important for NAT operation. The figure illustrates the importance of inside and outside definitions regarding the processing sequence. When a packet travels from an inside domain to an outside domain, it is received at an inside interface, routed, and, only then, addresses are translated to global addresses. At this point, the border device automatically creates translation-mapping (basically a "dictionary entry") if the mapping does not exist. The packet is then forwarded out the exit (outside) interface. In dynamic translation, the border device also sets a timeout value for each mapping it creates. The key point to remember is that with dynamic NAT implementation, mapping creation is "provoked" by inside to outside traffic. Without outbound traffic, no mappings are created.
內部與外部的定義對 NAT 運作十分重要。此圖說明了內部與外部定義在處理順序上的重要性。當封包從內部網域傳往外部網域時,會先在內部介面被接收、進行路由,然後才將位址轉譯為全域位址。此時,若對映不存在,邊界裝置會自動建立轉譯對映(基本上就是一筆「字典項目」)。接著封包會從出口(外部)介面轉送出去。在動態轉譯中,邊界裝置也會為它建立的每一筆對映設定逾時值。要記住的重點是:在動態 NAT 實作中,對映的建立是由「內部到外部」的流量所觸發的。若沒有出向流量,就不會建立任何對映。
When a packet travels from an outside domain to an inside domain, the process is reversed: packets arriving from the outside with their global addresses are first translated back to their local addresses and, only then, routed. Note that the inbound traffic has the translated address (the inside global address) in the destination IPv4 header. Since the routing happens after translation, it will be based on the original, local IPv4 address. However, all outside routers—routers in external networks—must have a route towards the global IPv4 address in order for packets to reach the inside network. Only the global address is visible in the external world.
當封包從外部網域傳往內部網域時,流程則相反:從外部到來、帶著全域位址的封包會先被轉譯回本地位址,然後才進行路由。請注意,入向流量的目的地 IPv4 標頭中帶的是經過轉譯的位址(內部全域位址)。由於路由是在轉譯之後才進行,因此會依原始的本地 IPv4 位址來路由。然而,所有外部路由器(外部網路中的路由器)都必須有一條通往該全域 IPv4 位址的路由,封包才能到達內部網路。在外部世界中,只有全域位址是可見的。
What happens if a packet arrives from the outside, and there is no mapping for its destination address? When NAT service on a device cannot find a mapping for an inbound packet, it will discard the packet. When is this situation encountered? Dynamic NAT creates mappings when an inside host initiates communication with the outside. However, dynamic mappings do not last forever. After a dynamic mapping timeout expires, the mapping is automatically deleted. Recall that dynamic mappings are not created unless there is inside to outside traffic. Also, when NAT is required, the outside to inside communication will not be possible, unless there was prior outbound communication. In other words, NAT does not allow requests initiated from the outside.
如果封包從外部到來,但其目的位址沒有對應的對映,會發生什麼事?當裝置上的 NAT 服務找不到某入向封包的對映時,會直接丟棄該封包。這種情況何時會發生?動態 NAT 是在內部主機發起與外部的通訊時才建立對映,但動態對映並非永久存在。動態對映逾時到期後,該對映會自動被刪除。請記住,若沒有內部到外部的流量,就不會建立動態對映。此外,當需要使用 NAT 時,除非先前已有出向通訊,否則無法進行由外部到內部的通訊。換句話說,NAT 不允許由外部發起的請求。
If the return communication is received after the timeout expires, there would be no mappings, and the packets will be discarded. You will not encounter this issue in static NAT. A static NAT configuration creates static mappings, which are not time limited. In other words, statically created mappings are always present. Therefore, those packets from outside can arrive at any moment, and they can be either requests initiating communication from the outside, or they can be responses to requests sent from inside.
如果逾時到期後才收到回傳的通訊,此時已無對映,封包將被丟棄。靜態 NAT 則不會遇到此問題。靜態 NAT 設定所建立的靜態對映沒有時間限制,換句話說,靜態建立的對映永遠存在。因此,這些來自外部的封包可能在任何時刻到達,它們可能是由外部發起通訊的請求,也可能是對內部所發送請求的回應。
The examples show how Network Address Translation is configured to enable internet access. Your task is to examine the examples and match the correct type of address with the callout letter displayed on the figure.
以下範例說明如何設定網路位址轉譯以啟用網際網路存取。你的任務是檢視這些範例,並將正確的位址類型與圖中標示的字母對應起來。
| Outside local address外部本地位址 | AA |
| Inside local address內部本地位址 | DD |
| Outside global address,外部全域位址 | BB |
| Inside global address內部全域位址 | CC |
| Inside local address內部本地位址 | BB |
| Outside local address外部本地位址 | CC |
| Inside global address內部全域位址 | AA |
| Outside global address外部全域位址 | DD |


