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
45
  ("@"          ""  "IN"  "NS"    "ns")
46
  ("@"          ""  "IN"  "NS"    "ns2")
47
  ("ns"         ""  "IN"  "A"     hermes-ip4)
48
  ("ns"         ""  "IN"  "AAAA"  hermes-ip6)
49
  ("ns2"        ""  "IN"  "A"     ene-ip4)
50
51
  ("@"          ""  "IN"  "MX"    "10 courriel")
52
  ("@"          ""  "IN"  "MX"    "50 b.courriel")
53
  ("b.courriel" ""  "IN"  "A"     hermes-ip4)
54
  ("b.courriel" ""  "IN"  "AAAA"  hermes-ip6)
55
  ("courriel"   ""  "IN"  "A"     ene-ip4)
56
  ("imap"       ""  "IN"  "CNAME" "courriel")
57
  ("smtp"       ""  "IN"  "CNAME" "b.courriel")
58
  ("@"          ""  "IN"  "TXT"   "v=spf1 mx a ~all")
59
  ("@"          ""  "IN"  "SPF"   "v=spf1 mx a ~all"))
60
61
(define-zone-entries ipv4-reverse.zone
62
  ("@" "" "IN" "PTR" "lepiller.eu.")
63
  ("@"          ""  "IN"  "NS"    "ns.lepiller.eu.")
64
  ("@"          ""  "IN"  "NS"    "ns2.lepiller.eu."))
65
66
(define-zone-entries ipv6-reverse.zone
67
  ("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0" "" "IN" "PTR" "lepiller.eu.")
68
  ("@"          ""  "IN"  "NS"    "ns.lepiller.eu.")
69
  ("@"          ""  "IN"  "NS"    "ns2.lepiller.eu."))
70
71
(define lepiller-master-zone
72
  (knot-zone-configuration
73
    (domain "lepiller.eu")
74
    (dnssec-policy "default")
75
    (zonefile-load 'difference)
76
    (zone (zone-file
77
            (origin "lepiller.eu")
78
            (entries lepiller.eu.zone)
79
            (serial 2019041202)))))
80
81
(define ipv6-reverse-master-zone
82
  (let* ((ip6 (string->list (substring (string-delete hermes-ip6 #\:) 0 12)))
83
         (rev-ip6-lst (fold (lambda (elem acc)
84
                          (cons* #\. elem acc))
85
                        '()
86
                        ip6))
87
         (rev-ip6 (list->string (cdr rev-ip6-lst)))
88
         (domain (string-append rev-ip6 ".ip6.arpa")))
89
    (knot-zone-configuration
90
      (domain domain)
91
      (zone (zone-file
92
              (origin domain)
93
              (entries ipv6-reverse.zone)
94
              (ns "ns.lepiller.eu.")
95
              (mail "hostmaster.lepiller.eu.")
96
              (serial 1))))))
97
98
(define ipv4-reverse-master-zone
99
  (let ((domain (string-append
100
                  (string-join (reverse (string-split hermes-ip4 #\.)) ".")
101
                  ".in-addr.arpa")))
102
    (knot-zone-configuration
103
      (domain domain)
104
      (zone (zone-file
105
              (origin domain)
106
              (entries ipv4-reverse.zone)
107
              (ns "ns.lepiller.eu.")
108
              (mail "hostmaster.lepiller.eu.")
109
              (serial 1))))))
110