更改 URI 端口号有什么作用?
我不太明白不同端口之间的差异。我在网上找不到任何有用的资源来详细介绍它。据我所知,它充当某种过滤器,阻止任何其他不使用相同端口号的请求。
在浏览器中输入网站时,何时需要更改端口号(如果需要)?如果我运行自己的网站怎么办?使用 80 端口时是否存在任何风险?例如,有没有办法使用不同的端口号来侵入网站?
由于简单邮件传输协议使用端口 25,我可以利用这些知识使用自己编写的程序发送电子邮件吗?
I don't really understand the differences between the different ports. I couldn't find any useful resources online that would go into detail about it. From what I can understand, it acts as some kind of filter that blocks out any other request not using the same port number.
When will I, if ever, need to change the port number when typing in a website in my browser? What about if I am running my own website? Are there any risks I take when using port 80? As in, are there ways to use different port numbers to hack into a website?
And since a Simple Mail Transfer Protocol uses port 25, could I use this knowledge to send emails using self written programs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据约定和标准,定义的协议通常默认侦听定义的端口。您可以将任何服务设置为侦听您想要的任何端口,只需注意,从标准端口进行更改意味着需要明确告知标准工具使用您的非标准端口。
例如,如果您运行一个 Web 服务器,那么默认情况下它可能正在侦听端口 80。因此,访问您的服务器所需要做的就是使用该地址:
但是,如果您将其更改为侦听非标准端口,例如例如 81,那么任何想要访问您网站的用户都需要指定端口号:
仅使用该地址的标准约定是不够的,因为您已经打破了约定。现在,如果您不希望人们随机使用您的网站,并且只希望您已告知端口号的人可以使用该网站,那么这很好。这称为“通过默默无闻实现安全”。它实际上并不以任何方式保护您的网站或过滤掉任何内容,它只是为网站的使用添加了一个额外的步骤。
至于 SMTP,是的,您可以编写程序连接到 SMTP 服务上的端口 25 并向这些服务发送数据。您确实可以通过这种方式欺骗电子邮件。然而,大多数服务都有其他内置的检查和平衡来防止此类欺骗。
By conventions and standards, defined protocols generally listen on defined ports by default. You can set any service to listen on any port you want, just be aware that changing from a standard port means that standard tools would need to be explicitly told to use your non-standard port.
For example, if you run a web server then by default it's probably listening on port 80. So all someone needs to do to visit your server is use the address:
However, if you change it to listen on a non-standard port, such as 81, then any user who wants to visit your site will need to specify the port number:
The standard convention of just using the address wouldn't be sufficient, because you've broken convention. Now, this is fine if you don't want people randomly using your site and only want it to be available to people to whom you've told the port number. This is called "security through obscurity." It doesn't actually secure your site in any way or filter out anything, it just adds an additional step to the use of the site.
As for SMTP, yes, you can write programs to connect to port 25 on SMTP services and send data to those services. You may indeed be able to spoof emails in this manner. However, most services have other built-in checks and balances to prevent such spoofing.
TCP/IP 支持机器上的 2^16 个端口。据说服务器程序侦听特定端口;其他机器使用端口号和机器名称联系机器上的服务器程序。就像信上的地址一样。
有些端口号是“众所周知的”,这仅意味着它们被正式分配给特定服务:端口 80 用于 Web 服务器,端口 25 用于 SMTP,端口 25 用于
telnet
等。服务器可以在任何端口上运行;只需更改代码或配置即可。有时您可能会在一台机器上运行两个独立的 Web 服务器;一个可能会监听端口 80,第二个可能会监听其他端口(8080 是开发过程中使用的服务器的常见选择。)
因此客户端无法有意义地将端口更改为某个随机数:必须有某些东西正在监听那个端口,在那台机器上,或者它不做任何事情。
TCP/IP supports 2^16 ports on a machine. A server program is said to listen on a specific port; other machines contact a server program at a machine using the port number and the name of the machine. It's like the address on a letter.
Some port numbers are "well known", which just means they're officially assigned for a particular service: port 80 is for web servers, port 25 for SMTP, port 25 for
telnet
, etc.But any server can run on any port; it's just a matter of changing the code or the configuration. Sometimes you may way to run two separate web servers on one machine; one might listen on port 80, and the second one on some other port (8080 is a common choice for servers used during development.)
So the client can't meaningfully change the port to some random number: there has to be something listening on that port, on that machine, or it doesn't do anything.
从纯粹的技术角度来看,在任何端口号上运行 Web 服务器之间没有“区别”,只要客户端和服务器都知道要使用哪个端口即可。当客户端连接到服务器时,它必须知道IP地址和端口。
按照惯例,标准服务会使用多个端口。例如,端口 25 是 SMTP、端口 80 是 http 端口、22 是 ssh 端口等。由于这些约定,小于 1024 的端口被操作系统保留,只能由 root 进程打开。
除非有特定原因,否则通常最好坚持使用标准端口号。高级端口扫描器/分析工具将尝试系统上的所有端口,因此在非标准端口上运行服务没有太大好处。
There is no 'difference' between running a web server on any port number, from a purely technical perspective, as long as the client and the server both know which port to use. When the client connects to the server, it has to know the IP address as well as the port.
By convention, several ports are used by standard services. For example, port 25 is SMTP, port 80 is the http port, 22 is the ssh port, etc. Because of these conventions, ports less than 1024 are reserved by the operating systems and can only be opened by a root process.
Unless there is a specfiic reason, it is generally a good idea to stick with the standard port numbers. Advanced port scanners/ analysis tools will try all ports on a system, so there isn't much benefit to running a service on a non-standard port.
端口号是通过 IP 链路复用通信的一种方式。这通常用于在接受的端口号上提供特定服务。 HTTP 服务器已分配端口 80 用于侦听传入的客户端连接,尽管这不是锁 - 没有什么可以阻止您构建/配置侦听端口 9001 或其他端口的 HTTP 服务器。如果您确实为服务器使用了非标准端口号,那么您必须专门指示浏览器连接到该端口,而不是像通常那样默认为 80。
使用您自己的程序在端口 25 中进行 SMTP - 当然,您可以做到这一点。任何邮件应用程序都是一些开发人员的“自己的程序”。
平均值,
马丁
The port numbers are a way of multiplexing communications over IP links. This is commonly used to provide specific services on accepted port numbers. HTTP servers have been allocated port 80 for listening for incoming client connections, though this is not a lock - there is nothing stopping you constructing/configuring an HTTP server that listens on port 9001, or whatever. If you did use a non-standard port number for your server, then you would have to specifically instruct a browser to connect to that port, rather than defaulting to 80 as it normally does.
SMTP in port 25 using your own program - sure, you can do this. Any mail app is some developers' 'own program' .
Rgds,
Martin