Windows防火墙命令行手册

https://blog.csdn.net/mystudyblog0507/article/details/79617629

简介


netsh advfirewall firewall 命令行在Windows Vista 和 Windows Server 2008 中可用。
它提供了用于控制 Windows 防火墙行为的功能。
在早期版本的 Windows <包含Win7>操作系统中应该使用 netsh firewall 命令。

新版本的命令行提供了更精确地控制的防火墙规则的功能,这些规则包括以下的每个配置文件设置︰

  • 域(Domain)
  • 私有(Private)
  • 公共(Public)
需要以管理员身份运行

Old command 针对Win7以下版本<包含Win7>

详细信息


示例 1︰ 启用程序

Old command New command
netsh firewall add allowedprogram C:\MyApp\MyApp.exe "My Application" ENABLE netsh 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=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=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=ALL Run 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

示例 2︰ 启用端口

Old command New command
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

For more information about how to add firewall rules, run the following command:

netsh advfirewall firewall add rule ?

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

Old command New command
netsh firewall delete allowedprogram C:\MyApp\MyApp.exe netsh advfirewall firewall delete rule name=rule nameprogram="C:\MyApp\MyApp.exe"
delete portopening protocol=UDP port=500 netsh advfirewall firewall delete rule name=rule name protocol=udp localport=500

示例 4︰ 配置 ICMP 设置

Old command New command
netsh firewall set icmpsetting 8 netsh 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=enable netsh advfirewall firewall add rule name="All ICMP V4" protocol=icmpv4:any,any dir=in action=allow
netsh firewall set icmpsetting 13 disable all netsh advfirewall firewall add rule name="Block Type 13 ICMP V4" protocol=icmpv4:13,any dir=in action=block

示例 5︰设置日志记录

Old command New command
netsh firewall set logging %systemroot%\system32\LogFiles\Firewall\pfirewall.log 4096 ENABLE ENABLE Run 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

currentprofile 可以使用/Domainprofile/Privateprofile/Publicprofile/选项替换

示例 6︰ 启用 Windows 防火墙

Old command New command
netsh firewall set opmode ENABLE netsh advfirewall set currentprofile state on
netsh firewall set opmode mode=ENABLE exceptions=enable Run 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=domain Run the following commands:

Netsh advfirewall set domainprofile state on

netsh advfirewall set domainprofile firewallpolicy blockinbound,allowoutbound

netsh firewall set opmode mode=enable profile=ALL Run the following commands:

netsh advfirewall set domainprofile state on

netsh advfirewall set privateprofile state on

currentprofile 可以使用/Domainprofile/Privateprofile/Publicprofile/选项替换

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

Old command New command
netsh firewall reset netsh advfirewall reset

例如 8︰ 启用特定服务

Old command New command
netsh firewall set service FileAndPrint netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes
netsh firewall set service RemoteDesktop enable netsh advfirewall firewall set rule group="remote desktop" new enable=Yes
netsh firewall set service RemoteDesktop enable profile=ALL Run 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

[转帖]Windows 使用netsh 命令行方式处理 windows防火墙的方法的更多相关文章

  1. ResHacker 用命令行方式修改 windows PE文件版本号

    由于工作需要在詹金斯(genkins)集成环境打包,打包避免不了需要修改版本号,写入版本号最简单的方式通过修改windows rc文件 这就意味着,每次构建新版本前需要修改一次源文件 这个在用詹金斯集 ...

  2. 批处理脚本命令行方式关闭Windows服务

    对于一些不常用的Windows Services,可以通过设置其启动类型为"禁用"而将其关闭.这种关闭方式是长期性的,电脑重启之后仍然起作用. 有时候希望在批处理脚本里通过命令行方 ...

  3. [转]Windows中使用命令行方式编译打包Android项目

    http://my.oschina.net/liux/blog/37875 网上很多用Ant来编译打包Android应用的文章,毕竟Ant是纯Java语言编写的,具有很好的跨平台性.今天想写个纯win ...

  4. Windows Server 2016-命令行方式管理Windows服务

    Microsoft Windows 服务(过去称为 NT 服务)允许用户创建可在其自身的 Windows 会话中长时间运行的可执行应用程序. 这些服务可在计算机启动时自动启动,可以暂停和重启,并且不显 ...

  5. Sqlserver 命令行方式修改 用户密码的方法

    1. 之前写了一个 可以使用  ssms 的方式修改密码的情况 2. 还有办法是执行命令 exec sp_password null,'newpassword','sa' # sa 是用户名 newp ...

  6. 用命令行方式关闭linux防火墙

    #/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT #/sbin/iptables -I INPUT -p tcp --dport 22 -j A ...

  7. 用命令行方式关闭CentOS防火墙

    #/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT #/sbin/iptables -I INPUT -p tcp --dport 22 -j A ...

  8. 使用命令行方式运行 JMeter 脚本

    For non-interactive testing, you may choose to run JMeter without the GUI. To do so, use the followi ...

  9. 玩转Windows服务系列——命令行管理Windows服务

    说到Windows服务的管理就不得不说通过命令行的方式管理Windows服务,因为无论是系统管理员,还是通过编程的方式调用cmd命令,命令行都是非常方便以及强大的工具. 接下来就看一下如何通过cmd命 ...

随机推荐

  1. kubernetes label 标签使用

    查看node的标签kubectl get node --show-labels 删除标签kubectl label nodes node5 storagenode- 设置标签kubectl label ...

  2. 【题解】[HNOI2008]神奇的国度—BZOJ1006。

    之前说顺着打BZOJ结果又被自己给鸽了qwq. ------------------------------------ 言归正传这道题应该怎么做. 先给大家普及一下弦图(连接环上俩个不相邻节点的边称 ...

  3. day2-课堂笔记

    #面向对象 函数=方法 系统内建函数:len().id() 对象函数

  4. WorldWind源码剖析系列:缓冲类Cache

    缓冲类Cache主要用于在最小的限制条件下保存从远程服务器通过网络下载下来的地理空间数据,以便当用户处于离线状态时能够使用这些已经缓冲好的数据.Google Earth也采用类似机制处理用户离线浏览漫 ...

  5. springbatch入门练习(第二篇)

    对第一遍内容的补充 <?xml version="1.0" encoding="UTF-8"?> <bean:beans xmlns=&quo ...

  6. TCP和UDP套接字编程 (java实现)

    在了解网络编程之前,我们先了解一下什么叫套接字 套接字即指同一台主机内应用层和运输层之间的接口 由于这个套接字是建立在网络上建立网络应用的可编程接口 因此也将套接字称为应用程序和网络之间的应用程序编程 ...

  7. rsync+inotifywait

    0.rsync+inotify是实现文件实时同步的,加什么参数才能实现实时同步,--delete参数又是什么意思? 1.运行模式(服务器) rsync有两种常用的认证方式,一种是rsync-daemo ...

  8. 运放参数的详细解释和分析-part3,输入失调电压Vos及温漂

    运放参数的详细解释和分析-part3,输入失调电压Vos及温漂 在运放的应用中,不可避免的会碰到运放的输入失调电压Vos问题,尤其对直流信号进行放大时,由于输入失调电压Vos的存在,放大电路的输出端总 ...

  9. [Baltic2013]ballmachine BZOJ3133

    分析: 我们考虑,因为每次放置的时候,都是向子树中含有的编号最小的哪一个走,那么放置的顺序是固定的,我们将边以to的子树最小排序,之后得到的出栈序就是球的放入顺序.目测可以使用堆来实现,线段树也能实现 ...

  10. 20155327 Exp9 Web安全基础

    20155327 Exp9 Web安全基础 基础问题回答 (1)SQL注入攻击原理,如何防御 SQL注入攻击就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器 ...