system-configuration/modules/config/dns.scm

dns.scm

1
;;; Tyreunom's system administration and configuration tools.
2
;;;
3
;;; Copyright © 2019 Julien Lepiller <julien@lepiller.eu>
4
;;;
5
;;; This program is free software: you can redistribute it and/or modify
6
;;; it under the terms of the GNU General Public License as published by
7
;;; the Free Software Foundation, either version 3 of the License, or
8
;;; (at your option) any later version.
9
;;;
10
;;; This program is distributed in the hope that it will be useful,
11
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
;;; GNU General Public License for more details.
14
;;;
15
;;; You should have received a copy of the GNU General Public License
16
;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18
;;
19
;; DNS services
20
;;
21
22
(define-module (config dns)
23
  #:use-module (data dns)
24
  #:use-module (gnu services)
25
  #:use-module (gnu services dns)
26
  #:use-module (srfi srfi-1)
27
  #:export (ipv4-reverse-master-zone
28
            ipv6-reverse-master-zone
29
            lepiller-master-zone))
30
31
(define-zone-entries lepiller.eu.zone
32
;; Name         TTL Class Type Data
33
  ("ene"        ""  "IN"  "A"     ene-ip4)
34
  ("hermes"     ""  "IN"  "A"     hermes-ip4)
35
  ("hermes"     ""  "IN"  "AAAA"  hermes-ip6)
36
  ("xana"       ""  "IN"  "A"     xana-ip4)
37
  ("@"          ""  "IN"  "A"     hermes-ip4)
38
  ("@"          ""  "IN"  "AAAA"  hermes-ip6)
39
  ("www"        ""  "IN"  "CNAME" "lepiller.eu.")
40
41
  ("avatar"     ""  "IN"  "CNAME" "ene")
42
  ("rennes"     ""  "IN"  "CNAME" "ene")
43
  ("nani"       ""  "IN"  "CNAME" "xana")
44
  ("i18n"       ""  "IN"  "CNAME" "xana")
45
46
  ("@"          ""  "IN"  "NS"    "ns")
47
  ("@"          ""  "IN"  "NS"    "ns2")
48
  ("ns"         ""  "IN"  "A"     hermes-ip4)
49
  ("ns"         ""  "IN"  "AAAA"  hermes-ip6)
50
  ("ns2"        ""  "IN"  "A"     ene-ip4)
51
52
  ("@"          ""  "IN"  "MX"    "10 courriel")
53
  ("@"          ""  "IN"  "MX"    "50 b.courriel")
54
  ("b.courriel" ""  "IN"  "A"     hermes-ip4)
55
  ("b.courriel" ""  "IN"  "AAAA"  hermes-ip6)
56
  ("courriel"   ""  "IN"  "A"     ene-ip4)
57
  ("imap"       ""  "IN"  "CNAME" "courriel")
58
  ("smtp"       ""  "IN"  "CNAME" "b.courriel")
59
  ("@"          ""  "IN"  "TXT"   "v=spf1 mx a ~all")
60
  ("@"          ""  "IN"  "SPF"   "v=spf1 mx a ~all"))
61
62
(define-zone-entries ipv4-reverse.zone
63
  ("@" "" "IN" "PTR" "lepiller.eu.")
64
  ("@"          ""  "IN"  "NS"    "ns.lepiller.eu.")
65
  ("@"          ""  "IN"  "NS"    "ns2.lepiller.eu."))
66
67
(define-zone-entries ipv6-reverse.zone
68
  ("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0" "" "IN" "PTR" "lepiller.eu.")
69
  ("@"          ""  "IN"  "NS"    "ns.lepiller.eu.")
70
  ("@"          ""  "IN"  "NS"    "ns2.lepiller.eu."))
71
72
(define lepiller-master-zone
73
  (knot-zone-configuration
74
    (domain "lepiller.eu")
75
    (dnssec-policy "default")
76
    (zonefile-load 'difference)
77
    (zone (zone-file
78
            (origin "lepiller.eu")
79
            (entries lepiller.eu.zone)
80
            (serial 2019041202)))))
81
82
(define ipv6-reverse-master-zone
83
  (let* ((ip6 (string->list (substring (string-delete hermes-ip6 #\:) 0 12)))
84
         (rev-ip6-lst (fold (lambda (elem acc)
85
                          (cons* #\. elem acc))
86
                        '()
87
                        ip6))
88
         (rev-ip6 (list->string (cdr rev-ip6-lst)))
89
         (domain (string-append rev-ip6 ".ip6.arpa")))
90
    (knot-zone-configuration
91
      (domain domain)
92
      (zone (zone-file
93
              (origin domain)
94
              (entries ipv6-reverse.zone)
95
              (ns "ns.lepiller.eu.")
96
              (mail "hostmaster.lepiller.eu.")
97
              (serial 1))))))
98
99
(define ipv4-reverse-master-zone
100
  (let ((domain (string-append
101
                  (string-join (reverse (string-split hermes-ip4 #\.)) ".")
102
                  ".in-addr.arpa")))
103
    (knot-zone-configuration
104
      (domain domain)
105
      (zone (zone-file
106
              (origin domain)
107
              (entries ipv4-reverse.zone)
108
              (ns "ns.lepiller.eu.")
109
              (mail "hostmaster.lepiller.eu.")
110
              (serial 1))))))
111