查看: 203|回复: 0

[Mikrotik Ros] Mikrotik RouterOS ipv6-dns脚本

[复制链接]

124

主题

0

回帖

508

积分

管理员

积分
508
发表于 2026-8-20 21:31:22 | 显示全部楼层 |阅读模式
  1. #!rsc by RouterOS
  2. #
  3. # Requirements:
  4. #   - mod/ipv6-functions
  5. #   - mod/ipv6-structured
  6. #
  7. # Usage:
  8. #
  9. # argWanPool: name of the WAN pool
  10. # argHosts: An array of {interface ; IID ; name} records
  11. # argManagedID: regex-escaped unique ID of the managed objects
  12. #
  13. # For every host in $argHosts one /ipv6/firewall/address-list
  14. # and one AAAA /ip/dns/static record will be added.
  15. #

  16. :global argWanPool
  17. :global argHosts
  18. :global argManagedID

  19. :global GlobalFunctionsReady;
  20. :while ($GlobalFunctionsReady != true) do={ :delay 500ms; }

  21. :global WaitIP6Address
  22. :global StructureIP6Address
  23. :global LogPrint

  24. /ipv6/pool
  25. :local varWanPrefix [get value-name=prefix $argWanPool]
  26. :local varWanPrefixTTL [get value-name=expires-after $argWanPool]
  27. :if ([:typeof $varWanPrefixTTL] = "nil") do={
  28.     :set varWanPrefixTTL 1d00:00:00
  29. } else={
  30.     :set varWanPrefixTTL ($varWanPrefixTTL + 01:00:00)
  31. }

  32. :foreach varHost in=$argHosts do={
  33.     :local varInt ($varHost->0)
  34.     :local varIID ($varHost->1)
  35.     :local varName ($varHost->2)

  36.     :do {
  37.         :local varPrefix ([$StructureIP6Address [$WaitIP6Address $varInt $varWanPrefix ""]]->"prefix")
  38.         :local varAddr ($varPrefix | $varIID)

  39.         /ipv6/firewall/address-list
  40.         remove [find list=$varName comment~"$argManagedID\$"]
  41.         :log info "Add $varName -> $varAddr address list, expires after $varWanPrefixTTL"
  42.         add list=$varName address=$varAddr timeout=$varWanPrefixTTL comment="Managed: DNSv6 / $argManagedID"

  43.         /ip/dns/static
  44.         remove [find name=$varName comment~"$argManagedID\$"]
  45.         :log info "Add $varName -> $varAddr dns, expires after $varWanPrefixTTL"
  46.         add name=$varName address=$varAddr type=AAAA ttl=$varWanPrefixTTL comment="Managed: DNSv6 / $argManagedID"
  47.     } on-error={
  48.         $LogPrint error $0 ("No prefix from $varWanPrefix on $varInt")
  49.         :error "fatal error in ipv6-dns.rsc"
  50.     }
  51. }
复制代码


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注公众号

相关侵权、举报、投诉及建议等,请发 E-mail:admin@discuz.vip

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.|蜀ICP备17024538号-6

在本版发帖
关注公众号
QQ客服返回顶部