CMD批量添加防火墙端口

通过命令提示符窗口输入命令,添加防火墙允许端口。语法格式如下:

netsh advfirewall firewall add rule name=新端口 protocol=TCP localport=新端口 dir=in action=allow,block 其中allow允许,block禁止

以33088端口为例,用管理员身份在命令提示符下运行下面命令,便可在Windows防火墙中开启33088端口。

netsh advfirewall firewall add rule name=33088 protocol=TCP localport=33088 dir=in action=allow

常用的脚本:

(1)恢复初始防火墙设置
    netsh advfirewall reset
(2)关闭防火墙(测试目前win7及以上版本的系统适用)
    netsh advfirewall set allprofiles state off
    (windows XP建议适用下面的命令:)
    netsh firewall set opmode mode=disable
(3)启用桌面防火墙
    netsh advfirewall set allprofiles state on
(4)设置默认输入和输出策略
    netsh advfirewall set allprofiles firewallpolicy allowinbound,allowoutbound
    以上是设置为允许,如果设置为拒绝使用blockinbound,blockoutbound
 

  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
 

  netsh advfirewall firewall add rule name= "80" dir=in protocol=tcp localport=137 action=allow

 netsh advfirewall firewall add rule name= "8080" dir=in protocol=tcp localport=138 action=allow
 

 netsh advfirewall firewall add rule name= "3306" dir=in protocol=tcp localport=3306 action=allow
 

 netsh advfirewall firewall add rule name= "3306" dir=in protocol=tcp localport=3306 action=allow
 

你可能感兴趣的:(服务器,网络,运维)