Netsh Commands for Windows Firewall with Advanced Security.连接,他给你的帮助会更大;
导出IPsec安全策略:Netsh ipsec static exportpolicy file = d:\ExportSecurity.ipsec
导入IPsec安全策略:Netsh ipsec static importpolicy file = d:\ImportSecurity.ipsec
1、建立一个新的策略
1.1首先建立一个空的安全策略[Michael's安全策略]
Netsh ipsec static add policy name = Michael's安全策略
1.2建立一个筛选器操作”阻止”
Netsh ipsec static add filteraction name = 阻止 action =block
1.3建立一个筛选器列表“可访问的终端列表”
Netsh ipsec static add filterlist name =可访问的终端列表
Netsh ipsec static add filter filterlist = 可访问的终端列表
srcaddr=203.86.32.248
dstaddr = me dstport = 3389
description = 部门1访问 protocol =TCP mirrored = yes
Netsh ipsec static add filter filterlist = 可访问的终端列表
Srcaddr = 203.86.31.0 srcmask=255.255.255.0
dstaddr = 60.190.145.9 dstport = 0
description = 部门2访问 protocol =any mirrored = yes
1.4建立策略规则
Netsh ipsec static add rule name =可访问的终端策略规则
Policy = Michael's安全策略
filterlist =可访问的终端列表
filteraction = 阻止
2、修改策略
netsh ipsec static set filter filterlist = 可访问的终端列表
srcaddr = 220.207.31.249
dstaddr = Me dstport=3389 protocol=TCP
3、删除策略
netsh ipsec static delete rule name = 可访问的终端策略规则 policy = Michael's安全策略
netsh ipsec static delete filterlist name = 可访问的终端列表
4、最最重要的一步是激活;
netsh ipsec static set policy name = Michael's安全策略 assign = y
以下提供一个我自己写的实例:
复制代码 代码如下:
echo 创建安全策略
Netsh IPsec static add policy name = APU安全策略
echo 创建筛选器是阻止的操作
Netsh IPsec static add filteraction name = 阻止 action = block
echo 创建筛选器是允许的操作
Netsh IPsec static add filteraction name = 允许 action = permit
echo 建立一个筛选器可以访问的终端列表
Netsh IPsec static add filterlist name = 可访问的终端列表
Netsh IPsec static add filter filterlist = 可访问的终端列表 srcaddr = 203.86.32.248 dstaddr = me dstport = 3389 description = 部门1访问 protocol = TCP mirrored = yes
echo 建立一个筛选器可以访问的终端列表
Netsh ipsec static add filter filterlist = 可访问的终端列表 Srcaddr = 203.86.31.0 srcmask=255.255.255.0 dstaddr = 60.190.145.9 dstport = 0 description = 部门2访问 protocol =any mirrored = yes
echo 建立策略规则
Netsh ipsec static add rule name = 可访问的终端策略规则 Policy = APU安全策略 filterlist = 可访问的终端列表 filteraction = 阻止
echo 激活策略
netsh ipsec static set policy name = APU安全策略 assign = y
pause
或者
复制代码 代码如下:
Netsh ipsec static add policy name = 默认策略名称
pause
Netsh ipsec static add filteraction name = 阻止操作 action = block
pause
Netsh ipsec static add filteraction name = 允许操作 action = permit
pause
Netsh ipsec static add filterlist name = 访问列表
pause
Netsh ipsec static add filterlist name = 阻止列表
pause
Netsh ipsec static add filter filterlist = 访问列表1 srcaddr = 203.86.32.248 dstaddr = me dstport = 3389 description = 部门1访问 protocol = TCP mirrored = yes
pause
Netsh ipsec static add filter filterlist = 访问列表2 srcaddr = 203.86.31.0 srcmask = 255.255.255.0 dstaddr = 60.190.145.9 dstport = 0 description = 部门2访问 protocol = any mirrored = yes
pause
Netsh ipsec static add rule name = 可访问的终端策略规则 Policy = 默认策略名称 filterlist = 访问列表1 filteraction = 阻止操作
pause
Netsh ipsec static add rule name = 可访问的终端策略规则 Policy = 默认策略名称 filterlist = 访问列表2 filteraction = 阻止操作
pause
netsh ipsec static set policy name = 默认策略名称 assign = y
pause
[以下是转载未经过测试,百度上都可以找的到。]
复制代码 代码如下:
REM =================开始================
netsh ipsec static ^
add policy name=bim
REM 添加2个动作,block和permit
netsh ipsec static ^
add filteraction name=Permit action=permit
netsh ipsec static ^
add filteraction name=Block action=block
REM 首先禁止所有访问
netsh ipsec static ^
add filterlist name=AllAccess
netsh ipsec static ^
add filter filterlist=AllAccess srcaddr=Me dstaddr=Any
netsh ipsec static ^
add rule name=BlockAllAccess policy=bim filterlist=AllAccess filteraction=Block
REM 开放某些IP无限制访问
netsh ipsec static ^
add filterlist name=UnLimitedIP
netsh ipsec static ^
add filter filterlist=UnLimitedIP srcaddr=61.128.128.67 dstaddr=Me
netsh ipsec static ^
add rule name=AllowUnLimitedIP policy=bim filterlist=UnLimitedIP filteraction=Permit
REM 开放某些端口
netsh ipsec static ^
add filterlist name=OpenSomePort
netsh ipsec static ^
add filter filterlist=OpenSomePort srcaddr=Any dstaddr=Me dstport=20 protocol=TCP
netsh ipsec static ^
add filter filterlist=OpenSomePort srcaddr=Any dstaddr=Me dstport=21 protocol=TCP
netsh ipsec static ^
add filter filterlist=OpenSomePort srcaddr=Any dstaddr=Me dstport=80 protocol=TCP
netsh ipsec static ^
add filter filterlist=OpenSomePort srcaddr=Any dstaddr=Me dstport=3389 protocol=TCP
netsh ipsec static ^
add rule name=AllowOpenSomePort policy=bim filterlist=OpenSomePort filteraction=Permit
REM 开放某些ip可以访问某些端口
netsh ipsec static ^
add filterlist name=SomeIPSomePort
netsh ipsec static ^
add filter filterlist=SomeIPSomePort srcaddr=Me dstaddr=Any dstport=80 protocol=TCP
netsh ipsec static ^
add filter filterlist=SomeIPSomePort srcaddr=61.128.128.68 dstaddr=Me dstport=1433 protocol=TCP
netsh ipsec static ^
add rule name=AllowSomeIPSomePort policy=bim filterlist=SomeIPSomePort filteraction=Permit