天天看点

netsh advfirewall

微软详细解释:

http://technet.microsoft.com/zh-cn/library/dd734783.aspx

Windows 防火墙: 保护所有网络连接       已启用

Windows 防火墙: 不允许例外    已禁用

Windows 防火墙: 定义程序例外       已启用

Windows 防火墙: 允许本地程序例外       已禁用

Windows 防火墙: 允许远程管理例外       已禁用

Windows 防火墙: 允许文件和打印机共享例外       已禁用

Windows 防火墙: 允许 ICMP 例外  已启用

Windows 防火墙: 允许远程桌面例外       已启用

Windows 防火墙: 允许 UPnP 框架例外   已禁用

Windows 防火墙: 阻止通知       已禁用

Windows 防火墙: 允许记录日志       已启用

Windows 防火墙: 阻止对多播或广播请求的单播响应    已启用

Windows 防火墙: 定义端口例外       已启用

Windows 防火墙: 允许本地端口例外       已禁用

对比:

netsh advfirewall firewall add rule name="My Application" dir=in action=allow program="C:\MyApp\MyApp.exe" enable=yes remoteip=157.60.0.1,172.16.0.0/16,LocalSubnet profile=domain

netsh advfirewall firewall add rule name="My Application" dir=in action=allow program="C:\MyApp\MyApp.exe" enable=yes remoteip=157.60.0.1,172.16.0.0/16,LocalSubnet profile=private

netsh advfirewall firewall add rule name="My Application" dir=in action=allow program="C:\MyApp\MyApp.exe" enable=yes

netsh advfirewall firewall add rule name="Open Port 80" dir=in action=allow protocol=TCP localport=80

netsh advfirewall firewall delete rule name=rule nameprogram="C:\MyApp\MyApp.exe

netsh advfirewall firewall delete rule name=rule nameprotocol=udp localport=500

netsh advfirewall firewall add rule name="ICMP Allow incoming V4 echo request" protocol=icmpv4:8,any dir=in action=allow

netsh advfirewall firewall add rule name="All ICMP V4" protocol=icmpv4:any,any dir=in action=allow

netsh advfirewall firewall add rule name="Block Type 13 ICMP V4" protocol=icmpv4:13,any dir=in action=block

netsh advfirewall set currentprofile logging filename %systemroot%\system32\LogFiles\Firewall\pfirewall.log

netsh advfirewall set currentprofile logging maxfilesize 4096

netsh advfirewall set currentprofile logging droppedconnections enable

netsh advfirewall set currentprofile logging allowedconnections enable

netsh advfirewall set currentprofile state on

netsh advfirewall set currentprofile firewallpolicy blockinboundalways,allowoutbound

Domainprofile

Privateprofile

Publicprofile

netsh advfirewall reset

netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes

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

netsh advfirewall firewall set rule group="remote desktop" new enable=Yes profile=domain 

netsh advfirewall firewall set rule group="remote desktop" new enable=Yes profile=private 

// ===============================================================

恢复到默认设置

    Netsh advfirewall reset

导出防火墙配置

    netsh advfirewall export “c:\advfirewall.wfw”

导入防火墙配置

    Netsh advfirewall import “c:\advfirewall.wfw”

增加一个针对messenger.exe的入站规则

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

删除针对本地21端口的所有入站规则:

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

让防火墙关闭所有配置文件:

    netsh advfirewall set allprofiles state off

在所有配置文件中设置默认阻挡入站并允许出站通信:

    netsh advfirewall set allprofiles firewallpolicy blockinbound,allowoutbound

 在所有配置文件中打开远程管理:

    netsh advfirewall set allprofiles settings remotemanagement enable

在所有配置文件中记录被断开的连接:

    netsh advfirewall set allprofiles logging droppedconnections enable

(1)启用桌面防火墙

netsh advfirewall set allprofiles state on

(2)设置默认输入和输出策略

netsh advfirewall set allprofiles firewallpolicy allowinbound,allowoutbound

以上是设置为允许,如果设置为拒绝使用blockinbound,blockoutbound

(3)关闭tcp协议的139端口

netsh advfirewall firewall add rule name="deny tcp 139" dir=in protocol=tcp localport=139 action=block

(4)关闭udp协议的139端口

netsh advfirewall firewall add rule name="deny udp 139" dir=in protocol=udp localport=139 action=block

(5)关闭tcp协议的445端口

netsh advfirewall firewall add rule name="deny tcp 445" dir=in protocol=tcp localport=445 action=block

(6)关闭udp协议的445端口

netsh advfirewall firewall add rule name="deny udp 445" dir=in protocol=udp localport=445 action=block

(7)使用相同的方法,依次关闭TCP协议的21、22、23、137、138、3389、5800、5900端口。

netsh advfirewall firewall add rule name= "deny tcp 21" dir=in protocol=tcp localport=21 action=block

netsh advfirewall firewall add rule name= "deny tcp 22" dir=in protocol=tcp localport=22 action=block

netsh advfirewall firewall add rule name= "deny tcp 23" dir=in protocol=tcp localport=23 action=block

netsh advfirewall firewall add rule name= "deny tcp 5800" dir=in protocol=tcp localport=5800 action=block

netsh advfirewall firewall add rule name= "deny tcp 5900" dir=in protocol=tcp localport=5900 action=block

netsh advfirewall firewall add rule name= "deny tcp 137" dir=in protocol=tcp localport=137 action=block

netsh advfirewall firewall add rule name= "deny tcp 138" dir=in protocol=tcp localport=138 action=block

(8)执行完毕后暂停

pause

echo 按任意键退出

恢复初始配置

(1)恢复初始防火墙设置

(2)关闭防火墙

netsh advfirewall set allprofiles state off

补充:

1. 优先性

GPEDIT.MSC中的策略作用大于FIREWALL高级设置中的设置,比如:

windows 防火墙:允许入站远程桌面例外中 不圈定访问ip,那么在firewall的高级设置中,即便限制了3389端口的IP范围也没用.

2.封对外访问

netsh advfirewall firewall add rule name ="PhaseACL" dir=out remoteip=3.3.3.3 action=block

     本文转自hbyh 51CTO博客,原文链接:http://blog.51cto.com/norman20000/1437734,如需转载请自行联系原作者

上一篇: BIP

继续阅读