Compare commits

...

2 Commits

Author SHA1 Message Date
85db27cdde added README 2020-12-26 16:45:54 +01:00
8fdb5ac3dd added address to bind to 2020-12-26 14:41:08 +01:00
3 changed files with 40 additions and 5 deletions

32
README.md Normal file
View File

@@ -0,0 +1,32 @@
# Cool dns
A simple dns server written in Go. It supports zonefile parsing, different zones based on IP and forwarding.
# Configuration
Example config file
```yaml
zones:
- zone: example.com. # Fully qualified domain name of the zone
file: zonefile.txt # Path to the zonefile to parse
- zone: example.com.
file: zonefile2.txt
acl: # What IPs can query the zone
- lan
acl: # List of ip filter rules
- name: vpn # Name of the rule
cidr: 10.0.0.0/24 # CIDR of the rule
- name: lan
cidr: 192.168.0.0/16
- name: local
cidr: 127.0.0.1/32
forward:
acl: # What IPs are allowed
- vpn
server: "8.8.8.8:53" # DNS server to forward to
address: 0.0.0.0:8053 # What address and port to listen on
```

View File

@@ -19,3 +19,5 @@ forward:
acl:
- vpn
server: "8.8.8.8:53"
address: 0.0.0.0:8053

View File

@@ -6,7 +6,6 @@ import (
"net"
"os"
"os/signal"
"strconv"
"strings"
"syscall"
@@ -27,6 +26,7 @@ type config struct {
Zones []configZone `yaml:"zones"`
ACL []configACL `yaml:"acl"`
Forward configForward `yaml:"forward"`
Address string `yaml:"address"`
}
type configForward struct {
@@ -211,15 +211,15 @@ func createServer(zones zoneMap, config config, aclList map[string]*net.IPNet) *
return srv
}
func listenAndServer(server *dns.ServeMux) {
func listenAndServer(server *dns.ServeMux, address string) {
go func() {
if err := dns.ListenAndServe(":"+strconv.Itoa(8053), "udp", server); err != nil {
if err := dns.ListenAndServe(address, "udp", server); err != nil {
log.Fatalf("Failed to set udp listener %s\n", err.Error())
}
}()
go func() {
if err := dns.ListenAndServe(":"+strconv.Itoa(8053), "tcp", server); err != nil {
if err := dns.ListenAndServe(address, "tcp", server); err != nil {
log.Fatalf("Failed to set tcp listener %s\n", err.Error())
}
}()
@@ -341,5 +341,6 @@ func main() {
server := createServer(zones, *config, aclList)
listenAndServer(server)
log.Printf("Start listening on udp %s and tcp %s\n", config.Address, config.Address)
listenAndServer(server, config.Address)
}