[转帖]Windows 使用netsh 命令行方式处理 windows防火墙的方法
Windows防火墙命令行手册
简介
- 域(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:
示例 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 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防火墙的方法的更多相关文章
- ResHacker 用命令行方式修改 windows PE文件版本号
由于工作需要在詹金斯(genkins)集成环境打包,打包避免不了需要修改版本号,写入版本号最简单的方式通过修改windows rc文件 这就意味着,每次构建新版本前需要修改一次源文件 这个在用詹金斯集 ...
- 批处理脚本命令行方式关闭Windows服务
对于一些不常用的Windows Services,可以通过设置其启动类型为"禁用"而将其关闭.这种关闭方式是长期性的,电脑重启之后仍然起作用. 有时候希望在批处理脚本里通过命令行方 ...
- [转]Windows中使用命令行方式编译打包Android项目
http://my.oschina.net/liux/blog/37875 网上很多用Ant来编译打包Android应用的文章,毕竟Ant是纯Java语言编写的,具有很好的跨平台性.今天想写个纯win ...
- Windows Server 2016-命令行方式管理Windows服务
Microsoft Windows 服务(过去称为 NT 服务)允许用户创建可在其自身的 Windows 会话中长时间运行的可执行应用程序. 这些服务可在计算机启动时自动启动,可以暂停和重启,并且不显 ...
- Sqlserver 命令行方式修改 用户密码的方法
1. 之前写了一个 可以使用 ssms 的方式修改密码的情况 2. 还有办法是执行命令 exec sp_password null,'newpassword','sa' # sa 是用户名 newp ...
- 用命令行方式关闭linux防火墙
#/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT #/sbin/iptables -I INPUT -p tcp --dport 22 -j A ...
- 用命令行方式关闭CentOS防火墙
#/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT #/sbin/iptables -I INPUT -p tcp --dport 22 -j A ...
- 使用命令行方式运行 JMeter 脚本
For non-interactive testing, you may choose to run JMeter without the GUI. To do so, use the followi ...
- 玩转Windows服务系列——命令行管理Windows服务
说到Windows服务的管理就不得不说通过命令行的方式管理Windows服务,因为无论是系统管理员,还是通过编程的方式调用cmd命令,命令行都是非常方便以及强大的工具. 接下来就看一下如何通过cmd命 ...
随机推荐
- [luogu4072] 征途
题面 题意体面中写得很明确, 应该不用我说了, 方差的概念在初中人教版九年级数学中有所提到, 没有上过初中的同学们可以左转百度. 将序列拆为几段求最值, 我们考虑用dp来实现. 先推一下式子, 令方差 ...
- 解决php编译报错configure: error: mcrypt.h not found. Please reinstall libmcrypt.
yum install -y epel-releaseyum install -y libmcrypt-devel
- Python:基础知识
python是一种解释型.面向对象的.带有动态语义的高级程序语言. 一.下载安装 官网下载地址:https://www.python.org/downloads 下载后执行安装文件,按照默认安装顺序安 ...
- sql 两表更新
UPDATE sale_origin_line set state='cancel' from sale_origin p,sale_origin_line q where p.id=q.or ...
- 深入解析Java中的装箱和拆箱
自己主动装箱和拆箱问题是Java中一个老生常谈的问题了,今天我们就来一些看一下装箱和拆箱中的若干问题.本文先讲述装箱和拆箱最主要的东西,再来看一以下试笔试中常常遇到的与装箱.拆箱相关的问题. 下面是本 ...
- 降阶法计算行列式方法有个地方有Bug(原文也已更正,此为更正后部分)
今天用此函数做方程求解时发现有误,特此更正: /// <summary> /// 降阶法计算行列式 /// </summary> /// <param name=&quo ...
- kettle学习笔记(九)——子转换、集群与变量
一.概述 kettle中3个重要的步骤: 子转换/映射 在转换里调用一个子转换,便于封装和重用. 集群 集群模式 变量和参数 变量和参数的用法 二.子转换 1.定义子转换 主要由映射输入与映射输出定义 ...
- 2017-2018-2 20155231《网络对抗技术》实验八: WEB基础实验
2017-2018-2 20155231<网络对抗技术>实验八:Web基础 实验要求: Web前端HTML(0.5分) 能正常安装.启停Apache.理解HTML,理解表单,理解GET与P ...
- WinRT IO相关整理
虽然一般UWP开发还是依赖.Net for UWP,但有时还是需要调用WinRT API.特别是在IO部分,WinRT有着和.Net似曾相识但又不尽相同的接口.在此对经常用到的一些地方进行一下整理. ...
- Luogu P1120 小木棍 [数据加强版]
看了题目心中只有一个字——搜索!!! 但是很显然,朴素的搜索(回溯)绝壁超时. 剪枝&优化(要搞很多,要不然过不了) 1:从小到大搜索它们的因数,这样找到就exit. 2:将数据从大到小排序, ...