diff --git a/config.json b/config.json index 041ea60..73d3364 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,5 @@ { "ListenAddress": "127.0.0.1:3128", - "ListenType": "tcp4" + "ListenType": "tcp4", + "DNSResolver": "192.168.1.1:53" } diff --git a/internal/conf/config.go b/internal/conf/config.go index f29d153..76d217d 100644 --- a/internal/conf/config.go +++ b/internal/conf/config.go @@ -4,4 +4,5 @@ type Config struct { ListenAddress string // Address to listen on, passed to net.Listen ListenType string // Type of network to listen on, passed to net.Listen. One of tcp, tcp4 and tcp6 + DNSResolver string // Address to send UDP & TCP DNS requests to. If set, the Go resolver will also be forced. } diff --git a/main.go b/main.go index f778286..1e09096 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "context" "encoding/json" "fmt" "log" @@ -8,6 +9,7 @@ import ( "os" "os/signal" "syscall" + "time" "edgaru089.ink/go/regolith/internal/conf" "edgaru089.ink/go/regolith/internal/http" @@ -44,6 +46,16 @@ func main() { } } + if len(conf.DNSResolver) != 0 { + dialer := &net.Dialer{ + Timeout: time.Second * 10, + } + net.DefaultResolver.PreferGo = true + net.DefaultResolver.Dial = func(ctx context.Context, network, address string) (net.Conn, error) { + return dialer.Dial(network, conf.DNSResolver) + } + } + listener, err := net.Listen(conf.ListenType, conf.ListenAddress) if err != nil { panic(err)