added address to bind to

This commit is contained in:
Niklas 2020-12-26 14:41:08 +01:00
parent 7d0e8e4b0d
commit 8fdb5ac3dd
2 changed files with 8 additions and 5 deletions

View File

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

View File

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