From 448b106c0edb7e28527f663b39f7c7518ffcc920 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Mon, 15 Aug 2022 20:39:42 +0800 Subject: [PATCH] feat: setting up dns server --- src/config.go | 1 - src/main.go | 3 ++- src/network.go | 23 +++++++++++++++++++++++ test.yml | 1 - 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/network.go diff --git a/src/config.go b/src/config.go index 8f108e1..2e0acda 100644 --- a/src/config.go +++ b/src/config.go @@ -20,7 +20,6 @@ var v6Address string type NetConfig struct { Gateway string `yaml:"gateway"` // network gateway Address string `yaml:"address"` // network address - Forward bool `yaml:"forward"` // enabled net forward } type Config struct { diff --git a/src/main.go b/src/main.go index 41cc999..2567365 100644 --- a/src/main.go +++ b/src/main.go @@ -24,5 +24,6 @@ func main() { panic(err) } loadConfig(content) - loadProxy("/etc/xproxy/config", "/xproxy") + //loadProxy("/etc/xproxy/config", "/xproxy") + loadDns() } diff --git a/src/network.go b/src/network.go new file mode 100644 index 0000000..b3a2166 --- /dev/null +++ b/src/network.go @@ -0,0 +1,23 @@ +package main + +import ( + log "github.com/sirupsen/logrus" + "os" +) + +func loadDns() { + if len(dnsServer) == 0 { + log.Info("Using system DNS server") + return + } + log.Infof("Setting up DNS server -> %v", dnsServer) + dnsContent := "" + for _, address := range dnsServer { + dnsContent += "nameserver " + address + "\n" + } + err := os.WriteFile("/etc/resolv.conf", []byte(dnsContent), 0644) + if err != nil { + log.Error("Setting up DNS failed") + panic("Setting up DNS failed") + } +} diff --git a/test.yml b/test.yml index 4312605..7e25170 100644 --- a/test.yml +++ b/test.yml @@ -22,7 +22,6 @@ network: ipv4: gateway: 192.168.2.1 address: 192.168.2.2/24 - forward: true ipv6: null bypass: - 169.254.0.0/16