NAT網絡地址轉換

隨着IPv6時代的到來,我也一直懷疑,是不是還有必要再去學習NAT技術——因爲網絡的資源不再如IPv4時代匱乏,而NAT技術正是爲解決IP地址的緊缺而存在的,如此,NAT便沒有存在的必要了。

但是,隨着這篇文章的翻譯,我的懷疑慢慢變成慶幸,漸而又變爲肯定,通過翻譯所學到的東西,不再僅僅是翻譯第一手資料帶來的成就感,更多的是通過翻譯,去領悟技術前輩們的智慧與經驗,也通過翻譯,養成自己從第一手資料獲得信息的習慣,從而將視野放得更寬,讓理解更爲透徹——至少,很多東西都是要經過仔細斟酌才真正轉化爲自己思想的一部分的。正是如此,我才堅定的要把這篇文章翻譯完,也如之前所提到的,如果時間允許的話,我會用C#來寫一些例子,讓大家更好的理解NAT技術,掌握NAT技術(主要涉及到即時通訊、文件對等傳輸和語音應用三個方面)。

這篇文章主要是介紹一下“代理”機制的起因以及給P2P應用帶來的不便,不需要任何基礎知識:)

1. Introduction
1、簡介
關鍵詞:
middleboxe(s) —— 我翻譯成“代理”,也許有更好的翻譯
host —— 我翻譯成“主機”,希望大家不要理解成服務器了,主機就是一臺普通的終端機

Present-day Internet has seen ubiquitous deployment of "middleboxes" such as network address translators(NAT), driven primarily by the ongoing depletion of the IPv4 address space. The asymmetric addressing and connectivity regimes established by these middleboxes, however, have created unique problems for peer-to-peer (P2P) applications and protocols, such as teleconferencing and multiplayer on-line gaming. These issues are likely to persist even into the IPv6 world, where NAT is often used as an IPv4 compatibility mechanism [NAT-PT], and firewalls will still be commonplace even after NAT is no longer required.

在當今的Internet中,普遍存在使用“代理”設備來進行網絡地址轉換(NAT),導致這種現象的原因是 IPV4 地址空間的資源耗盡危機。雖然不對稱 asymmetric 的地址分配和連通性制度已經在代理中被定義,但是卻給端對端應用程序和協議制定造成了一些特殊的問題。像電話會議和多媒體網絡遊戲。這些問題即使在IPV6世界中還是會存在,因爲NAT作爲IPV4的一種兼容性機制經常被使用[NAT-PT],並且防火牆將仍然將普遍存在,即使不再需要NAT技術。

Currently deployed middleboxes are designed primarily around the client/server paradigm, in which relatively anonymous client machines actively initiate connections to well-connected servers having stable IP addresses and DNS names.

Most middleboxes implement an asymmetric communication model in which hosts on the private internal network can initiate outgoing connections to hosts on the public network, but external hosts cannot initiate connections to internal hosts except as specifically configured by the middlebox's administrator. In the common case of NAPT, a client on the internal network does not have a unique IP address on the public Internet, but instead must share a single public IP address, managed by the NAPT, with other hosts on the same private network.The anonymity and inaccessibility of the internal hosts behind a middlebox is not a problem for client software such as web browsers, which only need to initiate outgoing connections. This inaccessibility is sometimes seen as a privacy benefit.

當前使用的“代理”技術主要是爲 客戶端/服務端 C/S 結構設計的,爲了實現那些需要連接但是又沒有固定IP地址的客戶端能夠連接到一臺配置好的擁有固定IP和DNS域名的服務器。
大多數的“代理”使用一種 asymmetric 通信模型,即 私網(局域網) 的主機能發起一個“外出”連接去連接公網上的主機。 但是公網上的主機卻無法發送信息給私網上的主機(除非對“代理”進行特殊的配置),NAPT(網絡地址端口轉換)的普通情況是,一個私網客戶端不需要一個公網的固定的IP地址,但是必須要共享一個由NAPT控制的公網的固定IP地址(當然這個NAPT是處於同一個私網內部的)。這樣的話,這些匿名的並且看起來難以觸及的藏在NAT之後的內網主機對於像 Web瀏覽器 這種軟件來說就不是一個問題,因爲內網的主機只需要發起向外部的連接就可以了。這樣一來,無法觸及也還是有他的優點的——那就是具有保密性。

In the peer-to-peer paradigm, however, Internet hosts that would normally be considered "clients" need to establish communication sessions directly with each other. The initiator and the responder might lie behind different middleboxes with neither endpoint having any permanent IP address or other form of public network presence. A common on-line gaming architecture, for example, is for the participating application hosts to contact a well-known server for initialization and administration purposes. Subsequent to this, the hosts establish direct connections with each other for fast and efficient propagation of updates during game play.

Similarly, a file sharing application might contact a well-known server for resource discovery or searching, but establish direct connections with peer hosts for data transfer. Middleboxes create problems for peer-to-peer connections because hosts behind a middlebox normally have no permanently usable public ports on the Internet to which incoming TCP or UDP connections from other peers can be directed.

RFC 3235 [NAT-APPL] briefly addresses this issue, but does not offer any general solutions.

然而,在P2P的應用中,Internet上的“客戶機”之間是需要建立一個通信會話直連的。邀請者和響應者也許會處於不同的NAT之後,也許他們都沒有固定IP或者即使有也不是公網的IP地址。舉例來說,在一個普通的網絡遊戲體系結構中,都是通過客戶端向一個具有公網固定IP的服務器發起申請進行初始化並通過驗證的。同時,客戶端之間也要建立直連,才使網絡間傳輸的速度加快,保證數據即時更新(不然搶不到裝備啊,呵呵)。

同樣的,一個文件共享應用程序也必須通過到一個服務器上去查找它想要的資源,然後再到擁有這個數據的主機上去下載(BT網站,走了一箇中介),“代理”造成了很多P2P直連的問題,因爲藏在“代理”之後的的主機通常沒有固定的端口來使其他的客戶端發起的TCP或UDP連接能夠最終到達。

RFC 3235[NAT-APPL] 簡要的提到了這個問題,但是沒有給出任何的解決方案。

In this document we address the P2P/middlebox problem in two ways. First, we summarize known methods by which P2P applications can work around the presence of middleboxes. Second, we provide a set of application design guidelines based on these practices to make P2P applications operate more robustly over currently-deployed middleboxes. Further, we provide design guidelines for future middleboxes to allow them to support P2P applications more effectively. Our focus is to enable immediate and wide deployment of P2P applications requiring to traverse middleboxes.

在這篇文章中,我們用兩種方式討論 P2P/代理 的問題。首先,概要的講敘已有的P2P應用程序能夠在現有的代理機制中的工作原理。然後,我們提供一組應用程序設計指南,基於已有的實踐,在現有的配置好的代理上,來使得P2P應用程序操作更加有條理。最後,我們提供了設計指南,爲以後的代理機制能夠更方便支持P2P應用程序。討論的焦點是如何 直接的、廣泛的 配置那些需要經過“代理”的P2P應用程序。
Peer-to-Peer (P2P) communication across middleboxes(術語篇)
2. Terminology
2. 術語

In this section we first summarize some middlebox terms. We focus hereon the two kinds of middleboxes that commonly cause problems for P2P applications.

在這一章節中,首先概要的介紹一下“代理”技術的一些術語。然後集中討論兩種造成P2P應用問題的代理機制。

Firewall
A firewall restricts communication between a private internal network and the public Internet, typically by dropping packets that are deemed unauthorized. A firewall examines but does not modify the IP address and TCP/UDP port information in packets crossing the boundary.

防火牆

防火牆限制了私網與公網的通信,它主要是將(防火牆)認爲未經授權的的包丟棄,防火牆只是檢驗包的數據,並不修改數據包中的IP地址和TCP/UDP端口信息。

Network Address Translator (NAT)

A network address translator not only examines but also modifies the header information in packets flowing across the boundary, allowing many hosts behind the NAT to share the use of a smaller number of public IP addresses (often one). Network address translators in turn have two main varieties:

網絡地址轉換(NAT)
當有數據包通過時,網絡地址轉換器不僅檢查包的信息,還要將包頭中的IP地址和端口信息進行修改。以使得處於NAT之後的機器共享幾個僅有的公網IP地址(通常是一個)。網絡地址轉換器主要有兩種類型:

Basic NAT

A Basic NAT maps an internal host's private IP address to a public IP address without changing the TCP/UDP port numbers in packets crossing the boundary. Basic NAT is generally only useful when the NAT has a pool of public IP addresses from which to make address bindings on behalf of internal hosts.

基礎NAT

基礎NAT 將私網主機的私有IP地址轉換成公網IP地址,但並不將TCP/UDP端口信息進行轉換。基礎NAT一般用在當NAT擁有很多公網IP地址的時候,它將公網IP地址與內部主機進行綁定,使得外部可以用公網IP地址訪問內部主機。(譯者注:實際上是隻將IP轉換,192.168.0.23 <-> 210.42.106.35,這與直接設置IP地址爲公網IP還是有一定區別的,特別是對於企業來說,外部的信息都要經過統一防火牆才能到達內部,但是內部主機又可以使用公網IP)

Network Address/Port Translator (NAPT)

By far the most common, a Network Address/Port Translator examines and modifies both the IP address and the TCP/UDP port number fields of packets crossing the boundary, allowing multiple internal hosts to share a single public IP address simultaneously.

Refer to [NAT-TRAD] and [NAT-TERM] for more general information on NAT taxonomy and terminology. Additional terms that further classify NAPT are defined in more recent work [STUN]. When an internal host opens an outgoing TCP or UDP session through a network address/port translator, the NAPT assigns the session a public IP address and port number so that subsequent response packets from the external endpoint can be received by the NAPT, translated, and forwarded to the internal host. The effect is that the NAPT establishes a port binding between (private IP address, private port number) and (public IP address, public port number).

The port binding defines the address translation the NAPT will perform for the duration of the session. An issue of relevance to P2P applications is how the NAT behaves when an internal host initiates multiple simultaneous sessions from a single (private IP, private port) pair to multiple distinct endpoints on the external network.



網絡地址和端口轉換 (NAPT)

這是最普遍的情況,網絡地址/端口轉換器檢查、修改包的IP地址和TCP/UDP端口信息,這樣,更多的內部主機就可以同時使用一個公網IP地址。

請參考[NAT-TRAD]和[NAT-TERM]兩個文檔瞭解更多的NAT分類和術語信息。另外,關於NAPT的分類和術語,[STUN]在最近做了更多的定義。當一個內部網主機通過NAT打開一個“外出”的TCP或UDP會話時,NAPT分配給這個會話一個公網IP和端口,用來接收外網的響應的數據包,並經過轉換通知內部網的主機。這樣做的效果是,NAPT在 [私有IP:私有端口] 和[公網IP:公網端口]之間建立了一個端口綁定。

端口綁定指定了NAPT將在這個會話的生存期內進行地址轉換任務。這中間存在一個這樣的問題,如果P2P應用程序從內部網絡的一個[私有IP地址:端口]對同時發出多條會話給不同的外網主機,那麼NAT會怎樣處理呢?請看以下幾種方案。

Cone NAT

After establishing a port binding between a (private IP, private port) tuple and a (public IP, public port) tuple, a cone NAT will re-use this port binding for subsequent sessions the application may initiate from the same private IP address and port number, for as long as at least one session using the port binding remains active.

錐形NAT

(譯者注:爲什麼叫做錐形呢?請看以下圖形,終端和外部服務器,都通過NAT分派的這個綁定地址對來傳送信息,就象一個漏斗一樣,篩選並傳遞信息)

當建立了一個 [私有IP:端口]-[公網IP:端口] 端口綁定之後,對於來自同一個[私有IP:端口]會話,錐形NAT服務器允許發起會話的應用程序 重複使用這個端口綁定,一直到這個會話結束才解除(端口綁定)。

For example, suppose Client A in the diagram below initiates two simultaneous outgoing sessions through a cone NAT, from the same internal endpoint (10.0.0.1:1234) to two different external servers, S1 and S2. The cone NAT assigns just one public endpoint tuple(元組), 155.99.25.11:62000, to both of these sessions, ensuring that the "identity" of the client's port is maintained across address translation. Since Basic NATs and firewalls do not modify port numbers as packets flow across the middlebox, these types of middleboxes can be viewed as a degenerate form of Cone NAT.

例如,假設 Client A(IP地址信息如上圖所示)通過一個 錐形NAT 同時發起兩個外出的連接,它使用同一個內部端口(10.0.0.1:1234)給公網的兩臺不同的服務器,S1和S2。錐形NAT 只分配一個公網IP和端口(155.99.25.11:62000)給這個兩個會話,通過地址轉換可以 確保 Client使用端口的“同一性”(譯者注:即這個Client只使用這個端口)。而基礎NATs和防火牆卻不能修改經過的數據包端口號,它們可以看作是錐形NAT的精簡版本。
Symmetric NAT

A symmetric NAT, in contrast, does not maintain a consistent port binding between (private IP, private port) and (public IP, public port) across all sessions.

Instead, it assigns a new public port to each new session. For example, suppose Client A initiates two outgoing sessions from the same port as above, one with S1 and one with S2. A symmetric NAT might allocate the public endpoint 155.99.25.11:62000 to session 1, and then allocate a different public endpoint 155.99.25.11:62001, when the application initiates session 2. The NAT is able to differentiate between the two sessions for translation purposes because the external endpoints involved in the sessions (those of S1 and S2) differ, even as the endpoint identity of the client application is lost across the address translation boundary.

對稱NAT
對稱NAT,與Cone NAT是大不相同的,並不對會話進行端口綁定,而是分配一個全新的 公網端口 給每一個新的會話。

還是上面那個例子:如果 Client A (10.0.0.1:1234)同時發起兩個 "外出" 會話,分別發往S1和S2。對稱Nat會分配公共地址155.99.25.11:62000給Session1,然後分配另一個不同的公共地址155.99.25.11:62001給Session2。對稱Nat能夠區別兩個不同的會話並進行地址轉換,因爲在 Session1 和 Session2中的外部地址是不同的,正是因爲這樣,Client端的應用程序就迷失在這個地址轉換邊界線了,因爲這個應用程序每發出一個會話都會使用一個新的端口,無法保障只使用同一個端口了。

The issue of cone versus symmetric NAT behavior applies equally to TCP and UDP traffic. Cone NAT is further classified according to how liberally the NAT accepts incoming traffic directed to an already-established (publicIP, public port) pair. This classification generally applies only to UDP traffic, since NATs and firewalls reject incoming TCP connection attempts unconditionally unless specifically configured to do otherwise.

在TCP和UDP通信中, (到底是使用同一個端口,還是分配不同的端口給同一個應用程序),錐形NAT和對稱NAT各有各的理由。當然錐形NAT在根據如何公平地將NAT接受的連接直達一個已創建的地址對上有更多的分類。這個分類一般應用在Udp通信(而不是Tcp通信上),因爲NATs和防火牆阻止了試圖無條件傳入的TCP連接,除非明確設置NAT不這樣做。這些分類如下:

Full Cone NAT

After establishing a public/private port binding for a new outgoing session, a full cone NAT will subsequently accept incoming traffic to the corresponding public port from ANY external endpoint on the public network. Full cone NAT is also sometimes called "promiscuous" NAT.

全雙工錐形NAT

當內部主機發出一個“外出”的連接會話,就會創建了一個 公網/私網 地址,一旦這個地址對被創建,全雙工錐形NAT會接收隨後任何外部端口傳入這個公共端口地址的通信。因此,全雙工錐形NAT有時候又被稱爲"混雜"NAT。

Restricted Cone NAT

A restricted cone NAT only forwards an incoming packet directed to a public port if its external (source) IP address matches the address of a node to which the internal host has previously sent one or more outgoing packets. A restricted cone NAT effectively refines the firewall principle of rejecting unsolicited incoming traffic, by restricting incoming traffic to a set of "known" external IP addresses.

受限制的錐形NAT

受限制的錐形NAT會對傳入的數據包進行篩選,當內部主機發出“外出”的會話時,NAT會記錄這個外部主機的IP地址信息,所以,也只有這些有記錄的外部IP地址,能夠將信息傳入到NAT內部,受限制的錐形NAT 有效的給防火牆提煉了篩選包的原則——即限定只給那些已知的外部地址“傳入”信息到NAT內部。

Port-Restricted Cone NAT

A port-restricted cone NAT, in turn, only forwards an incoming packet if its external IP address AND port number match those of an external endpoint to which the internal host has previously sent outgoing packets. A port-restricted cone NAT provides internal nodes the same level of protection against unsolicited incoming traffic that a symmetric NAT does, while maintaining a private port's identity across translation.

端口受限制的Cone NAT

端口受限制的錐形NAT,與受限制的錐形NAT不同的是:它同時記錄了外部主機的IP地址和端口信息,端口受限制的錐形NAT給內部節點提供了同一級別的保護,在維持端口“同一性”過程中,將會丟棄對稱NAT傳回的信息。

Finally, in this document we define new terms for classifying the P2P-relevant behavior of middleboxes:

最後,在這篇文檔裏我們將定義一組新的術語 ,以便更好的對P2P代理相關的行爲進行分類。

P2P應用程序

P2P應用程序是指,在已有的一個公共服務器的基礎上,並分別利用自己的私有地址或者公有地址(或者兩者兼備)來建立一個端到端的會話通信。

P2P-Application

P2P-application as used in this document is an application in which each P2P participant registers with a public registration server, and subsequently uses either its private endpoint, or public endpoint, or both, to establish peering sessions.

P2P-Middlebox

A P2P-Middlebox is middlebox that permits the traversal of P2P applications.

P2P代理

P2P代理是一個允許 P2P應用程序進行通信的代理機制

P2P-firewall

A P2P-firewall is a P2P-Middlebox that provides firewall functionality but performs no address translation.

P2P防火牆
P2P防火牆是一個提供了防火牆的功能的P2P代理,但是不進行地址轉換.

P2P-NAT
A P2P-NAT is a P2P-Middlebox that provides NAT functionality, and may also provide firewall functionality. At minimum, a P2P-Middlebox must implement Cone NAT behavior for UDP traffic, allowing applications to establish robust P2P connectivity using the UDP hole punching technique.

P2P-NAT

P2P-NAT 是一個 P2P代理,提供了NAT的功能,也提供了防火牆的功能,一個最簡的P2P代理必須具有 錐形NAT對Udp通信支持的功能,並允許應用程序利用Udp打洞技術建立強健的P2P連接。

Loopback translation

When a host in the private domain of a NAT device attempts to connect with another host behind the same NAT device using the public address of the host, the NAT device performs the equivalent of a "Twice-nat" translation on the packet as follows. The originating host's private endpoint is translated into its assigned public endpoint, and the target host's public endpoint is translated into its private endpoint, before the packet is forwarded to the target host. We refer the above translation performed by a NAT device as "Loopback translation".

迴環轉換

當NAT的私網內部機器想通過公共地址來訪問同一臺局域網內的機器的時,NAT設備等價於做了兩次NAT的事情,在包到達目標機器之前,先將私有地址轉換爲公網地址,然後再將公網地址轉換回私有地址。我們把具有上敘轉換功能的NAT設備叫做“迴環轉換”設備 

NAT有三種類型:靜態NAT(Static NAT)、動態地址NAT(Pooled NAT)、網絡地址端口轉換NAPT(Port-Level NAT)。

其中靜態NAT設置起來最爲簡單和最容易實現的一種,內部網絡中的每個主機都被永久映射成外部網絡中的某個合法的地址。而動態地址NAT則是在外部網絡中定 義了一系列的合法地址,採用動態分配的方法映射到內部網絡。NAPT則是把內部地址映射到外部網絡的一個IP地址的不同端口上。根據不同的需要,三種 NAT方案各有利弊。

動態地址NAT只是轉換IP地址,它爲每一個內部的IP地址分配一個臨時的外部IP地址,主要應用於撥號,對於頻繁的遠程聯接也可以採用動態NAT。當遠程用戶聯接上之後,動態地址NAT就會分配給他一個IP地址,用戶斷開時,這個IP地址就會被釋放而留待以後使用。

網絡地址端口轉換NAPT(Network Address Port Translation)是人們比較熟悉的一種轉換方式。NAPT普遍應用於接入設備中,它可以將中小型的網絡隱藏在一個合法的IP地址後面。NAPT與 動態地址NAT不同,它將內部連接映射到外部網絡中的一個單獨的IP地址上,同時在該地址上加上一個由NAT設備選定的TCP端口號。
在Internet 中使用NAPT時,所有不同的信息流看起來好像來源於同一個IP地址。這個優點在小型辦公室內非常實用,通過從ISP處申請的一個IP地址,將多個連接通 過NAPT接入Internet。實際上,許多SOHO遠程訪問設備支持基於PPP的動態IP地址。這樣,ISP甚至不需要支持NAPT,就可以做到多個內部IP地址共用一個外部IP地址上Internet,雖然這樣會導致信道的一定擁塞,但考慮到節省的ISP上網費用和易管理的特點,用NAPT還是很值 得的。

還可以用PAT的。只是PAT 要比NAT對設備要求高,特別是用戶數量大流量大的時候

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章