Repository: mageddo/dns-proxy-server
Pull request #409 (2023-04-05 04:24:22)

Option to not comment out existing nameservers from resolv.conf
Relates to #386


Patch:
diff --git a/.gitignore b/.gitignore
index 4b91c22f..7c0d93fa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -65,7 +65,7 @@ node_modules
 .env.test.local
 .env.production.local
 runjar.bat
-conf/config.json
+conf
 examples/tmp
 issues
 /files
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 2ffc0371..97fffa68 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -9,6 +9,7 @@ for more details
 * Cache improvement for a concurrent approach synchronized by key
 * Increasing tcp and udp server parallelism from 20 to 50 threads each, threads are created lazilly
 * Fixing solver NPE on unsupported query types
+* Option to not comment out existing nameservers from resolv.conf [see the docs](http://mageddo.github.io/dns-proxy-server/3.15/en/3-configuration/)
 
 ## 3.14.5
 * Specify minimum required docker api version `1.21` (as DPS 2)
diff --git a/docs/content/3-configuration/_index.en.md b/docs/content/3-configuration/_index.en.md
index ce531421..3f9f36d1 100755
--- a/docs/content/3-configuration/_index.en.md
+++ b/docs/content/3-configuration/_index.en.md
@@ -42,7 +42,8 @@ __Version 2__
   "defaultDns" : true, // if must be set as the default DNS
   "hostMachineHostname" : "host.docker", // hostname to solve machine IP
   "serverProtocol" : "UDP_TCP", // protocol to start the dns server
-  "dockerHost" : null, // docker host address, default value is SO dependent
+  "dockerHost" : null, // docker host address, default value is SO dependent,
+  "resolvConfOverrideNameServers": true // If must comment all existing nameservers at resolv.conf file or just put DPS at the first place.
 }
 ```
 
@@ -51,17 +52,18 @@ __Version 2__
 Boolean values
 
 > You can use `1` or `true` (case insensitive) to specify which the flag is activated, any other
-value will be considered false.
+> value will be considered false.
 
-| VARIBLE                     | DESCRIPTION                                                           | DEFAULT VALUE                                                                                     |
-|-----------------------------|-----------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
-| MG_RESOLVCONF               | Linux resolvconf or systemd-resolved path to set DPS as default DNS   | /host/etc/systemd/resolved.conf,/host/etc/resolv.conf,/etc/systemd/resolved.conf,/etc/resolv.conf |
-| MG_LOG_LEVEL                |                                                                       | INFO                                                                                              |
-| MG_LOG_FILE                 | Path where to logs will be stored                                     | console                                                                                           |
-| MG_REGISTER_CONTAINER_NAMES | if should register container name / service name as a hostname        | false                                                                                             |
-| MG_HOST_MACHINE_HOSTNAME    | hostname to solve host machine IP                                     | host.docker                                                                                       |
-| MG_DOMAIN                   | The container names domain (requires MG_REGISTER_CONTINER_NAMES=TRUE) | .docker                                                                                           |
-| MG_DOCKER_HOST              | Docker host address                                                   | depends on the SO                                                                                 |
+| VARIBLE                            | DESCRIPTION                                                                                      | DEFAULT VALUE                                                                                     |
+|------------------------------------|--------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
+| MG_RESOLVCONF                      | Linux resolvconf or systemd-resolved path to set DPS as default DNS                              | /host/etc/systemd/resolved.conf,/host/etc/resolv.conf,/etc/systemd/resolved.conf,/etc/resolv.conf |
+| MG_LOG_LEVEL                       |                                                                                                  | INFO                                                                                              |
+| MG_LOG_FILE                        | Path where to logs will be stored                                                                | console                                                                                           |
+| MG_REGISTER_CONTAINER_NAMES        | if should register container name / service name as a hostname                                   | false                                                                                             |
+| MG_HOST_MACHINE_HOSTNAME           | hostname to solve host machine IP                                                                | host.docker                                                                                       |
+| MG_DOMAIN                          | The container names domain (requires MG_REGISTER_CONTINER_NAMES=TRUE)                            | .docker                                                                                           |
+| MG_DOCKER_HOST                     | Docker host address                                                                              | depends on the SO                                                                                 |
+| MG_RESOLVCONF_OVERRIDE_NAMESERVERS | If must comment all existing nameservers at resolv.conf file or just put DPS at the first place. | true                                                                                              |
 
 ### Terminal configuration
 Run one of the commands below to get the commandline instructions help:
diff --git a/gradle.properties b/gradle.properties
index aaee2625..88a28d14 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,1 +1,1 @@
-version=3.15.9-snapshot
+version=3.15.10-snapshot
diff --git a/src/main/java/com/mageddo/dnsproxyserver/config/Config.java b/src/main/java/com/mageddo/dnsproxyserver/config/Config.java
index b1c240d4..1100ee42 100644
--- a/src/main/java/com/mageddo/dnsproxyserver/config/Config.java
+++ b/src/main/java/com/mageddo/dnsproxyserver/config/Config.java
@@ -83,6 +83,8 @@ public class Config {
 
   private URI dockerHost;
 
+  private boolean resolvConfOverrideNameServers;
+
   public void resetConfigFile() {
     try {
       Files.deleteIfExists(this.getConfigPath());
diff --git a/src/main/java/com/mageddo/dnsproxyserver/config/Configs.java b/src/main/java/com/mageddo/dnsproxyserver/config/Configs.java
index 7d5c934e..d0c36f5d 100644
--- a/src/main/java/com/mageddo/dnsproxyserver/config/Configs.java
+++ b/src/main/java/com/mageddo/dnsproxyserver/config/Configs.java
@@ -65,6 +65,9 @@ public class Configs {
       .dockerHost(ObjectUtils.firstNonNull(
         flag.getDockerHost(), env.getDockerHost(), json.getDockerHost(), buildDefaultDockerHost()
       ))
+      .resolvConfOverrideNameServers(firstNonNullRequiring(
+        env.getResolvConfOverrideNameServers(), json.getResolvConfOverrideNameServers(), flag.getResolvConfOverrideNameServers()
+      ))
       .build();
   }
 
diff --git a/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigEnv.java b/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigEnv.java
index 54abc8cb..de0a2f2e 100644
--- a/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigEnv.java
+++ b/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigEnv.java
@@ -31,6 +31,7 @@ public class ConfigEnv {
   public static final String DEFAULT_RESOLV_CONF_PATH =
     "/host/etc/systemd/resolved.conf,/host/etc/resolv.conf,/etc/systemd/resolved.conf,/etc/resolv.conf";
   public static final String MG_DOCKER_HOST = "MG_DOCKER_HOST";
+  public static final String MG_RESOLVCONF_OVERRIDE_NAMESERVERS = "MG_RESOLVCONF_OVERRIDE_NAMESERVERS";
 
   private Path currentPath;
   private String resolvConfPath;
@@ -42,6 +43,7 @@ public class ConfigEnv {
   private Boolean dpsNetwork;
   private Boolean dpsNetworkAutoConnect;
   private URI dockerHost;
+  private Boolean resolvConfOverrideNameServers;
 
   public static ConfigEnv fromEnv() {
     return ConfigEnv
@@ -56,6 +58,7 @@ public class ConfigEnv {
       .dpsNetwork(Envs.getBooleanOrNull(MG_DPS_NETWORK))
       .dpsNetworkAutoConnect(Envs.getBooleanOrNull(MG_DPS_NETWORK_AUTO_CONNECT))
       .dockerHost(UriUtils.createURI(Envs.getStringOrNull(MG_DOCKER_HOST)))
+      .resolvConfOverrideNameServers(Envs.getBooleanOrNull(MG_RESOLVCONF_OVERRIDE_NAMESERVERS))
       .build();
   }
 
@@ -66,4 +69,5 @@ public class ConfigEnv {
     }
     return logFile;
   }
+
 }
diff --git a/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigFlag.java b/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigFlag.java
index a0c4f180..8c36eddf 100644
--- a/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigFlag.java
+++ b/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigFlag.java
@@ -114,7 +114,6 @@ public class ConfigFlag implements Callable<Boolean> {
   )
   private Boolean dpsNetwork;
 
-
   @Option(
     names = {"-dps-network-auto-connect", "--dps-network-auto-connect"},
     description = """
@@ -135,6 +134,16 @@ public class ConfigFlag implements Callable<Boolean> {
   )
   private URI dockerHost;
 
+  @Option(
+    names = {"-resolvconf-override-name-servers", "--resolvconf-override-name-servers"},
+    description = """
+      If must comment all existing nameservers at resolv.conf file or just put DPS at the first place.
+      (default true)
+       """,
+    defaultValue = "true"
+  )
+  private Boolean resolvConfOverrideNameServers;
+
   @Option(
     names = {"-help", "--help"},
     description = "This message (default false)",
@@ -186,4 +195,5 @@ public class ConfigFlag implements Callable<Boolean> {
     }
     return false;
   }
+
 }
diff --git a/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigJson.java b/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigJson.java
index 8038d176..6637ff87 100644
--- a/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigJson.java
+++ b/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigJson.java
@@ -38,4 +38,6 @@ public interface ConfigJson {
   SimpleServer.Protocol getServerProtocol();
 
   URI getDockerHost();
+
+  Boolean getResolvConfOverrideNameServers();
 }
diff --git a/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigJsonV1.java b/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigJsonV1.java
index 7f1241a3..3d72e13f 100644
--- a/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigJsonV1.java
+++ b/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigJsonV1.java
@@ -82,6 +82,11 @@ public class ConfigJsonV1 implements ConfigJson {
     return null;
   }
 
+  @Override
+  public Boolean getResolvConfOverrideNameServers() {
+    return null;
+  }
+
   public ConfigJsonV2 toConfigV2() {
     return new ConfigJsonV2()
       .setDomain(this.getDomain())
diff --git a/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigJsonV2.java b/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigJsonV2.java
index 4f848eb0..2c5d008e 100644
--- a/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigJsonV2.java
+++ b/src/main/java/com/mageddo/dnsproxyserver/config/entrypoint/ConfigJsonV2.java
@@ -53,6 +53,8 @@ public class ConfigJsonV2 implements ConfigJson {
 
   private URI dockerHost;
 
+  private Boolean resolvConfOverrideNameServers;
+
   @JsonIgnore
   public List<IpAddr> getRemoteDnsServers() {
     return this.remoteDnsServers
diff --git a/src/main/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/ConfigureDPSHandler.java b/src/main/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/ConfigureDPSHandler.java
index a448e3e6..cccff435 100644
--- a/src/main/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/ConfigureDPSHandler.java
+++ b/src/main/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/ConfigureDPSHandler.java
@@ -2,8 +2,6 @@ package com.mageddo.dnsproxyserver.dnsconfigurator.linux;
 
 import com.mageddo.conf.parser.Entry;
 import com.mageddo.conf.parser.Transformer;
-import com.mageddo.dnsproxyserver.dnsconfigurator.linux.DpsTokens;
-import com.mageddo.dnsproxyserver.dnsconfigurator.linux.EntryTypes;
 
 import java.util.Set;
 import java.util.function.Supplier;
diff --git a/src/main/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/DnsConfiguratorLinux.java b/src/main/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/DnsConfiguratorLinux.java
index cdef7e09..f492f9ab 100644
--- a/src/main/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/DnsConfiguratorLinux.java
+++ b/src/main/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/DnsConfiguratorLinux.java
@@ -4,8 +4,8 @@ import com.mageddo.commons.lang.Objects;
 import com.mageddo.dnsproxyserver.config.Configs;
 import com.mageddo.dnsproxyserver.dnsconfigurator.DnsConfigurator;
 import com.mageddo.dnsproxyserver.dnsconfigurator.linux.ResolvFile.Type;
-import com.mageddo.net.IpAddr;
 import com.mageddo.dnsproxyserver.systemd.ResolvedService;
+import com.mageddo.net.IpAddr;
 import com.mageddo.utils.Tests;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -42,8 +42,13 @@ public class DnsConfiguratorLinux implements DnsConfigurator {
     }
 
     final var confFile = this.getConfFile();
+
     if (confFile.isResolvconf()) {
-      ResolvconfConfigurator.process(confFile.getPath(), addr);
+      final var overrideNameServers = Configs
+        .getInstance()
+        .isResolvConfOverrideNameServers()
+        ;
+      ResolvconfConfigurator.process(confFile.getPath(), addr, overrideNameServers);
     } else if (confFile.isResolved()) {
       this.configureResolved(addr, confFile);
     } else {
diff --git a/src/main/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/ResolvconfConfigurator.java b/src/main/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/ResolvconfConfigurator.java
index fdfce5f7..b591bb06 100644
--- a/src/main/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/ResolvconfConfigurator.java
+++ b/src/main/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/ResolvconfConfigurator.java
@@ -2,8 +2,8 @@ package com.mageddo.dnsproxyserver.dnsconfigurator.linux;
 
 import com.mageddo.conf.parser.ConfParser;
 import com.mageddo.conf.parser.EntryType;
-import com.mageddo.net.IpAddr;
 import com.mageddo.dnsproxyserver.utils.Dns;
+import com.mageddo.net.IpAddr;
 
 import java.nio.file.Path;
 import java.util.function.Function;
@@ -11,13 +11,20 @@ import java.util.function.Function;
 public class ResolvconfConfigurator {
 
   public static void process(Path confFile, IpAddr addr) {
+    process(confFile, addr, true);
+  }
+
+  public static void process(Path confFile, IpAddr addr, boolean overrideNameServers) {
 
     Dns.validateIsDefaultPort(addr);
 
     ConfParser.process(
         confFile,
         createParser(),
-        new ConfigureDPSHandler(() -> String.format("nameserver %s # dps-entry", addr.getIp().toText()))
+        new ResolvconfConfigureDPSHandler(
+          () -> String.format("nameserver %s # dps-entry", addr.getIp().toText()),
+          overrideNameServers
+        )
     );
   }
 
diff --git a/src/main/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/ResolvconfConfigureDPSHandler.java b/src/main/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/ResolvconfConfigureDPSHandler.java
new file mode 100644
index 00000000..5918ae7c
--- /dev/null
+++ b/src/main/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/ResolvconfConfigureDPSHandler.java
@@ -0,0 +1,57 @@
+package com.mageddo.dnsproxyserver.dnsconfigurator.linux;
+
+import com.mageddo.conf.parser.Entry;
+import com.mageddo.conf.parser.Transformer;
+
+import java.util.Set;
+import java.util.function.Supplier;
+
+public class ResolvconfConfigureDPSHandler implements Transformer {
+
+  private final Supplier<String> dpsDnsLineBuilder;
+  private final boolean overrideNameServers;
+  private boolean dpsSet = false;
+
+  public ResolvconfConfigureDPSHandler(Supplier<String> dpsDnsLineBuilder, boolean overrideNameServers) {
+    this.dpsDnsLineBuilder = dpsDnsLineBuilder;
+    this.overrideNameServers = overrideNameServers;
+  }
+
+  @Override
+  public String handle(Entry entry) {
+    return switch (entry.getType().name()) {
+      case EntryTypes.DPS_SERVER -> {
+        this.dpsSet = true;
+        yield this.dpsDnsLineBuilder.get();
+      }
+      case EntryTypes.SERVER -> {
+        if (!this.overrideNameServers) {
+          if (!this.dpsSet) {
+            this.dpsSet = true;
+            yield String.format("%s%n%s", this.dpsDnsLineBuilder.get(), entry.getLine());
+          }
+          yield entry.getLine();
+        }
+        yield DpsTokens.comment(entry.getLine());
+      }
+      default -> entry.getLine();
+    };
+  }
+
+  @Override
+  public String after(boolean fileHasContent, Set<String> foundEntryTypes) {
+    if (
+      !fileHasContent
+        || (!has(foundEntryTypes, EntryTypes.DPS_SERVER) && this.overrideNameServers)
+        || (!has(foundEntryTypes, EntryTypes.DPS_SERVER) && !has(foundEntryTypes, EntryTypes.SERVER) && !this.overrideNameServers)
+    ) {
+      return this.dpsDnsLineBuilder.get();
+    }
+    return null;
+  }
+
+  private static boolean has(Set<String> foundEntryTypes, final String type) {
+    return foundEntryTypes.contains(type);
+  }
+
+}


Test patch:
diff --git a/src/test/java/com/mageddo/dnsproxyserver/config/ConfigsTest.java b/src/test/java/com/mageddo/dnsproxyserver/config/ConfigsTest.java
index 66b80d48..8ffc5eaf 100644
--- a/src/test/java/com/mageddo/dnsproxyserver/config/ConfigsTest.java
+++ b/src/test/java/com/mageddo/dnsproxyserver/config/ConfigsTest.java
@@ -36,9 +36,9 @@ class ConfigsTest {
   void mustParseDefaultConfigsAndCreateConfigFile(@TempDir Path tmpDir) {
 
     // arrange
-    final var tmpConfigFile = tmpDir.resolve("tmpfile.json");
-    final var args = new String[]{"--conf-path", tmpConfigFile.toString()};
-    assertFalse(Files.exists(tmpConfigFile));
+    final var jsonConfigFile = tmpDir.resolve("tmpfile.json");
+    final var args = new String[]{"--conf-path", jsonConfigFile.toString()};
+    assertFalse(Files.exists(jsonConfigFile));
 
     // act
     final var config = Configs.build(args);
@@ -48,8 +48,8 @@ class ConfigsTest {
       readAndSortJsonExcluding("/configs-test/001.json", excludingFields),
       readAndSortJsonExcluding(config, excludingFields)
     );
-    assertTrue(Files.exists(tmpConfigFile));
-    assertEquals(readAndSortJson("/configs-test/002.json"), readAndSortJson(tmpConfigFile));
+    assertTrue(Files.exists(jsonConfigFile));
+    assertEquals(readAndSortJson("/configs-test/002.json"), readAndSortJson(jsonConfigFile));
   }
 
 
diff --git a/src/test/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/ResolvconfConfiguratorTest.java b/src/test/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/ResolvconfConfiguratorTest.java
index 19aa3172..465a308d 100644
--- a/src/test/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/ResolvconfConfiguratorTest.java
+++ b/src/test/java/com/mageddo/dnsproxyserver/dnsconfigurator/linux/ResolvconfConfiguratorTest.java
@@ -79,7 +79,7 @@ class ResolvconfConfiguratorTest {
   @Test
   void mustRestoreOriginalResolvconf(@TempDir Path tmpDir) throws Exception {
 
-    // arrrange
+    // arrange
     final var resolvFile = tmpDir.resolve("resolv.conf");
 
     Files.writeString(resolvFile, """
@@ -121,4 +121,66 @@ class ResolvconfConfiguratorTest {
     assertTrue(msg.contains("requires dns server port to"), msg);
 
   }
+
+  @Test
+  void mustNotCommentFollowingNameServersWhenNameserversOverrideIsDisabled(@TempDir Path tmpDir) throws Exception {
+
+    // arrange
+    final var resolvFile = tmpDir.resolve("resolv.conf");
+    final var ip = IpAddrTemplates.local();
+
+    Files.writeString(resolvFile, """
+      # Provided by test
+      nameserver 7.7.7.7
+      # nameserver 8.8.8.8
+      nameserver 8.8.4.4
+      """);
+
+    // act
+    ResolvconfConfigurator.process(resolvFile, ip, false);
+
+    // assert
+    assertEquals(
+      """
+        # Provided by test
+        nameserver 10.10.0.1 # dps-entry
+        nameserver 7.7.7.7
+        # nameserver 8.8.8.8
+        nameserver 8.8.4.4
+        """,
+      Files.readString(resolvFile)
+    );
+  }
+
+
+  @Test
+  void mustCreateExactlyOneDpsEntryWhenNameserversOverrideIsDisabled(@TempDir Path tmpDir) throws Exception {
+
+    // arrange
+    final var resolvFile = tmpDir.resolve("resolv.conf");
+    final var ip = IpAddrTemplates.local();
+
+    Files.writeString(resolvFile, """
+      # Provided by test
+      nameserver 7.7.7.7
+      # nameserver 8.8.8.8
+      nameserver 8.8.4.4
+      """);
+
+    // act
+    ResolvconfConfigurator.process(resolvFile, ip, false);
+    ResolvconfConfigurator.process(resolvFile, ip, false);
+
+    // assert
+    assertEquals(
+      """
+        # Provided by test
+        nameserver 10.10.0.1 # dps-entry
+        nameserver 7.7.7.7
+        # nameserver 8.8.8.8
+        nameserver 8.8.4.4
+        """,
+      Files.readString(resolvFile)
+    );
+  }
 }
diff --git a/src/test/resources/config-json-v1-test/002.json b/src/test/resources/config-json-v1-test/002.json
index 401cbd47..8ce00c35 100644
--- a/src/test/resources/config-json-v1-test/002.json
+++ b/src/test/resources/config-json-v1-test/002.json
@@ -23,6 +23,7 @@
   "registerContainerNames" : false,
   "remoteDnsServers" : [ "8.8.8.8", "4.4.4.4" ],
   "version" : 2,
+  "resolvConfOverrideNameServers" : null,
   "serverProtocol" : null,
   "webServerPort" : 0
 }
diff --git a/src/test/resources/configs-test/001.json b/src/test/resources/configs-test/001.json
index d4bc5f18..afc8b827 100644
--- a/src/test/resources/configs-test/001.json
+++ b/src/test/resources/configs-test/001.json
@@ -13,6 +13,7 @@
     "port" : 53,
     "rawIP" : "8.8.8.8"
   } ],
+  "resolvConfOverrideNameServers" : true,
   "serverProtocol" : "UDP_TCP",
   "webServerPort" : 5380
 }
diff --git a/src/test/resources/configs-test/002.json b/src/test/resources/configs-test/002.json
index 5517106e..f6e57b25 100644
--- a/src/test/resources/configs-test/002.json
+++ b/src/test/resources/configs-test/002.json
@@ -23,6 +23,7 @@
   "registerContainerNames" : null,
   "remoteDnsServers" : [ ],
   "version" : 2,
+  "resolvConfOverrideNameServers" : null,
   "serverProtocol" : null,
   "webServerPort" : null
 }
diff --git a/src/test/resources/configs-test/004.json b/src/test/resources/configs-test/004.json
index e61ae17e..d2fa674e 100644
--- a/src/test/resources/configs-test/004.json
+++ b/src/test/resources/configs-test/004.json
@@ -13,6 +13,7 @@
     "port" : 53,
     "rawIP" : "8.8.8.8"
   } ],
+  "resolvConfOverrideNameServers" : true,
   "serverProtocol" : "UDP_TCP",
   "webServerPort" : 9393
 }
diff --git a/src/test/resources/flags-test/001.json b/src/test/resources/flags-test/001.json
index 559dad1c..03c2be25 100644
--- a/src/test/resources/flags-test/001.json
+++ b/src/test/resources/flags-test/001.json
@@ -14,5 +14,6 @@
   "domain" : "docker",
   "dpsNetwork" : false,
   "dpsNetworkAutoConnect" : false,
-  "help" : null
+  "help" : null,
+  "resolvConfOverrideNameServers" : true
 }
diff --git a/src/test/resources/flags-test/002.txt b/src/test/resources/flags-test/002.txt
index 2dd020e8..4bbb387e 100644
--- a/src/test/resources/flags-test/002.txt
+++ b/src/test/resources/flags-test/002.txt
@@ -1,8 +1,8 @@
 Usage: <main class> [-default-dns] [-dps-network] [-dps-network-auto-connect] [-help] [-register-container-names]
-                    [-service-publish-web-port] [-version] [-conf-path=<configPath>] [-docker-host=<dockerHost>]
-                    [-domain=<domain>] [-host-machine-hostname=<hostMachineHostname>] [-log-file=<logToFile>]
-                    [-log-level=<logLevel>] [-server-port=<dnsServerPort>] [-service=<service>]
-                    [-web-server-port=<webServerPort>]
+                    [-resolvconf-override-name-servers] [-service-publish-web-port] [-version]
+                    [-conf-path=<configPath>] [-docker-host=<dockerHost>] [-domain=<domain>]
+                    [-host-machine-hostname=<hostMachineHostname>] [-log-file=<logToFile>] [-log-level=<logLevel>]
+                    [-server-port=<dnsServerPort>] [-service=<service>] [-web-server-port=<webServerPort>]
       -conf-path, --conf-path=<configPath>
                             The config file path (default conf/config.json)
       -default-dns, --default-dns
@@ -32,6 +32,11 @@ Usage: <main class> [-default-dns] [-dps-network] [-dps-network-auto-connect] [-
                             Log Level ERROR, WARNING, INFO, DEBUG (default INFO)
       -register-container-names, --register-container-names
                             If must register container name / service name as host in DNS server (default false)
+      -resolvconf-override-name-servers, --resolvconf-override-name-servers
+                            If must comment all existing nameservers at resolv.conf file or just put DPS at the first
+                              place.
+                            (default true)
+
       -server-port, --server-port=<dnsServerPort>
                             The DNS server to start into (default 53)
       -service, --service=<service>
diff --git a/src/test/resources/json-configs-test/001.json b/src/test/resources/json-configs-test/001.json
index 762477d8..810960e8 100644
--- a/src/test/resources/json-configs-test/001.json
+++ b/src/test/resources/json-configs-test/001.json
@@ -30,6 +30,7 @@
     "4.4.4.4"
   ],
   "version": 2,
+  "resolvConfOverrideNameServers" : null,
   "serverProtocol" : null,
   "webServerPort": 0
 }