01
2024
02
09:44:47

使用cmd命令设置windows防火墙策略



推荐点击下面图片,通过本站淘宝优惠价购买:

image.png

使用cmd命令设置windows防火墙策略

 

1、增加策略:

入站:netsh advfirewall firewall add rule name=1433 dir=in action =allow protocol=tcp localport=1433 remoteip=10.110.6.58,10.110.6.59,10.110.6.214,10.110.6.193,10.110.6.195,10.110.9.84,10.110.9.146

出站:netsh advfirewall firewall add rule name=8530 dir=out action =allow protocol=tcp remoteport=8530 remoteip=10.100.1.103

2、修改策略

netsh advfirewall firewall set rule name=1433 new remoteip=10.110.6.58,10.110.6.59,10.110.6.214,10.110.6.193,10.110.6.195,10.110.9.84,10.110.9.146,10.110.6.222

3、删除策略:
netsh advfirewall firewall delete rule name=1433

 

以下为转发内容,留作参考。

1、添加防火墙策略

添加策略采用netsh advfirewall firewall add 来添加策略 


用法: add rule name=<string>

      dir=in|out

      action=allow|block|bypass

      [program=<program path>]

      [service=<service short name>|any]

      [description=<string>]

      [enable=yes|no (default=yes)]

      [profile=public|private|domain|any[,...]]

      [localip=any|<IPv4 address>|<IPv6 address>|<subnet>|<range>|<list>]

      [remoteip=any|localsubnet|dns|dhcp|wins|defaultgateway|

         <IPv4 address>|<IPv6 address>|<subnet>|<range>|<list>]

      [localport=0-65535|<port range>[,...]|RPC|RPC-EPMap|IPHTTPS|any (default=any)]

      [remoteport=0-65535|<port range>[,...]|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=<SDDL string>]

      [rmtusrgrp=<SDDL string>]

      [edge=yes|deferapp|deferuser|no (default=no)]

      [security=authenticate|authenc|authdynenc|authnoencap|notrequired

         (default=notrequired)]

 

备注:

      - 将新的入站或出站规则添加到防火墙策略。

      - 规则名称应该是唯一的,且不能为 "all"。

      - 如果已指定远程计算机或用户组,则 security 必须为

        authenticate、authenc、authdynenc 或 authnoencap。

      - 为 authdynenc 设置安全性可允许系统动态协商为匹配

        给定 Windows 防火墙规则的通信使用加密。

        根据现有连接安全规则属性协商加密。

        选择此选项后,只要入站 IPSec 连接已设置安全保护,

        但未使用 IPSec 进行加密,计算机就能够接收该入站连接的第一个 TCP 或

        UDP 包。

        一旦处理了第一个数据包,服务器将重新协商连接并对其进行升级,以便所

        有后续通信都完全加密。

      - 如果 action=bypass,则 dir=in 时必须指定远程计算机组。

      - 如果 service=any,则规则仅应用到服务。

      - ICMP 类型或代码可以为 "any"。

      - Edge 只能为入站规则指定。

      - AuthEnc 和 authnoencap 不能同时使用。

      - Authdynenc 仅当 dir=in 时有效。

      - 设置 authnoencap 后,security=authenticate 选项就变成可选参数。

 

示例:

      为不具有封装的 messenger.exe 添加入站规则:

      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 remoteip="192.168.1.1-192.168.1.30,192.168.2.41,192.168.3.0/24"

添加成功后提示 “确定”

 

2、修改windows防火墙策略

修改策略采用set rule 格式来修改已经存在的策略。

 

用法: set rule

      group=

      [dir=in|out]

      [profile=public|private|domain|any[,...]]

      [program=

      [service=service short name|any]

      [localip=any|

      [remoteip=any|localsubnet|dns|dhcp|wins|defaultgateway|        

      [localport=0-65535|

      [remoteport=0-65535|

      [protocol=0-255|icmpv4|icmpv6|icmpv4:type,code|icmpv6:type,code|

         tcp|udp|any]

      new

      [name=

      [dir=in|out]

      [program=

      [service=

      [action=allow|block|bypass]

      [description=

      [enable=yes|no]

      [profile=public|private|domain|any[,...]]

      [localip=any|

      [remoteip=any|localsubnet|dns|dhcp|wins|defaultgateway|        

      [localport=0-65535|RPC|RPC-EPMap|any[,...]]

      [remoteport=0-65535|any[,...]]

      [protocol=0-255|icmpv4|icmpv6|icmpv4:type,code|icmpv6:type,code|

         tcp|udp|any]

      [interfacetype=wireless|lan|ras|any]

      [rmtcomputergrp=

      [rmtusrgrp=

      [edge=yes|deferapp|deferuser|no (default=no)]

      [security=authenticate|authenc|authdynenc|notrequired] 

备注:

      - 为已识别的规则设置新的参数值。如果规则不存在,

        则该命令失败。若要创建规则,请使用添加命令。

      - 会更新规则中 new 关键字后的值。如果

        没有值,或缺少关键字 new,则没有任何更改。

      - 一组规则只能被启用或禁用。

      - 如果多个规则与条件匹配,则会

        更新所有匹配规则。

      - 规则名称应该是唯一的,并且不能是 "all"。

      - 如果指定远程计算机或用户组,security 必须

        为 authenticate、authenc 或 authdynenc。

      - 为 authdynenc 设置安全性可允许系统动态协商为匹配

        给定 Windows 防火墙规则的通信使用加密。

        根据现有连接安全规则属性协商加密。

        选择此选项后,只要入站 IPSec 连接已设置安全保护,

        但未使用 IPSec 进行加密,计算机就能够接收该入站连接的第一个 TCP

        或 UDP 包。

        一旦处理了第一个数据包,服务器将重新协商连接并对其进行升级,以便

        所有后续通信都完全加密。

      - Authdynenc 仅当 dir=in 时有效。

      - 如果 action=bypass,则当 dir=in 时必须指定远程计算机组。

      - 如果 service=any,则规则只适用于服务。

      - ICMP 类型或代码可以是 "any"。

      - 只能为入站规则指定边缘。

 

示例:

 

      根据名称为 "allow80" 的规则更改远程 IP 地址:

      netsh advfirewall firewall set rule name="allow80"  new  remoteip=192.168.0.2

 

      启用带有分组字符串 "Remote Desktop" 的组:

      netsh advfirewall firewall set rule group="remote desktop" new  enable=yes

      为 udp- 更改规则 "Allow port range" 上的本地端口

      Set rule name="Allow port range" dir=out protocol=udp localport=5000-5020 action=allow


本文链接:https://hqyman.cn/post/4976.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:





休息一下,本站随机推荐观看栏目:


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

您的IP地址是: