批处理设置IPsec安全策略

导出IP安全策略:netsh ipsec static exportpolicy file=d:\Security.ipsec
导入IP安全策略:netsh ipsec static importpolicy file=d:\Security.ipsc

windows 2003命令行ipsec批量添加端口

添加安全策略名称

netsh ipsec static add policy name=我的安全策略

添加 IP筛选器列表

netsh ipsec static add filterlist name=允许列表
netsh ipsec static add filterlist name=拒绝列表


添加筛选器到IP筛选器列表(允许上网)

netsh ipsec static add filter filterlist=允许列表  srcaddr=me dstaddr=any dstport=80 protocol=tcp mirrored=yes description=web访问
netsh ipsec static add filter filterlist=允许列表  srcaddr=me dstaddr=any dstport=53 protocol=tcp mirrored=yes description=dns访问
netsh ipsec static add filter filterlist=允许列表  srcaddr=me dstaddr=any dstport=53 protocol=udp mirrored=yes description=dns访问
添加筛选器到IP筛选器列表(不让别人访问)
netsh ipsec static add filter filterlist=拒绝列表  srcaddr=any dstaddr=me protocol=any mirrored=yes description=别人到我任何访问
netsh ipsec static add filter filterlist=拒绝列表  srcaddr=me dstaddr=any protocol=any mirrored=yes description=我到任何访问

添加筛选器操作

netsh ipsec static add filteraction name=可以 action=permit
netsh ipsec static add filteraction name=不可以 action=block

创建一个链接指定 IPSec 策略、筛选器列表和筛选器操作的规则(加入规则到我的安全策略)

netsh ipsec static add rule name=允许规则  policy=我的安全策略 filterlist=允许列表 filteraction=可以
netsh ipsec static add rule name=拒绝规则  policy=我的安全策略 filterlist=拒绝列表 filteraction=不可以

激活我的安全策略

netsh ipsec static set policy name=我的安全策略 assign=y

总结一下,策略policy(规则rule(筛选器列表filterlist(筛选器filter))—筛选器操作filteraction)
批处理设置文件服务器IPsec安全策略如下

@echo off
netsh ipsec static add policy name=Security
 
netsh ipsec static add filterlist name=DenyAll description="拒绝所有访问"
netsh ipsec static add filter filterlist=DenyAll srcaddr=Any srcport=0 dstaddr=Any dstport=0 protocol=Any mirrored=yes
netsh ipsec static add filteraction name=Block action=block
netsh ipsec static add rule name=DenyAll policy=Security filterlist=DenyAll filteraction=Block
 
netsh ipsec static add filterlist name=share
netsh ipsec static add filter filterlist=share srcaddr=Any srcport=0 dstaddr=Me dstport=445 protocol=TCP mirrored=yes
netsh ipsec static add rule name=share policy=Security filterlist=share filteraction=Permit
 
netsh ipsec static set policy name=Security assign=y
pause
exit

还没有评论,快来抢沙发!

发表评论

  • 😉
  • 😐
  • 😡
  • 😈
  • 🙂
  • 😯
  • 🙁
  • 🙄
  • 😛
  • 😳
  • 😮
  • emoji-mrgree
  • 😆
  • 💡
  • 😀
  • 👿
  • 😥
  • 😎
  • ➡
  • 😕
  • ❓
  • ❗
  • 70 queries in 0.380 seconds