简体   繁体   English

如何禁止访问本地主机(internal.network 和 inte.net)

[英]How to Disable access to localhost (internal network and internet)

I want to block a program from accessing the local server "local host" (On windows) temporary so i can test random disconnections cases... I tried adding a (rule) to the firewall for disabling both inbound and outbound in all.networks types but the program just got block from accessing the inte.net not the local.network我想暂时阻止程序访问本地服务器“本地主机”(在 Windows 上),这样我就可以测试随机断开连接的情况...我尝试向防火墙添加一个(规则)以禁用 all.networks 中的入站和出站类型,但程序刚刚被阻止访问 inte.net 而不是 local.network

Moving on to an answer instead of a comment - nevertheless, more information on your use-case is greatly appreciated;继续回答而不是评论 - 尽管如此,非常感谢有关您的用例的更多信息;

I think it is impossible to block access to localhost but allow inte.net access.我认为不可能阻止对 localhost 的访问但允许 inte.net 访问。 Two reasons:两个原因:

  • Networking works on different layers ("OSI layers") and localhost communication is looped back before firewall might filter (see ).网络在不同的层(“OSI 层”)上工作,本地主机通信在防火墙可能过滤之前环回(参见 参考资料)。 Not so sure on this though.虽然不太确定。
  • localhost communication might be "basic" in a way that it is necessary for applications when they want to communicate via.network.本地主机通信可能是“基本的”方式,当应用程序想要通过.network 进行通信时,这是必需的。

UPDATE after OPs comment OP评论后更新

I assume you are on Windows 10, and you know the path to the executable of the program you want to block.我假设您使用的是 Windows 10,并且您知道要阻止的程序的可执行文件的路径。

  • Open "Windows Defender Firewall with Advanced Security".打开“具有高级安全性的 Windows Defender 防火墙”。
  • On the left side, go to "Outbound Rules".在左侧,go 到“出站规则”。
  • Then, on the right side click on "New Rule...".然后,在右侧单击“新规则...”。
  • A new window will open;一个新的window将开通; Leave "Program" selected and click "Next".选择“程序”并单击“下一步”。
  • Next to "This program path:" is a Button "Browse..." - select your program here. “此程序路径:”旁边是一个“浏览...”按钮 - select 您的程序在这里。 Click "Next..."点击下一步...”
  • Select "Block the connection", then "Next...". Select “阻止连接”,然后“下一步...”。
  • Select all three; Select 全部三个; Domain, Private and Public.域,私有和公共。
  • After click "Next..." choose an appropriate name, then click "Finish".单击“Next...”后选择合适的名称,然后单击“Finish”。
  • From now on, you can disable/enable this rule as you see fit.从现在开始,您可以根据需要禁用/启用此规则。

Kinda hard to provide detailed answer having only the information you've provided, but I think this scenario can be easily tested with simple containers configuration: having both program under test and "localhost" service running in containers, you can randomly update container's.network configuration to simulate connectivity issues.很难提供仅包含您提供的信息的详细答案,但我认为可以使用简单的容器配置轻松测试这种情况:在容器中同时运行被测程序和“本地主机”服务,您可以随机更新容器的.network配置来模拟连接问题。

You can use a reverse proxy like Fiddler and block all requests coming from this application to localhost.您可以使用像 Fiddler 这样的反向代理并阻止所有从该应用程序到本地主机的请求。

If I understood what you mean then this will do: To create a rule, select the Inbound Rules or Outbound Rules category at the left side of the window and click the Create Rule link on the right side.如果我理解您的意思,那么这样做:要创建规则,select window 左侧的入站规则或出站规则类别,然后单击右侧的创建规则链接。 The Windows firewall offers four types of rules: Program – Block or allow a program. Windows 防火墙提供四种类型的规则: 程序 – 阻止或允许程序。 Port – Block or allow a port, port range, or protocol.端口 – 阻止或允许端口、端口范围或协议。

if you are using a third party anti-virus solution with a built-in firewall, go to the firewall option and black list/disable/prevent inte.net access to your app如果您使用带有内置防火墙的第三方防病毒解决方案,go 到防火墙选项和黑名单/禁用/阻止 inte.net 访问您的应用程序

Otherwise, disabling your firewall will not stop any access, as it will allow inbound and outbound traffic.否则,禁用防火墙不会阻止任何访问,因为它会允许入站和出站流量。 you can prevent specific ports but disabling the firewall wall will not only do what mentioned before but it will also leave your device vulnerable for online threatts您可以阻止特定端口,但禁用防火墙墙不仅会执行前面提到的操作,还会使您的设备容易受到在线威胁

Try these 3 simple steps.试试这 3 个简单的步骤。

  1. run your program运行你的程序
  2. Open cmd ( please check you need admin access for this, if yes then run as admin)打开 cmd(请检查您是否需要管理员权限,如果需要,请以管理员身份运行)
  3. Run the following command to see at which port the localhost is listening.运行以下命令以查看本地主机正在侦听的端口。

netstat -ano |网络统计-ano | findstr:查找字符串:

eg (if your localhost is listening at port 3900 the command will be as follow;例如(如果您的本地主机正在侦听端口3900 ,则命令如下;

netstat -ano |网络统计-ano | findstr:3900查找字符串:3900

the result will be shown on cmd console, the last column is PID (Process id) We will just kill that process which will eventually stop the localhost server to listen any request from any source.结果将显示在 cmd 控制台上,最后一列是 PID(进程 ID)我们将终止该进程,最终停止本地主机服务器以侦听来自任何来源的任何请求。

taskkill /PID /F taskkill /PID /F

< PID > that you will get from above command. < PID >你将从上面的命令中得到。

in this case, only the localhost will stop it's service, but you application will keep communicating to outer.network, inte.net.在这种情况下,只有本地主机会停止它的服务,但您的应用程序将继续与 outer.network、inte.net 通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM