在 %systemroot%\system32\drivers\etc\hosts 文件中包含端口号
是否可以在主机文件中包含端口号?我问这个问题的原因是因为我尝试将一些站点从一台托管服务器迁移到另一台托管服务器,并且这些站点指向使用标准 TCP/IP 端口 (1433) 的旧 SQL 服务器。在新服务器上,SQL Server 端口不同,我不想更改这些站点的连接字符串。
谢谢你!
Is it possible to include port numbers in hosts file? Reason that I'm asking is because I have sites that I'm trying to migrate from one hosting server to another, and the sites are pointing to an old SQL server that uses the standard TCP/IP port (1433). On the new server, the SQL Server port is different, and I don't want to change the connection strings for these sites.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这在主机文件中是不可能的。 DNS 不知道有关端口号的任何信息。
This is not possible in the host file. DNS doesn't know anything about port numbers.
您可以在 SQL 配置管理工具中配置别名。旨在准确地涵盖这种情况。
You can configure an alias in the SQL Configuration Management tool. Is designed to cover exactly this scenario.
主机文件将主机名转换为 IP 地址(反之亦然)。您不能包含端口号。
The hosts file translates host names to IP addresses (and vice-versa). You can't include port numbers.
您可以设置路由器在新站点进行端口转发,并且如果尚未通过路由器进行路由,则将路由器的地址作为新主机。
You could set up a router to do port forwarding at the new site, and—if not already routed through the router, then give the router's address as the new host.
如果这对任何人有帮助,我在主机文件中定义如下:
MyServer 在特定端口上工作。
当 SQL Server 2005 Management Studio 在创建连接时询问“服务器名称”时,我输入“Myserver,1234”,其中 1234 是端口号。
因为它会在下次下拉菜单中记住它们,所以这对我来说已经足够了。
If this helps anyone I definded mine as follows, in the hosts file:
The MyServer works on a specific port.
The when SQL Server 2005 management studio asks for 'server name' when creating a connection, I entered 'Myserver,1234' where 1234 was the port number.
Since it remembers them in a drop down for next time, this was good enough for me.