netsh ipsec 使用方法
在命令行下,通过netsh ipsec static来配置IPSEC安全策略。前提是IPSEC服务已经打开。 一个IPSEC由一个或者多个规则组成;一个规则有一个IP筛选器列表和一个相应的筛选器操作组成;这个筛选器列表和筛选器可以是系统本身所没有的,如果没有则需要自行建立,而一个筛选器又由一个或多个筛选器组成,因此配置IPSEC的时候必须分步进行。规则由筛选器列表和筛选器操作构成。而且存放在策略里,策略器由策略器列表来存储,这样就决定了一个步骤:建立空的安全策略,建立筛选器列表,建立筛选器操作,这三步不需要特定的顺序,建立筛选器需要在空筛选器列表建立成以后;建立规则在上述三步骤完成之后。下面开始配置策略的新增,修改,删除、最重要的是激活;
更详细的资料请参考微软的技术资源库: Netsh Commands for Internet Protocol Security (IPsec) 连接如下:http://technet.microsoft.com/zh-cn/cc725926 备注:注意连接里的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
前 |