aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2019-04-06 16:22:11 +0000
committerChristine Dodrill <me@christine.website>2019-04-06 16:22:11 +0000
commit1a2bc6313d2e03ad1e97ce590c859510c1d32630 (patch)
treeae78779a84a82156ef26532e4934a6be3dd46d25 /cmd
parent64aea8ab9b9d793128a4725fd77f308ca8d876bc (diff)
downloadx-1a2bc6313d2e03ad1e97ce590c859510c1d32630.tar.xz
x-1a2bc6313d2e03ad1e97ce590c859510c1d32630.zip
document dnsd for others
Diffstat (limited to 'cmd')
-rw-r--r--cmd/dnsd/Dockerfile11
-rw-r--r--cmd/dnsd/README.md87
-rw-r--r--cmd/dnsd/dnsd.service12
-rw-r--r--cmd/dnsd/main.go21
4 files changed, 112 insertions, 19 deletions
diff --git a/cmd/dnsd/Dockerfile b/cmd/dnsd/Dockerfile
new file mode 100644
index 0000000..7cd22bf
--- /dev/null
+++ b/cmd/dnsd/Dockerfile
@@ -0,0 +1,11 @@
+ARG X_VERSION
+
+FROM xena/xperimental:$X_VERSION as build
+FROM xena/alpine
+
+ENV PORT 53
+ENV FORWARD_SERVER 1.1.1.1:53
+EXPOSE 53/udp
+
+COPY --from=build /usr/local/bin/dnsd /usr/local/bin/dnsd
+CMD /usr/local/bin/dnsd
diff --git a/cmd/dnsd/README.md b/cmd/dnsd/README.md
new file mode 100644
index 0000000..2855ae3
--- /dev/null
+++ b/cmd/dnsd/README.md
@@ -0,0 +1,87 @@
+# dnsd
+
+A custom DNS server for my network. DNS zone files are dynamically downloaded on
+startup and are continuously monitored for changes. When the DNS zone is changed,
+the service reloads it.
+
+I primarily use this to give myself a limited form of piHole DNS adblocking, as
+well as serving my [home network services](https://home.cetacean.club).
+
+This is related to my [WireGuard Site to Site VPN](https://christine.website/blog/site-to-site-wireguard-part-1-2019-04-02)
+project.
+
+## How to Configure `dnsd`
+
+`dnsd` relies on [RFC 1035](https://tools.ietf.org/html/rfc1035) zone files. This
+is a file that looks roughly like this:
+
+```rfc1035
+$TTL 60
+$ORIGIN pele.
+@ IN SOA oho.pele. some@email.address. (
+ 2019040601 ; serial number YYYYMMDDNN
+ 28800 ; Refresh
+ 7200 ; Retry
+ 864000 ; Expire
+ 60 ; Minimum DNS TTL
+ )
+ IN NS oho.pele.
+
+oho IN A 10.55.0.1
+1.0.55.10.in-addr.arpa. IN PTR oho.pele.
+
+;; apps
+prometheus IN CNAME oho.pele.
+grafana IN CNAME oho.pele.
+```
+
+Put this file in a publicly available place and then set its URL as a
+`-zone-file` in the command line configuration. This file will be monitored
+every minute for changes (via the proxy of the ETag of the HTTP responses).
+
+If you need to change the DNS forwarding server, set the value of the environment
+variable `FORWARD_SERVER` or the command line flag `-forward-server`.
+
+## Installation
+
+### Docker
+
+```console
+$ docker run --name dnsd -p 53:53/udp -dit --restart always xena/dnsd:1.0.2-5-g64aea8a \
+ dnsd -zone-url https://domain.hostname.tld/path/to/your.zone \
+ -zone-url https://domain.hostname.tld/path/to/adblock.zone \
+ -forward-server 1.1.1.1:53
+```
+
+### From Git with systemd
+
+```console
+$ go get -u -v github.com/Xe/x/cmd/dnsd@latest
+$ GOBIN=$(pwd) go install github.com/Xe/x/cmd/dnsd
+$ sudo cp dnsd /usr/local/bin/dnsd
+<edit dnsd.service as needed>
+$ sudo cp dnsd.service /etc/systemd/system/dnsd.service
+$ sudo systemctl daemon-reload
+$ sudo systemctl start dnsd
+$ sudo systemctl status dnsd
+$ sudo systemctl enable dnsd
+```
+
+## Testing
+
+```console
+$ dig @127.0.0.1 google.com
+$ dig @127.0.0.1 custom.domain
+```
+
+## Support
+
+If you need help with this, please [contact](https://christine.website/contact) me.
+This is fairly simplistic software. If you need anything more, I'd suggest using
+[CoreDNS](https://coredns.io) or similar.
+
+If you like this software, please consider donating on [Patreon](https://www.patreon.com/cadey)
+or [Ko-Fi](https://www.ko-fi.com/christinedodrill). I use this software daily on my personal
+network to service most of my devices.
+
+Thanks and be well.
diff --git a/cmd/dnsd/dnsd.service b/cmd/dnsd/dnsd.service
new file mode 100644
index 0000000..73add3d
--- /dev/null
+++ b/cmd/dnsd/dnsd.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=dnsd
+
+[Service]
+Environment=PORT=53
+Environment=FORWARD_SERVER=1.1.1.1:53
+ExecStart=/usr/local/bin/dnsd -zone-file https://host.domain.tld/path/to/your.zone -zone-file https://host.domain.tld/path/to/adblock.zone
+Restart=always
+RestartSec=1s
+
+[Install]
+WantedBy=multi-user.target
diff --git a/cmd/dnsd/main.go b/cmd/dnsd/main.go
index 6e25be8..eefa518 100644
--- a/cmd/dnsd/main.go
+++ b/cmd/dnsd/main.go
@@ -6,11 +6,10 @@ import (
"log"
"net/http"
"os"
- "time"
"os/signal"
"syscall"
+ "time"
- "go.chromium.org/luci/common/flag/stringmapflag"
"github.com/Xe/x/internal"
"github.com/miekg/dns"
"github.com/mmikulicic/stringlist"
@@ -20,8 +19,6 @@ var (
port = flag.String("port", "53", "UDP port to listen on for DNS")
server = flag.String("forward-server", "1.1.1.1:53", "forward DNS server")
- prefixes = new(stringmapflag.Value)
-
zoneURLs = stringlist.Flag("zone-url", "DNS zonefiles to load")
)
@@ -30,10 +27,6 @@ var (
"https://xena.greedo.xeserv.us/files/akua.zone",
"https://xena.greedo.xeserv.us/files/adblock.zone",
}
-
- defaultPrefixes = map[string]string {
- "eq": "10.88.0.1:53",
- }
)
func monitorURLs(urls []string) {
@@ -44,7 +37,7 @@ func monitorURLs(urls []string) {
for {
select {
- case <- t.C:
+ case <-t.C:
for _, urli := range urls {
resp, err := http.Get(urli)
if err != nil {
@@ -67,18 +60,8 @@ func monitorURLs(urls []string) {
}
func main() {
- flag.Var(prefixes, "prefix", "sets prefix=host:port to forward DNS requests to")
internal.HandleStartup()
- if len(*prefixes) == 0 {
- v := stringmapflag.Value(defaultPrefixes)
- prefixes = &v
- }
-
- for k, v := range *prefixes {
- log.Printf("conf: -prefix %s=%s", k, v)
- }
-
if len(*zoneURLs) == 0 {
*zoneURLs = defaultZoneURLS
}