LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

如何使用脚本添加Windows防火墙规则

admin
2025年7月17日 22:42 本文热度 51

CMD

添加示例

netsh advfirewall firewall add rule name="规则名称"dir=in action=allow protocol=TCP localport=1030 

一些参数说明:

name:规则名称

dir:方向 (in入口方向 out出口方向)

action:行为(allow允许  block 阻止)

protocol:协议类型(TCP/UDP)

localport:本地端口

program:程序路径

security:安全(使用默认或者不指定即可)(authenticate|authenc|authdynenc|authnoencap|notrequired(default=notrequired))

authenticate     - 要求双向身份验证,但不加密       

authenc          - 要求双向身份验证和加密       

authdynenc       - 要求身份验证,加密可选       

authnoencap      - 要求身份验证,禁用ESP封装       

notrequired      - 不要求安全措施 

以下是一些示例:

为 messenger.exe 添加入站规则:

1 netsh advfirewall firewall add rule name="allow messenger" dir=in program="c:\programfiles\messenger\msmsgs.exe" security=authnoencap action=allow 

为端口 80 添加出站规则(禁止):

netsh advfirewall firewall add rule name="allow80" protocol=TCP dir=out localport=80 action=block 

为 TCP 端口 80 通信添加需要安全和加密的入站规则:

netsh advfirewall firewall add rule name="Require Encryption for Inbound TCP/80" protocol=TCP dir=in localport=80 security=authdynenc action=allow 

为 messenger.exe 添加需要安全的入站规则:

netsh advfirewall firewall add rule name="allow messenger"dir=in program="c:\program files\messenger\msmsgs.exe" security=authenticate action=allow 

为 SDDL 字符串标识的组 acmedomain\scanners 添加经过身份验证的防火墙跳过规则:

netsh advfirewall firewall add rule name="allow scanners"dir=in rmtcomputergrp=<SDDL string> action=bypass security=authenticate 

为 udp- 的本地端口 5000-5010 添加出站允许规则

netsh advfirewall firewall Add rule name="Allow port range"dir=out protocol=udp localport=5000-5010 action=allow

启用名为 "MyRule" 的防火墙规则:

netsh advfirewall firewall set rule name="MyRule" new enable=yes

将名为 "MyRule" 的规则的本地端口更改为 8080:

netsh advfirewall firewall set rule name="MyRule" new localport=8080

将名为 "MyRule" 的规则的远程 IP 地址限制为 192.168.1.1:

netsh advfirewall firewall set rule name="MyRule" new remoteip=192.168.1.1

将名为 "MyRule" 的规则的协议更改为 UDP:

netsh advfirewall firewall set rule name="MyRule" new protocol=UDP

运行以下命令查看规则是否已正确修改:

netsh advfirewall firewall show rule name="MyRule"

删除示例

删除本地端口 80 的所有入则:

netsh advfirewall firewall delete rule name=all protocol=tcp localport=80 

删除名为 "allow80" 的规则:

netsh advfirewall firewall delete rule name="allow80"

PowerShell

New-NetFirewallRule -DisplayName '规则名称' -Profile 'Private' -Direction Inbound -Action Allow -Protocol TCP -LocalPort 6124 

详细的使用介绍可以查看参考资料中的链接,非常详细 。 

参考资料:

https://learn.microsoft.com/zh-cn/windows/security/operating-system-security/network-security/windows-firewall/configure-with-command-line?tabs=cmd

https://learn.microsoft.com/zh-cn/troubleshoot/windows-server/networking/netsh-advfirewall-firewall-control-firewall-behavior


阅读原文:原文链接


该文章在 2025/7/18 11:02:59 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2025 ClickSun All Rights Reserved