-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
29 lines (23 loc) · 771 Bytes
/
Copy pathmain.go
File metadata and controls
29 lines (23 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// main.go
package main
import (
"flag"
"fmt"
"log"
"github.com/akiyomov/dns-proxy-go/resolver"
"github.com/miekg/dns"
)
func main() {
port := flag.String("port", "53", "Port to run the DNS server on")
blocklistPath := flag.String("blocklist", "./config/blocklist.txt", "Path to the blocklist file")
upstream := flag.String("upstream", "1.1.1.1:53", "Upstream DNS server address")
flag.Parse()
proxy := resolver.NewDNSProxy(*upstream, *blocklistPath)
address := fmt.Sprintf(":%s", *port)
server := &dns.Server{Addr: address, Net: "udp"}
server.Handler = dns.HandlerFunc(proxy.HandleDNSRequest)
log.Printf("Starting DNS proxy on %s...", address)
if err := server.ListenAndServe(); err != nil {
log.Fatalf("Failed to start DNS server: %v", err)
}
}