تنظیمات فایروال ویندوز با دستور netsh

1- بررسی وضعیت فایروال ویندوز
netsh advfirewall show allprofiles
2- خاموش و روشن کردن فایروال ویندوز توسط دستور netsh
netsh advfirewall set all state off netsh advfirewall set all state on
خط اول تمام پروفایل های فایروال را خاموش می کند و در خط دوم تمام پروفایل ها روشن می شود.
اگر می خواهید یک پروفایل خاص را خاموش یا روشن کنید از دستور زیر استفاده کنید.
netsh advfirewall set privateprofile state off netsh advfirewall set privateprofile state on
3- باز کردن و بلاک پورت با دستور netsh
ساختار کلی
netsh advfirewall firewall add rule name="Rule name" protocol=[TCP or UDP or ...] dir=[Outbound or Inbound] remoteport=[port number] action=[Allow or Block]
مثال
netsh advfirewall firewall add rule name="Block8080" protocol=TCP dir=out remoteport=8080 action=block netsh advfirewall firewall add rule name="Allow8081" protocol=TCP dir=out remoteport=8081 action=Allow
در خط اول پورت 8080 بلاک شده و در خط دوم پورت 8081 باز برای خروجی ( Outbound ) باز شده است.
4- بلاک کردن دسترسی به یک IP خاص
ساختار
netsh advfirewall firewall add rule name="Rule name" dir=[inbound or outbound] interface=[interface name] action=[allow or block] remoteip=[IP]
مثال
netsh advfirewall firewall add rule name="IP Block" dir=in interface=any action=block remoteip=5.5.5.5
5- بلاک کردن دسترسی یک برنامه از اینترنت
ساختار
netsh advfirewall firewall add rule name="Rule Name" dir=[inbound or outbound] action=[allow or block] program="Program address" enable=[yes or no]
مثال
netsh advfirewall firewall add rule name="photoshop block" dir=out action=block program="C:\Program Files\Adobe\Adobe Photoshop CC 2015\photoshop.exe" enable=yes
6- باز کردن و بلاک یک سرویس در فایروال
ساختار کلی
netsh advfirewall firewall set rule group="profile Name" new enable=[yes or no]
مثال
netsh advfirewall firewall set rule group="remote desktop" new enable=yes netsh advfirewall firewall set rule group="remote desktop" new enable=no
در خط اول سرویس Remote Desktop باز شده و در خط دوم بلاک شده است.
7-حذف کردن رول با دستور netsh
ساختار
netsh advfirewall firewall delete rule name="Rule Name"
مثال
netsh advfirewall firewall delete rule name="IP Block"
8- ریست کردن تنظیمات فایروال به حالت پیشفرض
netsh advfirewall reset