IPSec阻止外网访问1433端口示例(命令行版本)

创建IP安全策略

@echo off
rem 1.创建IP安全策略
netsh ipsec static add policy name=disallow-tcp-1433
rem 2.添加规则
rem 2.1 阻止访问tcp1433规则
netsh ipsec static add filter filterlist=disallow_1433 protocol=TCP srcaddr=Any srcport=0 dstaddr=Me dstport=1433 mirrored=yes
netsh ipsec static add filteraction name=disallow_1433 action=block
netsh ipsec static add rule name=rule1 policy=disallow-tcp-1433 filterlist=disallow_1433 filteraction=disallow_1433
rem 2.2 允许访问tcp1433规则
netsh ipsec static add filter filterlist=allow_1433 protocol=TCP srcaddr=192.168.0.0 srcmask=255.255.255.0 srcport=0 dstaddr=Me dstport=1433 mirrored=yes
netsh ipsec static add filteraction name=allow_1433 action=permit
netsh ipsec static add rule name=rule2 policy=disallow-tcp-1433 filterlist=allow_1433 filteraction=allow_1433
rem 3.指派策略
netsh ipsec static set policy name=disallow-tcp-1433 assign=yes

删除IP安全策略

@echo off
rem 删除指定的 IPSec 策略及所有关联规则
netsh ipsec static delete policy name=disallow-tcp-1433

说明:netsh ipsec命令行只能在Windows Server™ 2003和Windows Server™ 2008系统下运行。
说明:同一时间只能一个IPSec 策略被指派。

参考资料

[1].用于 Internet 协议安全的 Netsh 命令:http://technet.microsoft.com/zh-cn/library/cc739550(v=ws.10).aspx

评论: 0 | 引用: 0 | 查看次数: 4414
发表评论
登录后再发表评论!