Skip to content

Commit

Permalink
Fix Docker instructions and add option to bind both UDP and TCP DNS l…
Browse files Browse the repository at this point in the history
…isteners (#130)
  • Loading branch information
joohoi committed Dec 13, 2018
1 parent 20411b6 commit f64de03
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 12 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ RUN apk --no-cache add ca-certificates && update-ca-certificates
VOLUME ["/etc/acme-dns", "/var/lib/acme-dns"]
ENTRYPOINT ["./acme-dns"]
EXPOSE 53 80 443
EXPOSE 53/udp
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ See the INSTALL section for information on how to do this.
```
docker run --rm --name acmedns \
-p 53:53 \
-p 53:53/udp \
-p 80:80 \
-v /path/to/your/config:/etc/acme-dns:ro \
-v /path/to/your/data:/var/lib/acme-dns \
Expand Down Expand Up @@ -216,8 +217,8 @@ $ dig @auth.example.org d420c923-bbd7-4056-ab64-c3ca54c9b3cf.auth.example.org
# In this case acme-dns will error out and you will need to define the listening interface
# for example: listen = "127.0.0.1:53"
listen = ":53"
# protocol, "udp", "udp4", "udp6" or "tcp", "tcp4", "tcp6"
protocol = "udp"
# protocol, "both", "both4", "both6", "udp", "udp4", "udp6" or "tcp", "tcp4", "tcp6"
protocol = "both"
# domain name to serve the requests off of
domain = "auth.example.org"
# zone name server
Expand Down Expand Up @@ -300,6 +301,10 @@ logformat = "text"


## Changelog

- master
- Changed
- A new protocol selection for DNS server "both", that binds both - UDP and TCP ports.
- v0.6
- New
- Command line flag `-c` to specify location of config file.
Expand Down
9 changes: 5 additions & 4 deletions config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# DNS interface. Note that systemd-resolved may reserve port 53 on 127.0.0.53
# In this case acme-dns will error out and you will need to define the listening interface
# for example: listen = "127.0.0.1:53"
listen = ":53"
# protocol, "udp", "udp4", "udp6" or "tcp", "tcp4", "tcp6"
protocol = "udp"
listen = "127.0.0.1:53"
# protocol, "both", "both4", "both6", "udp", "udp4", "udp6" or "tcp", "tcp4", "tcp6"
protocol = "both"
# domain name to serve the requests off of
domain = "auth.example.org"
# zone name server
Expand All @@ -26,7 +26,8 @@ debug = false
engine = "sqlite3"
# Connection string, filename for sqlite3 and postgres:https://$username:$password@$host/$db_name for postgres
# Please note that the default Docker image uses path /var/lib/acme-dns/acme-dns.db for sqlite3
connection = "/var/lib/acme-dns/acme-dns.db"
#connection = "/var/lib/acme-dns/acme-dns.db"
connection = "acme-dns.db"
# connection = "postgres:https://user:password@localhost/acmedns_db"

[api]
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
ports:
- "443:443"
- "53:53"
- "53:53/udp"
- "80:80"
volumes:
- ./config:/etc/acme-dns:ro
Expand Down
28 changes: 23 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
stdlog "log"
"net/http"
"os"
"strings"
"syscall"

"github.com/julienschmidt/httprouter"
Expand Down Expand Up @@ -60,8 +61,25 @@ func main() {
errChan := make(chan error, 1)

// DNS server
dnsServer := setupDNSServer()
go startDNS(dnsServer, errChan)
if strings.HasPrefix(Config.General.Proto, "both") {
// Handle the case where DNS server should be started for both udp and tcp
udpProto := "udp"
tcpProto := "tcp"
if strings.HasSuffix(Config.General.Proto, "4") {
udpProto += "4"
tcpProto += "4"
} else if strings.HasSuffix(Config.General.Proto, "6") {
udpProto += "6"
tcpProto += "6"
}
dnsServerUDP := setupDNSServer(udpProto)
dnsServerTCP := setupDNSServer(tcpProto)
go startDNS(dnsServerUDP, errChan)
go startDNS(dnsServerTCP, errChan)
} else {
dnsServer := setupDNSServer(Config.General.Proto)
go startDNS(dnsServer, errChan)
}

// HTTP API
go startHTTPAPI(errChan)
Expand All @@ -79,15 +97,15 @@ func main() {
func startDNS(server *dns.Server, errChan chan error) {
// DNS server part
dns.HandleFunc(".", handleRequest)
log.WithFields(log.Fields{"addr": Config.General.Listen}).Info("Listening DNS")
log.WithFields(log.Fields{"addr": Config.General.Listen, "proto": server.Net}).Info("Listening DNS")
err := server.ListenAndServe()
if err != nil {
errChan <- err
}
}

func setupDNSServer() *dns.Server {
return &dns.Server{Addr: Config.General.Listen, Net: Config.General.Proto}
func setupDNSServer(proto string) *dns.Server {
return &dns.Server{Addr: Config.General.Listen, Net: proto}
}

func startHTTPAPI(errChan chan error) {
Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestMain(m *testing.M) {
_ = newDb.Init("sqlite3", ":memory:")
}
DB = newDb
server := setupDNSServer()
server := setupDNSServer("udp")
// Make sure that we're not creating a race condition in tests
var wg sync.WaitGroup
wg.Add(1)
Expand Down

0 comments on commit f64de03

Please sign in to comment.