820-dns-config 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/lua
  2. local site = require 'gluon.site'
  3. local uci = require('simple-uci').cursor()
  4. local dns = site.dns({})
  5. local next_node = site.next_node({})
  6. local dnsmasq = uci:get_first("dhcp", "dnsmasq")
  7. uci:set('dhcp', dnsmasq, 'localise_queries', true)
  8. uci:set('dhcp', dnsmasq, 'localservice', false)
  9. uci:set('dhcp', dnsmasq, 'server', dns.servers)
  10. uci:set('dhcp', dnsmasq, 'cachesize', dns.cacheentries)
  11. uci:delete('firewall', 'client_dns')
  12. if dns.servers then
  13. -- allow inbound traffic for dns from client zone
  14. uci:section('firewall', 'rule', 'client_dns', {
  15. src = 'local_client',
  16. dest_port = '53',
  17. proto = 'tcpudp',
  18. target = 'ACCEPT',
  19. })
  20. end
  21. local function set_dns_record(name, ip, sectionname)
  22. if not ip then return end
  23. uci:section('dhcp', 'domain', sectionname, {
  24. name = name,
  25. ip = ip,
  26. })
  27. end
  28. uci:delete_all('dhcp', 'domain', function(s)
  29. return (s['.name'] and string.match(s['.name'], "^nextnode[46]"))
  30. end)
  31. for i, name in ipairs(next_node.name or {}) do
  32. set_dns_record(name, next_node.ip4, 'nextnode4_' .. i)
  33. set_dns_record(name, next_node.ip6, 'nextnode6_' .. i)
  34. end
  35. uci:save('dhcp')
  36. uci:save('firewall')