Windows Firewall
2024-03-05 20:28:17

Enable/Disable Firewall

1
netsh advfirewall set currentprofile state <on/off>

Netsh Usage

The netsh advfirewall firewall command-line context is available in Windows Server 2012 R2 & after. netsh firewall may be deprecated in future versions. It is advised to use netsh advfirewall firewall.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Enable a program
netsh firewall add allowedprogram C:\rev.exe "name" ENABLE
netsh advfirewall firewall add rule name="name" dir=in action=allow program="C:\rev.exe" enable=Yes

# Enable a port
netsh firewall add portopening TCP 80 "Open Port 80"
netsh advfirewall firewall add rule name= "Open Port 80" dir=in action=allow protocol=TCP localport=80

# Deleting rules
netsh firewall delete allowedprogram C:\MyApp\MyApp.exe
netsh advfirewall firewall delete rule name= rule name program="C:\MyApp\MyApp.exe"

netsh firewall delete portopening protocol=UDP port=500
netsh advfirewall firewall delete rule name= rule name protocol=udp localport=500

Common Firewall Groups

Remote Admin Stuff

Enables firewall rules for RDP and ports remote admin ports like 135 and 445.

1
2
3
4
netsh firewall set service RemoteDesktop enable
netsh firewall set service RemoteDesktop enable profile=ALL
netsh advfirewall firewall set rule group="remote desktop" new enable=Yes
netsh advfirewall firewall set rule group="remote administration" new enable=Yes

File Sharing

Enables file sharing - opens ports 135, 139, 445

1
2
netsh firewall set service FileAndPrint
netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes
2024-03-05 20:28:17