diff --git a/config.yml b/config.yml index aa5f263..7ea1414 100644 --- a/config.yml +++ b/config.yml @@ -19,3 +19,5 @@ forward: acl: - vpn server: "8.8.8.8:53" + +address: 0.0.0.0:8053 \ No newline at end of file diff --git a/coolDns.go b/coolDns.go index 92971e3..28f8392 100644 --- a/coolDns.go +++ b/coolDns.go @@ -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) }