路由器上端口转发
Although modern routers handle most functions automatically, some applications will require you to manually forward a port to that application or device. Fortunately, it’s really simple to do if you know where to look.
尽管现代路由器会自动处理大多数功能,但是某些应用程序将要求您手动将端口转发到该应用程序或设备。 幸运的是,如果您知道要看的地方,这真的很简单。
什么是端口转发? (What Is Port Forwarding?)
There are plenty of projects we’ve covered that use your computer as a server for other devices. When you’re inside of your network, most things will work fine. But some apps, if you want to access them when you’re outside your network, make things significantly hairier. Let’s start by taking a look at why that is.
我们涵盖了许多项目,这些项目将您的计算机用作其他设备的服务器。 当您处于网络内部时,大多数事情都会正常进行。 但是某些应用程序,如果您想在网络之外访问它们,则会使事情变得很麻烦。 让我们开始看看为什么会这样。
路由器如何处理请求和使用端口 (How Your Router Handles Requests and Uses Ports)
Here’s a map of a simple home network. The cloud icon represents the greater internet and your public, or forward-facing, Internet Protocol (IP) address. This IP address represents your entire household from the oustide world–like a street address, in a way.
这是一个简单的家庭网络的地图。 云图标代表更大的Internet和您的公共或前向Internet协议(IP)地址。 该IP地址在某种程度上代表了来自被驱逐世界的整个家庭,就像街道地址一样。
The red address 192.1.168.1 is the router address within your network. The additional addresses all belong to the computers seen at the bottom of the image. If your public IP address is like a street address, think of the internal IP addresses like apartment numbers for that street address.
红色地址192.1.168.1是您网络内的路由器地址。 所有其他地址都属于在图像底部看到的计算机。 如果您的公共IP地址像街道地址一样,请考虑内部IP地址,例如该街道地址的公寓号。
The diagram raises an interesting question which you may not have thought about before. How does all the information from the internet get to the right device inside the network? If you visit howtogeek.com on your laptop how does it end up on your laptop and not your son’s desktop if the public-facing IP address is the same for all devices?
该图提出了一个有趣的问题,您可能以前没有想到过。 来自Internet的所有信息如何到达网络内部的正确设备? 如果您在笔记本电脑上访问howtogeek.com,并且所有设备的面向公众的IP地址都相同,它将如何在笔记本电脑而不是儿子的桌面上显示?
This is thanks to a wonderful bit of routing magic known as a Network Address Translation (NAT). This function occurs at the router level where the NAT acts like a traffic cop, directing the flow of network traffic through the router so that a single public IP address can be shared among all the devices behind the router. Because of the NAT, everyone in your household can request web sites and other internet content simultaneously and it will all be delivered to the right device.
这要归功于出色的路由魔术功能,即网络地址转换(NAT)。 此功能发生在路由器级别,其中NAT充当流量警察,引导网络流量通过路由器,以便可以在路由器后面的所有设备之间共享一个公用IP地址。 由于使用了NAT,家庭中的每个人都可以同时请求网站和其他Internet内容,并且所有内容都将传递到正确的设备上。
So where do ports come into this process? Ports are an old but useful holdover from the early days of network computing. Back in the day, when computers could only run one application at a time, all you had to do was point one computer at another computer on the network to connect them as they would be running the same application. Once computers became sophisticated to run multiple applications, early computer scientists had to wrestle with the issue of ensuring applications connected to the right applications. Thus, ports were born.
那么端口在哪里进入这个过程呢? 从网络计算的早期开始,端口就是一个古老而有用的保留方式。 过去,当计算机一次只能运行一个应用程序时,您要做的就是将一台计算机指向网络上的另一台计算机以连接它们,因为它们将运行同一应用程序。 一旦计算机变得复杂到可以运行多个应用程序,早期的计算机科学家就不得不为确保应用程序连接到正确的应用程序而苦恼。 因此,港口诞生了。
Some ports have specific applications which are standards throughout the computing industry. When you fetch a web page, for example, it uses port 80. The receiving computer’s software knows that port 80 is used for serving http documents, so it listens there and responds accordingly. If you send an http request over a different port—say, 143—the web server won’t recognize it because it’s not listening there (although something else might be, like an IMAP email server which traditionally uses that port).
一些端口具有特定的应用程序,这些应用程序是整个计算机行业的标准。 例如,当您获取一个网页时,它使用端口80。接收方计算机的软件知道该端口80用于提供http文档,因此它在此处进行监听并做出相应的响应。 如果您通过其他端口(例如143)发送http请求,则Web服务器将无法识别该请求,因为它不在那儿监听(尽管可能还有其他情况,例如传统上使用该端口的IMAP电子邮件服务器)。
Other ports don’t have pre-assigned uses, and you can use them for whatever you want. To avoid interfering with other standard-abiding applications, it’s best to use larger numbers for these alternate configurations. Plex Media Server uses