如何从互联网访问本地网络内的服务器
假设我有一个服务器应用程序在未直接连接到互联网但通过路由器连接的计算机上工作,所以问题是如何从不在内部网络(从互联网)内的另一台计算机连接到该服务器?
据我所知,管理员可以配置路由器将指定端口请求重定向到该计算机,但我可以自动执行此操作吗?
我正在使用 WCF 和 C#
Assume I have a server application which is working in computer not connected to internet directly but with router, so the question is how to connect to that server from another computer not within internal network(from internet)?
As I know Administrator can configure router to redirect specified port requests to that computer, but can I do this automatically?
I am using WCF and C#
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
端口转发和 NAT 必须在路由器上完成,您不能从给定的本地计算机劫持该设置,这将导致圣经比例的利用。
Port Forwarding and NAT have to be done at the router, you can't hijack that setting from a given local machine, that would lead to exploits of biblical proportions.
如果路由器支持uPnP,并且服务器应用程序请求它,则路由器可以代表打开端口服务器应用程序的。
这实际上只适用于消费级路由器,因为任何理智的管理员都会在真实网络上关闭它。
编辑
这里有一些在C#中启用uPnP的代码这里 和此处。
另一种方法是在互联网上众所周知的位置拥有一台服务器。防火墙后面的应用程序创建与互联网服务器的持久连接。
然后,用户连接到互联网服务器,该服务器将数据包中继到受防火墙保护的应用程序。 teamviewer 等程序使用此方法来绕过 NAT。
If the router supports uPnP, and the server application requests it, the router can open the port on behalf of the server app.
This really only works on consumer grade routers since any sane admin will have turned this off on a real network.
edit
There is some code for enabling uPnP in C# here and here.
The alternative is to have a server at a well known location on the internet. The application behind the firewall creates a persistent connection to the internet server.
The user then connects to the internet server which relays packets to the firewalled application. Programs like teamviewer use this method to get around the NAT.
不可以。您的网络应配置为在 Internet 上托管服务器或服务。利用网络地址转换、端口地址转换或 DMZ 将是最好的方法。
No. Your network should be configured to host the Server or Service on the Internet. Making use of Network Address Translation, Port Address Translation, or a DMZ would be the best approach.
我想这就是你的答案。如果允许您连接的内部设备(即已经连接到互联网的设备)也允许您执行此类配置,则可以从外部(互联网)执行此类配置。但考虑到让一些计算机没有互联网连接的全部意义,这确实是一个奇怪的设置。
在我怀疑的头脑中,这听起来更像是想要闯入,而不是想做一些被允许做的事情。对于后者,已经给出的答案非常好。 :)
I think that's your answer right there. It may be possible to perform such configuration from the outside (internet) if something on the inside which allows you to connect to it (i.e. something already connected to the internet) also lets you perform such configuration. But considering the whole point of leaving some computers without internet connectivity that would be a strange setup indeed.
This, to my suspicious mind, sounds more like wanting to break in than wanting to do something one's allowed to. For the latter, the answers already given are pretty good. :)