Translate

Showing posts with label Windows Firewall. Show all posts
Showing posts with label Windows Firewall. Show all posts

Thursday, November 22, 2018

Network connection from public to private with Powershell

Sometimes the Windows 10 network connection will be classified automatically as public or private and it is not in the way as it should be. As this will affect firewall rules you sometimes get by a domain group policy. The effect is that your software cant communicate anymore when this was done wrong.

How to fix this?

Very simple with PowerShell!

1. Open an Admin PowerShell Command Prompt.
2. Type in: Get-NetConnectionProfile
3. Check the name from your network connection. Keep in mind when you have Security features like credential guard and/or HyperV enabled you will see more "Unidentified networks". You can safely ignore them. Here in my example the network is called "CAP".
4. Type in: Set-NetConnectionProfile -Name "CAP" -NetworkCategory Private

Your setting will be active immediately!





Monday, May 2, 2016

DONT DO THIS AT HOME! - Just for testing disable the local firewall with Powershell on new Windows Servers

I found while working with the advanced firewall under current Windows Server 2012R2 and newer that since an update (cant tell you which one) disabling the firewall may result in total loss of communication.




Which is in general a very good security practice.


For production machines it is always absolutelly recommended to have a fully operational firewall.




BUT under some circumstances it might be good to know if a newly introduced service is working in general to find out if a blocked port is causing issues or if it is the service itself.




In the past it was easy:
Simply shutdown the firewall on all profiles and you could test if it works or not.


But now its more complex. (PowerShell helps a lot here!)


Just to rembember:


1. Dont do this at home! (unskilled admins should stay away!)
2. Make sure you only do it in a save testing environment which is externally protected by a firewall. (Ok in these days firewalls are only a basic protection anymore!)
3. If you checked that your testing environment works well turn on the firewall again and add all needed firewall ports from your services documentation to make sure it works the way it was designed for!!!


Here how it works:


Open the PowerShell as admin and let run these 4 lines:


New-NetFirewallRule -DisplayName "Allow TCP Outbound - TESTING ONLY RE-ENABLE IT AFTER YOUR TESTS!" -Direction Outbound –LocalPort Any -Protocol TCP -Action Allow

New-NetFirewallRule -DisplayName "Allow UDP Outbound - TESTING ONLY RE-ENABLE IT AFTER YOUR TESTS!" -Direction Outbound –LocalPort Any -Protocol UDP -Action Allow


New-NetFirewallRule -DisplayName "Allow TCP Inbound - TESTING ONLY RE-ENABLE IT AFTER YOUR TESTS!" -Direction Inbound –LocalPort Any -Protocol TCP -Action Allow


New-NetFirewallRule -DisplayName "Allow UDP Inbound - TESTING ONLY RE-ENABLE IT AFTER YOUR TESTS!" -Direction Inbound –LocalPort Any -Protocol UDP -Action Allow









But last but not least you also need to Re-Enable the firewall function after your testing!


This is done with these steps:


Remove-NetFirewallRule -DisplayName "Allow TCP Outbound - TESTING ONLY RE-ENABLE IT AFTER YOUR TESTS!"

Remove-NetFirewallRule -DisplayName "Allow UDP Outbound - TESTING ONLY RE-ENABLE IT AFTER YOUR TESTS!"


Remove-NetFirewallRule -DisplayName "Allow TCP Inbound - TESTING ONLY RE-ENABLE IT AFTER YOUR TESTS!"


Remove-NetFirewallRule -DisplayName "Allow UDP Inbound - TESTING ONLY RE-ENABLE IT AFTER YOUR TESTS!"