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 | lepiller-slave-zone |
31 | master-acl |
32 | slave-acl |
33 | hermes |
34 | ene)) |
35 | |
36 | (define-zone-entries lepiller.eu.zone |
37 | ;; Name TTL Class Type Data |
38 | ("ene" "" "IN" "A" ene-ip4) |
39 | ("hermes" "" "IN" "A" hermes-ip4) |
40 | ("hermes" "" "IN" "AAAA" hermes-ip6) |
41 | ("xana" "" "IN" "A" xana-ip4) |
42 | ("@" "" "IN" "A" hermes-ip4) |
43 | ("@" "" "IN" "AAAA" hermes-ip6) |
44 | ("www" "" "IN" "CNAME" "lepiller.eu.") |
45 | |
46 | ("avatar" "" "IN" "CNAME" "ene") |
47 | ("rennes" "" "IN" "CNAME" "ene") |
48 | ("nani" "" "IN" "CNAME" "xana") |
49 | ("i18n" "" "IN" "CNAME" "xana") |
50 | |
51 | ("@" "" "IN" "NS" "ns") |
52 | ("@" "" "IN" "NS" "ns2") |
53 | ("ns" "" "IN" "A" hermes-ip4) |
54 | ("ns" "" "IN" "AAAA" hermes-ip6) |
55 | ("ns2" "" "IN" "A" ene-ip4) |
56 | |
57 | ("@" "" "IN" "MX" "10 courriel") |
58 | ("@" "" "IN" "MX" "50 b.courriel") |
59 | ("b.courriel" "" "IN" "A" hermes-ip4) |
60 | ("b.courriel" "" "IN" "AAAA" hermes-ip6) |
61 | ("courriel" "" "IN" "A" ene-ip4) |
62 | ("imap" "" "IN" "CNAME" "courriel") |
63 | ("smtp" "" "IN" "CNAME" "b.courriel") |
64 | ("@" "" "IN" "TXT" "v=spf1 mx a ~all") |
65 | ("@" "" "IN" "SPF" "v=spf1 mx a ~all")) |
66 | |
67 | (define-zone-entries ipv4-reverse.zone |
68 | ("@" "" "IN" "PTR" "lepiller.eu.") |
69 | ("@" "" "IN" "NS" "ns.lepiller.eu.") |
70 | ("@" "" "IN" "NS" "ns2.lepiller.eu.")) |
71 | |
72 | (define-zone-entries ipv6-reverse.zone |
73 | ("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0" "" "IN" "PTR" "lepiller.eu.") |
74 | ("@" "" "IN" "NS" "ns.lepiller.eu.") |
75 | ("@" "" "IN" "NS" "ns2.lepiller.eu.")) |
76 | |
77 | (define ene |
78 | (knot-remote-configuration |
79 | (id "ene") |
80 | (address (list ene-ip4)) |
81 | (key "lepiller-key"))) |
82 | |
83 | (define hermes |
84 | (knot-remote-configuration |
85 | (id "hermes") |
86 | (address (list hermes-ip4)) |
87 | (key "lepiller-key"))) |
88 | |
89 | (define master-acl |
90 | (knot-acl-configuration |
91 | (id "master-acl") |
92 | (address (list hermes-ip4)) |
93 | (key '("lepiller-key")) |
94 | (action '(transfer)))) |
95 | |
96 | (define slave-acl |
97 | (knot-acl-configuration |
98 | (id "slave-acl") |
99 | (address (list ene-ip4)) |
100 | (key '("lepiller-key")) |
101 | (action '(notify)))) |
102 | |
103 | (define lepiller-master-zone |
104 | (knot-zone-configuration |
105 | (domain "lepiller.eu") |
106 | (notify '("hermes")) |
107 | (dnssec-policy "default") |
108 | (acl '("master-acl")) |
109 | (zonefile-load 'difference) |
110 | (zone (zone-file |
111 | (origin "lepiller.eu") |
112 | (entries lepiller.eu.zone) |
113 | (serial 2019041202))))) |
114 | |
115 | (define lepiller-slave-zone |
116 | (knot-zone-configuration |
117 | (domain "lepiller.eu") |
118 | (acl '("slave-acl")) |
119 | (master '("ene")))) |
120 | |
121 | (define ipv6-reverse-master-zone |
122 | (let* ((ip6 (string->list (substring (string-delete hermes-ip6 #\:) 0 12))) |
123 | (rev-ip6-lst (fold (lambda (elem acc) |
124 | (cons* #\. elem acc)) |
125 | '() |
126 | ip6)) |
127 | (rev-ip6 (list->string (cdr rev-ip6-lst))) |
128 | (domain (string-append rev-ip6 ".ip6.arpa"))) |
129 | (knot-zone-configuration |
130 | (domain domain) |
131 | (zone (zone-file |
132 | (origin domain) |
133 | (entries ipv6-reverse.zone) |
134 | (ns "ns.lepiller.eu.") |
135 | (mail "hostmaster.lepiller.eu.") |
136 | (serial 1)))))) |
137 | |
138 | (define ipv4-reverse-master-zone |
139 | (let ((domain (string-append |
140 | (string-join (reverse (string-split hermes-ip4 #\.)) ".") |
141 | ".in-addr.arpa"))) |
142 | (knot-zone-configuration |
143 | (domain domain) |
144 | (zone (zone-file |
145 | (origin domain) |
146 | (entries ipv4-reverse.zone) |
147 | (ns "ns.lepiller.eu.") |
148 | (mail "hostmaster.lepiller.eu.") |
149 | (serial 1)))))) |
150 |