如何使用netsh advfirewall firewall而不是netsh firewall控制Windows Server 2008的防火墙行为

如何使用"netsh advfirewall firewall"上下文,而不是"netsh firewall"上下文控制Windows Vista 和 Windows Server 2008 中的防火墙行为

适用于: Windows Server 2008 EnterpriseWindows Server 2008 DatacenterWindows Server 2008 Standard 详细


重要提示:本文章是 Microsoft 软件自动翻译的结果,而非专业译者翻译的结果。 Microsoft 提供专业人员翻译的文章、由自动翻译生成的文章以及来自 Microsoft 社区的文章翻译,因此你能够以自己的语言阅读所有知识库文章。 需要注意的是,由自动翻译生成的文章(包括 Microsoft 社区审阅的文章)可能包含词汇、句法或语法错误。 对于因不正确的内容翻译或使用不正确的内容翻译而造成的不准确或错误或任何损害,Microsoft 概不负责。

查看原始英文文章:947709

简介


Windows Vista 和 Windows Server 2008 中,由防火墙的 netsh命令行上下文可用。此上下文提供了用于控制 Windows 防火墙行为,是由netsh 防火墙上下文在早期版本的 Windows 操作系统中提供的功能。这里还提供了更精确地控制的防火墙规则的功能。这些规则包括以下的每个配置文件设置:

  • 私有
  • 公共

防火墙 netsh命令行上下文可能会在未来版本的 Windows 操作系统中不建议使用。我们建议您使用netsh 由防火墙上下文以控制防火墙行为。注意:不建议在 Windows Vista 中使用 netsh 防火墙命令行。本文介绍如何使用netsh 由防火墙上下文,而不是控制 Windows Vista 和 Windows Server 2008 中的 Windows 防火墙行为的netsh 防火墙上下文。

更多信息


重要:如果您是成员的管理员组,并且您从具有提升权限的命令提示符运行命令的计算机上启用用户帐户控制。若要使用提升的权限启动命令提示符下,查找图标或开始菜单条目用来启动命令提示符会话,用鼠标右键单击它,然后单击以管理员身份运行。下表提供了常用命令的一些示例。可以使用这些示例来帮助您从较早的netsh 防火墙上下文迁移到新的netsh 由防火墙上下文。此外,提供了可用于获取详细的内联帮助由命令。

示例 1: 启用程序

旧命令新命令
netsh firewall add allowedprogram C:\MyApp\MyApp.exe "My Application" ENABLEnetsh advfirewall firewall add rule name="My Application" dir=in action=allow program="C:\MyApp\MyApp.exe" enable=yes
netsh firewall add allowedprogram program=C:\MyApp\MyApp.exe name="My Application" mode=ENABLE scope=CUSTOM addresses=157.60.0.1,172.16.0.0/16,LocalSubnet profile=Domainnetsh 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 firewall add allowedprogram program=C:\MyApp\MyApp.exe name="My Application" mode=ENABLE scope=CUSTOM addresses=157.60.0.1,172.16.0.0/16,LocalSubnet profile=ALLRun the following commands:

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 ?

示例 2: 启用端口

旧命令新命令
netsh firewall add portopening TCP 80 "Open Port 80"netsh advfirewall firewall add rule name="Open Port 80" dir=in action=allow protocol=TCP localport=80

有关如何添加防火墙规则的详细信息,运行以下命令:

netsh advfirewall firewall add rule ?

示例 3: 删除启用的程序或端口

旧命令新命令
netsh firewall delete allowedprogram C:\MyApp\MyApp.exenetsh advfirewall firewall delete rule name=rule name program="C:\MyApp\MyApp.exe"
delete portopening protocol=UDP port=500netsh advfirewall firewall delete rule name=rule name protocol=udp localport=500

有关如何删除防火墙规则,运行以下命令:

netsh advfirewall firewall delete rule ?

示例 4: 配置 ICMP 设置

旧命令新命令
netsh firewall set icmpsetting 8netsh advfirewall firewall add rule name="ICMP Allow incoming V4 echo request" protocol=icmpv4:8,any dir=in action=allow
netsh firewall set icmpsetting type=ALL mode=enablenetsh advfirewall firewall add rule name="All ICMP V4" protocol=icmpv4:any,any dir=in action=allow
netsh firewall set icmpsetting 13 disable allnetsh advfirewall firewall add rule name="Block Type 13 ICMP V4" protocol=icmpv4:13,any dir=in action=block

有关如何配置 ICMP 设置的详细信息,运行以下命令:

netsh advfirewall firewall add rule ?

示例 5: 将日志记录设置

旧命令新命令
netsh firewall set logging %systemroot%\system32\LogFiles\Firewall\pfirewall.log 4096 ENABLE ENABLERun the following commands:

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 ?

如果要将特定配置文件的日志记录设置,请使用以下选项之一,而不是"currentprofile"选项:

  • Domainprofile
  • Privateprofile
  • Publicprofile

示例 6: 启用 Windows 防火墙

旧命令新命令
netsh firewall set opmode ENABLEnetsh advfirewall set currentprofile state on
netsh firewall set opmode mode=ENABLE exceptions=enableRun the following commands:

Netsh advfirewall set currentprofile state on


netsh advfirewall set currentprofile firewallpolicy blockinboundalways,allowoutbound
netsh firewall set opmode mode=enable exceptions=disable profile=domainRun the following commands:

Netsh advfirewall set domainprofile state on


netsh advfirewall set domainprofile firewallpolicy blockinbound,allowoutbound
netsh firewall set opmode mode=enable profile=ALLRun the following commands:

netsh advfirewall set domainprofile state on


netsh advfirewall set privateprofile state on

有关更多信息,请运行以下命令:

netsh advfirewall set currentprofile ?

如果要设置特定的配置文件的防火墙状态,请使用以下选项之一,而不是"currentprofile"选项:

  • Domainprofile
  • Privateprofile
  • Publicprofile

示例 7: 还原默认策略设置

旧命令新命令
netsh firewall resetnetsh advfirewall reset

有关更多信息,请运行以下命令:

netsh advfirewall reset ?

例如 8: 启用特定服务

旧命令新命令
netsh firewall set service FileAndPrintnetsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes
netsh firewall set service RemoteDesktop enablenetsh advfirewall firewall set rule group="remote desktop" new enable=Yes
netsh firewall set service RemoteDesktop enable profile=ALLRun the following commands:

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

上次更新时间:2019年3月16日

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值