您可能听说过称为IP 地址(IP Address)的东西,如果您没有听说过,请先阅读我们解释该概念的文章,但对于这篇关于NAT(网络地址转换(Network Address Translation))的文章,您需要知道 IP 地址是有限的。网络上的两台设备也不能具有相同的 IP 地址(same IP address)。
问题是不同的网络,例如您的家庭网络和整个互联网上的计算机,将不可避免地具有相同的 IP 地址或在其网络地址的设置方式上不兼容。NAT解决了 IP 地址稀缺和需要相互通信的网络不兼容的问题。
大多数时候这不是您需要担心的事情,但有时您的互联网问题是NAT出错的结果。因此,对NAT(NAT)是什么以及它是如何工作的有一个基本的了解可以帮助解决这个问题。
NAT 发生在哪里?(Where Does NAT Happen?)
对于像我们这样的普通用户,NAT是由您的路由器处理的工作。路由器有一个由您的服务提供商分配给它的 IP 地址(IP address assigned to it by your service provider)。这是互联网上其他人看到的地址。家庭网络上的每台(Every)设备都分配有一个私有 IP 地址,这是它们用来相互通信的地址。
当您网络上的设备想要与外界通信时,路由器会代替它。路由器有一个公共 IP 地址,其他人都可以看到。它跟踪哪些私有 IP 地址请求了哪些流量,并确保将数据包路由到正确的设备。
私有与公共 IP 地址(Private Vs Public IP Addresses)
在我们了解您将遇到的NAT类型之前,最好快速讨论一下私有和公共 IP 地址。
按照惯例,某些 IP 地址范围是为特定目的而保留的。公共 IP(Public IP)地址保留给面向 Internet 的设备,例如您的路由器或 Web 服务器。您的ISP为您的路由器分配了一个公共 IP 地址,该地址是网络上所有外人都能看到的地址。通常,私有 Internet 地址类似于 192.168.0.X 或 10.1.1.X,但这因路由器而异。虽然私有地址在私有网络中必须是唯一的,但它们几乎可以肯定在私有网络之间是相同的。
如上所述,公共 IP 地址是互联网上其他所有人都能看到的地址。当您访问一个网站时,您的浏览器会连接到其公共 IP 地址。通常,家庭路由器不允许通过不是由它发起的公共 IP 地址直接访问。这意味着您不能只输入朋友路由器的公共地址就可以访问他们网络上的设备。
但是,某些 Web 服务和设备(例如视频游戏机)需要更宽松的方法。这就是各种NAT类型发挥作用的地方。通常问题是由于您的连接的NAT类型与您尝试使用的服务类型不符。接下来我们将更详细地介绍NAT类型。
NAT 类型(NAT Types)
虽然NAT(NAT)的基本概念并不太复杂,但在实践中它的实际工作方式存在很多细微差别。有多种类型的NAT适合不同的翻译需求。
静态 NAT(Static NAT)
NAT的静态样式将一个特定的私有 IP 地址映射到一个特定的公共 IP 地址。使用静态NAT,可以直接访问映射到公共地址的设备。
这是用于也是专用网络一部分的Web 服务器(web servers)的 NAT 类型。通过此静态地图访问服务器时,您无法同时访问其专用网络上的其他设备。但是,服务器本身可以毫无问题地与其专用网络上的设备通信。
动态 NAT(Dynamic NAT)
(Dynamic NAT)当您有一个想要动态分配给私有网络上设备的公共 IP 地址池时,将使用 动态 NAT 。
这不用于从网络外部访问 Web 服务器。相反,当专用网络上的设备想要访问 Internet 或不在专用网络上的其他资源时,会为其分配池中的一个公共 IP 地址。
NAT 过载 (PAT)(NAT Overload (PAT))
使用静态和动态NAT的元素,NAT过载样式是最常见的形式,也是大多数家庭路由器使用的形式。它被称为具有端口地址转换(Port Address Translation)( PAT ) 的(PAT)NAT以及其他名称。
在大多数情况下,您的路由器分配有一个公共 IP 地址,但您网络上的所有设备可能都需要访问互联网。使用NAT过载,路由器在其公共 IP 地址和服务器的公共 IP 地址之间建立连接。然后它将数据包发送到服务器,但也分配一个返回目标端口。
这有助于它知道哪些数据包用于您的专用网络上的哪个 IP 地址。顺便说一句,这就是过程的PAT部分。
专有 NAT 类型(Proprietary NAT Types)
为了更加混乱,一些公司决定对事物进行自己的NAT分类。这主要适用于游戏机,您会发现当您进行网络测试时,它会告诉您您使用的是NAT Type 2或NAT Type D之类的东西。
这些分类特定于控制台或设备制造商,您应该查看他们的官方文档以了解每个分类的实际含义。
NAT 问题的常见修复(Common Fixes for NAT Issues)
大多数时候,对于大多数人来说,NAT可以完美运行并且完全透明。但是,有时它会发生故障或妨碍工作。
再一次,游戏机最有可能遇到问题,因为它们的某些服务需要您的网络接受来自外部对您的公共 IP 地址的访问请求,因为标准NAT配置通常不允许这样做。好消息是,您可以尝试一些常见的修复方法来减少NAT的限制并允许传入连接。
首先,访问您的路由器(根据其手册)并检查UPnP(通用即插即用)是否已打开。此功能允许本地网络上的应用程序自动转发端口(forward ports),而无需您搞乱网络设置。请注意,您网络上的任何恶意软件(例如恶意软件)也可以使用UPnP。如果您使用此功能,请(Make)确保您的设备都被扫描并清除。
您还可以选择进行手动端口转发,以便需要不太严格连接的设备可以根据具体情况进行处理。
这只是自然的 (It’s Only NATural )
这就是您需要了解的关于什么是NAT的全部内容。NAT工作原理的具体细节可能会很快变得复杂,但只要您了解NAT在高层次上的作用以及它有时会出错的原因,您就会明白为什么某些修复在您运行时有效或无效进入网络问题。
What Is NAT, How Does It Work, and Why Is It Used?
You might have heard of something called an IP Address, – if you haven’t, start off by reading our article explaining the concept – but for this article on NAT (Network Address Translation) you need to know that IP addresses are limited. You also can’t have two devices on a network with the same IP address.
The problem is that different networks, such as your home network and computers on the internet as a whole, will inevitably have the same IP addresses or have incompatibilities in how their network addresses are set up. NAT solved both the problem of IP address scarcity and incompatible networks that need to talk to each other.
Most of the time it’s not something you need to worry about, but sometimes your internet woes are a result of NAT going wrong. So having a basic understanding of what NAT is and how it works can help solve the issue.
Where Does NAT Happen?
In the case of regular users like us, NAT is a job handled by your router. The router has an IP address assigned to it by your service provider. That’s the address that the rest of the internet sees. Every device on your home network is assigned a private IP address, which is what they’ll use to talk to each other.
When a device on your network wants to communicate with the outside world, the router stands in for it. The router has a public IP address, which everyone else sees. It keeps track of which private IP addresses requested what traffic and makes sure the data packets are routed to the right device.
Private Vs Public IP Addresses
Before we get into the types of NAT you’ll encounter, it’s a good idea to quickly discuss private and public IP addresses.
By convention, certain ranges of IP addresses are reserved for specific purposes. Public IP addresses are reserved for the internet-facing devices such as your router or web servers. Your ISP allocates a public IP address to your router and that’s the address that all outsiders on the web see. Typically a private internet address is something like 192.168.0.X or 10.1.1.X, but this varies from one router to the next. While private addresses have to be unique within a private network, they are almost certainly the same between private networks.
A public IP address, as mentioned above, is the one seen by everyone else on the internet. When you visit a website, your browser is connected to its public IP address. Typically, home routers don’t allow direct access through its public IP address that wasn’t initiated by it. This means you can’t just type in the public address of your friend’s router and have access to devices on their network.
However, some web services and devices, such as video game consoles, need a more lenient approach. This is where various NAT types come into play. Often problems arise from your connection’s NAT type being wrong for the type of service you’re trying to use. We’ll cover NAT types in more detail next.
NAT Types
While the basic idea of what NAT is isn’t too complicated, in practice there’s a lot of nuance to how it actually works. There are various types of NAT that are appropriate for different translation needs.
Static NAT
The static style of NAT maps one specific private IP address to a specific public IP address. With static NAT it’s possible to access the device mapped to the public address directly.
This is the type of NAT used for web servers that are also part of a private network. When accessing the server through this static map, you can’t also access the other devices on its private network. The server itself, however, can talk to the devices on its private network with no issue.
Dynamic NAT
Dynamic NAT is used when you have a pool of public IP addresses that you want to dynamically assign to the devices on your private network.
This is not used for web server access from outside the network. Instead, when a device on the private network wants to access the internet or another resource not on the private network, it is assigned one of the public IP addresses in the pool.
NAT Overload (PAT)
With elements of both static and dynamic NAT, the NAT overload style is the most common form and is what most home routers use. It’s known as NAT with Port Address Translation (PAT) among other names.
In most cases, your router has one public IP address assigned to it, yet all the devices on your network probably want internet access. Using NAT overload the router sets up a connection between its public IP address and that of the server. It then sends the packets to the server, but also assigns a return destination port.
This helps it know which packets are meant for which IP address on your private network. That’s the PAT part of the process, incidentally.
Proprietary NAT Types
To muddle things even more, some companies have decided to slap their own NAT classifications on things. This is mostly applicable to game consoles and you’ll find that when you do a network test, it will tell you that you’re using something like NAT Type 2 or NAT Type D.
These classifications are specific to the console or device makers and you should check their official documentation to figure out what each classification actually means.
Common Fixes for NAT Issues
Most of the time, for most people, NAT works perfectly and with complete transparency. Sometimes however, it malfunctions or gets in the way.
Once again, game consoles are most likely to run into issues, because some of their services need your network to accept access requests to your public IP address from outside, since standard NAT configurations usually don’t allow this. The good news is that there are a few common fixes you can try to make NAT less restrictive and allow incoming connections.
First, access your router (according to its manual) and check if UPnP (universal plug and play) is switched on. This feature allows applications on your local network to automatically forward ports without you needing to mess around with network settings. Just be advised that any malicious software on your network, such as malware, can also make use of UPnP. Make sure your devices are all scanned and cleared if you use this function.
You also have the option of doing manual port forwarding, so that devices that need a less strict connection can get it on a case-by-case basis.
It’s Only NATural
That’s all you need to know about what NAT is to get you started. The real nuts and bolts of how NAT works can get complicated quickly, but as long as you understand what NAT does at a high level and why it sometimes goes wrong, you’ll also understand why certain fixes work or won’t when you run into network issues.