简体   繁体   中英

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

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. Two reasons:

  • Networking works on different layers ("OSI layers") and localhost communication is looped back before firewall might filter (see ). 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.

UPDATE after OPs comment

I assume you are on Windows 10, and you know the path to the executable of the program you want to block.

  • Open "Windows Defender Firewall with Advanced Security".
  • On the left side, go to "Outbound Rules".
  • Then, on the right side click on "New Rule...".
  • A new window will open; Leave "Program" selected and click "Next".
  • Next to "This program path:" is a Button "Browse..." - select your program here. Click "Next..."
  • Select "Block the connection", then "Next...".
  • Select all three; Domain, Private and Public.
  • After click "Next..." choose an appropriate name, then click "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.

You can use a reverse proxy like Fiddler and block all requests coming from this application to localhost.

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. The Windows firewall offers four types of rules: Program – Block or allow a program. 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

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.

  1. run your program
  2. Open cmd ( please check you need admin access for this, if yes then run as admin)
  3. Run the following command to see at which port the localhost is listening.

netstat -ano | findstr:

eg (if your localhost is listening at port 3900 the command will be as follow;

netstat -ano | findstr: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.

taskkill /PID /F

< PID > that you will get from above command.

in this case, only the localhost will stop it's service, but you application will keep communicating to outer.network, inte.net.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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