netsh advfirewall firewall

netsh是一个脚本命令,可以修改或显示计算机当前的网络配置,可以在cmd中使用netsh进入netsh界面,使用help命令能查看到所有的配置命令,最主要的是提供脚本功能对使用的计算机直接允许命令

netsh advfirewall 可以用于控制防火墙的安全上下文,使用命令的方式去创建防火墙规则

  1. 防火墙策略使用

                        #策略的导出和导入
导入:netsh advfirewall import "位置"
  netsh advfirewall import "c:\newpolicy.pol"
导出:netsh advfirewall export "位置"
  netsh advfirewall export "c:\advfirewallpolicy.pol"
  
                        #防火墙恢复默认设置
恢复:netsh advfirewall reset 
                        #防火墙关闭和开启
关闭:netsh advfirewall set allprofiles state off
启用:netsh advfirewall set allprofiles state on
  1. firewall的使用

netsh advfirewall firewall ?
add            - 添加新入站或出站防火墙规则。
delete         - 删除所有匹配的防火墙规则。
dump           - 显示一个配置脚本。
help           - 显示命令列表。
set            - 为现有规则的属性设置新值。
show           - 显示指定的防火墙规则
删除策略:netsh advfirewall firewall add rule 
add rule name=<string>                                
//添加规则名称=<string>

dir=in|out                                            
//dir=输入|输出

action=allow|block|bypass                            
//action=允许|阻止|旁路

[program=<program path>]                             
//[程序=<程序路径>]

[service=<service short name>|any]                    
//[service=<service short name>|any]

[description=<string>]                                 
//[描述=<string>]

[enable=yes|no (default=yes)]                          
 //[启用=是|否(默认=是)]

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

[localip=any|<IPv4 address>|<IPv6 address>|<subnet>|<range>|<list>]  
//[localip=任何|<IPv4地址>|<IPv6地址>|<子网>|<范围>|<列表>]

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

<IPv4 address>|<IPv6 address>|<subnet>|<range>|<list>]                  
//<IPv4地址>|<IPv6地址>|<子网>|<范围>|<列表>]

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

[remoteport=0-65535|<port range>[,...]|any (default=any)]                       //[remoteport=0-65535|<port range>[,…]|any(默认值=any)]

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

tcp|udp|any (default=any)]                                    
//[tcp|udp|any(默认值=any)]

[interfacetype=wireless|lan|ras|any]
//[接口类型=无线|lan|ras|any]

[rmtcomputergrp=<SDDL string>]                                
//[rmtcomputergrp=<SDDL字符串>]

[rmtusrgrp=<SDDL string>]                                       
//[rmtusrgrp=<SDDL字符串>]

[edge=yes|deferapp|deferuser|no (default=no)]                    
//[edge=yes|delefapp|delefuser|no(默认值=no)]

[security=authenticate|authenc|authdynenc|authnoencap|notrequired            //[security=authenticate|authentication|authdynenc|authnoencap|不需要

(default=notrequired)]                                                    
//(默认=不需要)]
                            #添加入站规则放行3389端口
netsh advfirewall firewall add rule name=3389port dir=in action=allow protocol=TCP localport=3389
                            #删除指定策略
netsh advfirewall firewall delete rule name=3389port protocol=TCP localport=3389
                            #禁止ICMP回显
netsh advfirewall firewall add rule name="icmp ban" protocol=icmpv4:8,any dir=in action=block
 type - ICMP 类型。
      2   - 允许出站数据包太大。
      3   - 允许出站目标不可访问。
      4   - 允许出站源抑制。
      5   - 允许重定向。
      8   - 允许入站回显请求。
      9   - 允许入站路由器请求。
      11  - 允许出站超时。
      12  - 允许出站参数错误。
      13  - 允许入站时间戳请求。
      17  - 允许入站掩码请求。
      ALL - 所有类型。
                            #显示所有动态入站规则
netsh advfirewall firewall show rule nam=all dir=in type=dynamic
                            # 显示名为 "ICMP ban" 的所有入站规则的
netsh advfirewall firewall show rule name="ICMP ban" verbose
案例:https://blog.csdn.net/qq_21453783/article/details/123679380

微软官方文档:https://learn.microsoft.com/zh-cn/windows-server/networking/technologies/netsh/netsh-contexts

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

https://blog.csdn.net/qq_21453783/article/details/123679380

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值