Bug fix: truncate /etc/resolv.conf, fixing DNS

- Refers to #326
- Refers to #329
This commit is contained in:
Quentin McGaw
2020-12-30 20:48:41 +00:00
parent 1e4243dedb
commit f385c4203a
2 changed files with 7 additions and 7 deletions

View File

@@ -26,7 +26,7 @@ func (c *configurator) UseDNSInternally(ip net.IP) {
func (c *configurator) UseDNSSystemWide(ip net.IP, keepNameserver bool) error {
c.logger.Info("using DNS address %s system wide", ip.String())
const filepath = string(constants.ResolvConf)
file, err := c.openFile(filepath, os.O_RDWR, 0644)
file, err := c.openFile(filepath, os.O_RDWR|os.O_TRUNC, 0644)
if err != nil {
return err
}
@@ -52,7 +52,7 @@ func (c *configurator) UseDNSSystemWide(ip net.IP, keepNameserver bool) error {
if !found {
lines = append(lines, "nameserver "+ip.String())
}
s = strings.Join(lines, "\n")
s = strings.Join(lines, "\n") + "\n"
_, err = file.WriteString(s)
if err != nil {
_ = file.Close()