经常有小伙伴需要批量添加或修改防火墙策略,下面附上用命令行添加修改防火墙策略的说明,后附例子,包括详细的针对IP地址限制的策略
测试环境 windows server2012,
1、添加防火墙策略
添加策略采用netsh advfirewall firewall add来添加策略
用法: add rule name=
dir=in|out
action=allow|block|bypass
[program=]
[service=|any]
[description=]
[enable=yes|no (default=yes)]
[profile=public|private|domain|any[,...]]
[localip=any|||||]
[remoteip=any|localsubnet|dns|dhcp|wins|defaultgateway|
||||]
[localport=0-65535|[,...]|RPC|RPC-EPMap|IPHTTPS|any (default=any)]
[remoteport=0-65535|[,...]|any (default=any)]
[protocol=0-255|icmpv4|icmpv6|icmpv4:type,code|icmpv6:type,code|
tcp|udp|any (default=any)]
[interfacetype=wireless|lan|ras|any]
[rmtcomputergrp=]
[rmtusrgrp=]
[edge=yes|deferapp|deferuser|no (default=no)]
[security=authenticate|authenc|authdynenc|authnoencap|notrequired
(default=notrequired)]
备注:
- 将新的入站或出站规则添加到防火墙策略。
- 规则名称应该是唯一的,且不能为 "all"。
- 如果已指定远程计算机或用户组,则 security 必须为
authenticate、authenc、authdynenc 或 a