附录一 6. 使用命令行工具

附录一 6. 使用命令行工具


  在 Windows 的 Server Core 模式,由于没有图形界面,必须通过命令行配置 Windows 防火墙。


6.1 启用一个程序

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="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


6.2 启用端口

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



6.3 删除启用的程序或端口

netsh advfirewall firewall delete rule name=规则名称 program="C:\MyApp\MyApp.exe"

netsh advfirewall firewall delete rule name=规则名称 protocol=udp localport=500


6.4 配置 ICMP

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



6.5 日志记录设置

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



6.6 启用、重置防火墙

netsh advfirewall set currentprofile state on

netsh advfirewall reset


6.7 启用其他服务

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



本文出自 “SQL Server 管理员指南” 博客,谢绝转载!

你可能感兴趣的:(防火墙)