How to setup DNS manually on Linux?












-1















In Linux /etc/resolv.conf get often overwritten when we setup the DNS, because of the multitude of programs managing the DNS servers.



How to properly setup the DNS ?










share|improve this question



























    -1















    In Linux /etc/resolv.conf get often overwritten when we setup the DNS, because of the multitude of programs managing the DNS servers.



    How to properly setup the DNS ?










    share|improve this question

























      -1












      -1








      -1


      2






      In Linux /etc/resolv.conf get often overwritten when we setup the DNS, because of the multitude of programs managing the DNS servers.



      How to properly setup the DNS ?










      share|improve this question














      In Linux /etc/resolv.conf get often overwritten when we setup the DNS, because of the multitude of programs managing the DNS servers.



      How to properly setup the DNS ?







      networking configuration dns vpn resolv.conf






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 hours ago









      intikaintika

      1875




      1875






















          1 Answer
          1






          active

          oldest

          votes


















          0














          DNS Config Under Linux



          DNS usage on linux is done over a set of routines in the C library that provide access to the Internet Domain Name System (DNS). The resolver configuration file (resolv.conf) contains information that is read by the resolver routines the first time they are invoked by a process. In short each process requesting DNS will read /etc/resolv.conf over library. The NSS is layered on top of this, and is configured by /etc/nsswitch.conf.



          Linux DNS config are located in the file /etc/resolv.conf BUT there are a number of programs/services that wants to automatically manage and handle the DNS configuration file at /etc/resolv.conf. In some situations you may want to manage this file yourself. Each program/service managing DNS have its own configuration files like /etc/dnsmasq.conf (for dnsmasq service) and append the DNS config at connection change and/or on other events... a quick solution is to lock the DNS config file with chattr +i /etc/resolv.conf but this is not recommended in certain case, a better solution is to setup correctly all the program/services using the DNS like (dnsmasq/network-manager/resolvconf/etc.)



          Getting Back The Control Of DNS



          Here is an exhaustive list of setups to get back the control of resolv.conf and avoid having it overwritten (how to disable/setup DNS from other location other than resolv.conf) note that resolvconf is an independent program from resolv.conf, also depending on your system/config you may not have one or many of the programs listed here.



          1. Resolvconf:



          Config files



          cat /etc/resolvconf/resolv.conf.d/head
          nameserver 8.8.4.4
          cat /etc/resolvconf/resolv.conf.d/base
          nameserver 8.8.4.4


          Update the config



          sudo resolvconf -u


          Disable resolvconf



          systemctl disable --now resolvconf.service 


          2. Dnsmasq Service:



          Config files



          cat /etc/dnsmasq.conf
          server=1.1.1.1
          server=8.8.4.4


          Update the config



          sudo systemctl restart dnsmasq.service


          3. Network Manager:



          Config files



          /etc/NetworkManager/*


          Disable DNS



          $ cat /etc/NetworkManager/conf.d/no-dns.conf
          [main]
          dns=none


          Enable DNS



          $ cat /etc/NetworkManager/conf.d/dns.conf
          [main]
          dns=default

          [global-dns]
          searches=example.com

          [global-dns-domain-*]


          Use resolved service



          $ cat /usr/lib/NetworkManager/conf.d/resolved.conf 
          [main]
          dns=systemd-resolved


          Use resolvconf



          $ cat /usr/lib/NetworkManager/conf.d/resolvconf.conf 
          [main]
          rc-manager=resolvconf


          Update the config



          systemctl restart NetworkManager.service


          4. Network Interfaces:



          Config files



          $ cat /etc/network/interfaces
          #nameservers
          # or dns-search like so
          # dns-search x.y
          dns-nameservers 4.4.4.4 8.8.8.8


          Update The Config



          reboot


          5. DHCP Client:



          Config files



          $ cat /etc/dhcp3/dhclient.conf
          supersede domain-name-servers <dns_ip_address1>,<dns_ip_address2>;


          Update The Config



          reboot


          6. Rdnssd Service:



          Disable rdnssd



          systemctl disable --now rdnssd.service


          7. Resolved Service:



          Disable resolved



          systemctl disable --now systemd-resolved.service


          8. Netconfig:



          Config files



          /etc/sysconfig/network/config


          Disable netconfig



          cat /etc/sysconfig/network/config
          NETCONFIG_DNS_POLICY=""


          Update The Config



          reboot


          Setting The DNS Server



          Example of a /etc/resolv.conf configuration



          #Cloudflare
          nameserver 1.0.0.1

          #Google
          #nameserver 8.8.8.8
          #nameserver 8.8.4.4

          #Cloudflare
          #nameserver 1.1.1.1

          #Classic Config
          #nameserver 192.168.1.1
          #search lan





          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494324%2fhow-to-setup-dns-manually-on-linux%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            DNS Config Under Linux



            DNS usage on linux is done over a set of routines in the C library that provide access to the Internet Domain Name System (DNS). The resolver configuration file (resolv.conf) contains information that is read by the resolver routines the first time they are invoked by a process. In short each process requesting DNS will read /etc/resolv.conf over library. The NSS is layered on top of this, and is configured by /etc/nsswitch.conf.



            Linux DNS config are located in the file /etc/resolv.conf BUT there are a number of programs/services that wants to automatically manage and handle the DNS configuration file at /etc/resolv.conf. In some situations you may want to manage this file yourself. Each program/service managing DNS have its own configuration files like /etc/dnsmasq.conf (for dnsmasq service) and append the DNS config at connection change and/or on other events... a quick solution is to lock the DNS config file with chattr +i /etc/resolv.conf but this is not recommended in certain case, a better solution is to setup correctly all the program/services using the DNS like (dnsmasq/network-manager/resolvconf/etc.)



            Getting Back The Control Of DNS



            Here is an exhaustive list of setups to get back the control of resolv.conf and avoid having it overwritten (how to disable/setup DNS from other location other than resolv.conf) note that resolvconf is an independent program from resolv.conf, also depending on your system/config you may not have one or many of the programs listed here.



            1. Resolvconf:



            Config files



            cat /etc/resolvconf/resolv.conf.d/head
            nameserver 8.8.4.4
            cat /etc/resolvconf/resolv.conf.d/base
            nameserver 8.8.4.4


            Update the config



            sudo resolvconf -u


            Disable resolvconf



            systemctl disable --now resolvconf.service 


            2. Dnsmasq Service:



            Config files



            cat /etc/dnsmasq.conf
            server=1.1.1.1
            server=8.8.4.4


            Update the config



            sudo systemctl restart dnsmasq.service


            3. Network Manager:



            Config files



            /etc/NetworkManager/*


            Disable DNS



            $ cat /etc/NetworkManager/conf.d/no-dns.conf
            [main]
            dns=none


            Enable DNS



            $ cat /etc/NetworkManager/conf.d/dns.conf
            [main]
            dns=default

            [global-dns]
            searches=example.com

            [global-dns-domain-*]


            Use resolved service



            $ cat /usr/lib/NetworkManager/conf.d/resolved.conf 
            [main]
            dns=systemd-resolved


            Use resolvconf



            $ cat /usr/lib/NetworkManager/conf.d/resolvconf.conf 
            [main]
            rc-manager=resolvconf


            Update the config



            systemctl restart NetworkManager.service


            4. Network Interfaces:



            Config files



            $ cat /etc/network/interfaces
            #nameservers
            # or dns-search like so
            # dns-search x.y
            dns-nameservers 4.4.4.4 8.8.8.8


            Update The Config



            reboot


            5. DHCP Client:



            Config files



            $ cat /etc/dhcp3/dhclient.conf
            supersede domain-name-servers <dns_ip_address1>,<dns_ip_address2>;


            Update The Config



            reboot


            6. Rdnssd Service:



            Disable rdnssd



            systemctl disable --now rdnssd.service


            7. Resolved Service:



            Disable resolved



            systemctl disable --now systemd-resolved.service


            8. Netconfig:



            Config files



            /etc/sysconfig/network/config


            Disable netconfig



            cat /etc/sysconfig/network/config
            NETCONFIG_DNS_POLICY=""


            Update The Config



            reboot


            Setting The DNS Server



            Example of a /etc/resolv.conf configuration



            #Cloudflare
            nameserver 1.0.0.1

            #Google
            #nameserver 8.8.8.8
            #nameserver 8.8.4.4

            #Cloudflare
            #nameserver 1.1.1.1

            #Classic Config
            #nameserver 192.168.1.1
            #search lan





            share|improve this answer




























              0














              DNS Config Under Linux



              DNS usage on linux is done over a set of routines in the C library that provide access to the Internet Domain Name System (DNS). The resolver configuration file (resolv.conf) contains information that is read by the resolver routines the first time they are invoked by a process. In short each process requesting DNS will read /etc/resolv.conf over library. The NSS is layered on top of this, and is configured by /etc/nsswitch.conf.



              Linux DNS config are located in the file /etc/resolv.conf BUT there are a number of programs/services that wants to automatically manage and handle the DNS configuration file at /etc/resolv.conf. In some situations you may want to manage this file yourself. Each program/service managing DNS have its own configuration files like /etc/dnsmasq.conf (for dnsmasq service) and append the DNS config at connection change and/or on other events... a quick solution is to lock the DNS config file with chattr +i /etc/resolv.conf but this is not recommended in certain case, a better solution is to setup correctly all the program/services using the DNS like (dnsmasq/network-manager/resolvconf/etc.)



              Getting Back The Control Of DNS



              Here is an exhaustive list of setups to get back the control of resolv.conf and avoid having it overwritten (how to disable/setup DNS from other location other than resolv.conf) note that resolvconf is an independent program from resolv.conf, also depending on your system/config you may not have one or many of the programs listed here.



              1. Resolvconf:



              Config files



              cat /etc/resolvconf/resolv.conf.d/head
              nameserver 8.8.4.4
              cat /etc/resolvconf/resolv.conf.d/base
              nameserver 8.8.4.4


              Update the config



              sudo resolvconf -u


              Disable resolvconf



              systemctl disable --now resolvconf.service 


              2. Dnsmasq Service:



              Config files



              cat /etc/dnsmasq.conf
              server=1.1.1.1
              server=8.8.4.4


              Update the config



              sudo systemctl restart dnsmasq.service


              3. Network Manager:



              Config files



              /etc/NetworkManager/*


              Disable DNS



              $ cat /etc/NetworkManager/conf.d/no-dns.conf
              [main]
              dns=none


              Enable DNS



              $ cat /etc/NetworkManager/conf.d/dns.conf
              [main]
              dns=default

              [global-dns]
              searches=example.com

              [global-dns-domain-*]


              Use resolved service



              $ cat /usr/lib/NetworkManager/conf.d/resolved.conf 
              [main]
              dns=systemd-resolved


              Use resolvconf



              $ cat /usr/lib/NetworkManager/conf.d/resolvconf.conf 
              [main]
              rc-manager=resolvconf


              Update the config



              systemctl restart NetworkManager.service


              4. Network Interfaces:



              Config files



              $ cat /etc/network/interfaces
              #nameservers
              # or dns-search like so
              # dns-search x.y
              dns-nameservers 4.4.4.4 8.8.8.8


              Update The Config



              reboot


              5. DHCP Client:



              Config files



              $ cat /etc/dhcp3/dhclient.conf
              supersede domain-name-servers <dns_ip_address1>,<dns_ip_address2>;


              Update The Config



              reboot


              6. Rdnssd Service:



              Disable rdnssd



              systemctl disable --now rdnssd.service


              7. Resolved Service:



              Disable resolved



              systemctl disable --now systemd-resolved.service


              8. Netconfig:



              Config files



              /etc/sysconfig/network/config


              Disable netconfig



              cat /etc/sysconfig/network/config
              NETCONFIG_DNS_POLICY=""


              Update The Config



              reboot


              Setting The DNS Server



              Example of a /etc/resolv.conf configuration



              #Cloudflare
              nameserver 1.0.0.1

              #Google
              #nameserver 8.8.8.8
              #nameserver 8.8.4.4

              #Cloudflare
              #nameserver 1.1.1.1

              #Classic Config
              #nameserver 192.168.1.1
              #search lan





              share|improve this answer


























                0












                0








                0







                DNS Config Under Linux



                DNS usage on linux is done over a set of routines in the C library that provide access to the Internet Domain Name System (DNS). The resolver configuration file (resolv.conf) contains information that is read by the resolver routines the first time they are invoked by a process. In short each process requesting DNS will read /etc/resolv.conf over library. The NSS is layered on top of this, and is configured by /etc/nsswitch.conf.



                Linux DNS config are located in the file /etc/resolv.conf BUT there are a number of programs/services that wants to automatically manage and handle the DNS configuration file at /etc/resolv.conf. In some situations you may want to manage this file yourself. Each program/service managing DNS have its own configuration files like /etc/dnsmasq.conf (for dnsmasq service) and append the DNS config at connection change and/or on other events... a quick solution is to lock the DNS config file with chattr +i /etc/resolv.conf but this is not recommended in certain case, a better solution is to setup correctly all the program/services using the DNS like (dnsmasq/network-manager/resolvconf/etc.)



                Getting Back The Control Of DNS



                Here is an exhaustive list of setups to get back the control of resolv.conf and avoid having it overwritten (how to disable/setup DNS from other location other than resolv.conf) note that resolvconf is an independent program from resolv.conf, also depending on your system/config you may not have one or many of the programs listed here.



                1. Resolvconf:



                Config files



                cat /etc/resolvconf/resolv.conf.d/head
                nameserver 8.8.4.4
                cat /etc/resolvconf/resolv.conf.d/base
                nameserver 8.8.4.4


                Update the config



                sudo resolvconf -u


                Disable resolvconf



                systemctl disable --now resolvconf.service 


                2. Dnsmasq Service:



                Config files



                cat /etc/dnsmasq.conf
                server=1.1.1.1
                server=8.8.4.4


                Update the config



                sudo systemctl restart dnsmasq.service


                3. Network Manager:



                Config files



                /etc/NetworkManager/*


                Disable DNS



                $ cat /etc/NetworkManager/conf.d/no-dns.conf
                [main]
                dns=none


                Enable DNS



                $ cat /etc/NetworkManager/conf.d/dns.conf
                [main]
                dns=default

                [global-dns]
                searches=example.com

                [global-dns-domain-*]


                Use resolved service



                $ cat /usr/lib/NetworkManager/conf.d/resolved.conf 
                [main]
                dns=systemd-resolved


                Use resolvconf



                $ cat /usr/lib/NetworkManager/conf.d/resolvconf.conf 
                [main]
                rc-manager=resolvconf


                Update the config



                systemctl restart NetworkManager.service


                4. Network Interfaces:



                Config files



                $ cat /etc/network/interfaces
                #nameservers
                # or dns-search like so
                # dns-search x.y
                dns-nameservers 4.4.4.4 8.8.8.8


                Update The Config



                reboot


                5. DHCP Client:



                Config files



                $ cat /etc/dhcp3/dhclient.conf
                supersede domain-name-servers <dns_ip_address1>,<dns_ip_address2>;


                Update The Config



                reboot


                6. Rdnssd Service:



                Disable rdnssd



                systemctl disable --now rdnssd.service


                7. Resolved Service:



                Disable resolved



                systemctl disable --now systemd-resolved.service


                8. Netconfig:



                Config files



                /etc/sysconfig/network/config


                Disable netconfig



                cat /etc/sysconfig/network/config
                NETCONFIG_DNS_POLICY=""


                Update The Config



                reboot


                Setting The DNS Server



                Example of a /etc/resolv.conf configuration



                #Cloudflare
                nameserver 1.0.0.1

                #Google
                #nameserver 8.8.8.8
                #nameserver 8.8.4.4

                #Cloudflare
                #nameserver 1.1.1.1

                #Classic Config
                #nameserver 192.168.1.1
                #search lan





                share|improve this answer













                DNS Config Under Linux



                DNS usage on linux is done over a set of routines in the C library that provide access to the Internet Domain Name System (DNS). The resolver configuration file (resolv.conf) contains information that is read by the resolver routines the first time they are invoked by a process. In short each process requesting DNS will read /etc/resolv.conf over library. The NSS is layered on top of this, and is configured by /etc/nsswitch.conf.



                Linux DNS config are located in the file /etc/resolv.conf BUT there are a number of programs/services that wants to automatically manage and handle the DNS configuration file at /etc/resolv.conf. In some situations you may want to manage this file yourself. Each program/service managing DNS have its own configuration files like /etc/dnsmasq.conf (for dnsmasq service) and append the DNS config at connection change and/or on other events... a quick solution is to lock the DNS config file with chattr +i /etc/resolv.conf but this is not recommended in certain case, a better solution is to setup correctly all the program/services using the DNS like (dnsmasq/network-manager/resolvconf/etc.)



                Getting Back The Control Of DNS



                Here is an exhaustive list of setups to get back the control of resolv.conf and avoid having it overwritten (how to disable/setup DNS from other location other than resolv.conf) note that resolvconf is an independent program from resolv.conf, also depending on your system/config you may not have one or many of the programs listed here.



                1. Resolvconf:



                Config files



                cat /etc/resolvconf/resolv.conf.d/head
                nameserver 8.8.4.4
                cat /etc/resolvconf/resolv.conf.d/base
                nameserver 8.8.4.4


                Update the config



                sudo resolvconf -u


                Disable resolvconf



                systemctl disable --now resolvconf.service 


                2. Dnsmasq Service:



                Config files



                cat /etc/dnsmasq.conf
                server=1.1.1.1
                server=8.8.4.4


                Update the config



                sudo systemctl restart dnsmasq.service


                3. Network Manager:



                Config files



                /etc/NetworkManager/*


                Disable DNS



                $ cat /etc/NetworkManager/conf.d/no-dns.conf
                [main]
                dns=none


                Enable DNS



                $ cat /etc/NetworkManager/conf.d/dns.conf
                [main]
                dns=default

                [global-dns]
                searches=example.com

                [global-dns-domain-*]


                Use resolved service



                $ cat /usr/lib/NetworkManager/conf.d/resolved.conf 
                [main]
                dns=systemd-resolved


                Use resolvconf



                $ cat /usr/lib/NetworkManager/conf.d/resolvconf.conf 
                [main]
                rc-manager=resolvconf


                Update the config



                systemctl restart NetworkManager.service


                4. Network Interfaces:



                Config files



                $ cat /etc/network/interfaces
                #nameservers
                # or dns-search like so
                # dns-search x.y
                dns-nameservers 4.4.4.4 8.8.8.8


                Update The Config



                reboot


                5. DHCP Client:



                Config files



                $ cat /etc/dhcp3/dhclient.conf
                supersede domain-name-servers <dns_ip_address1>,<dns_ip_address2>;


                Update The Config



                reboot


                6. Rdnssd Service:



                Disable rdnssd



                systemctl disable --now rdnssd.service


                7. Resolved Service:



                Disable resolved



                systemctl disable --now systemd-resolved.service


                8. Netconfig:



                Config files



                /etc/sysconfig/network/config


                Disable netconfig



                cat /etc/sysconfig/network/config
                NETCONFIG_DNS_POLICY=""


                Update The Config



                reboot


                Setting The DNS Server



                Example of a /etc/resolv.conf configuration



                #Cloudflare
                nameserver 1.0.0.1

                #Google
                #nameserver 8.8.8.8
                #nameserver 8.8.4.4

                #Cloudflare
                #nameserver 1.1.1.1

                #Classic Config
                #nameserver 192.168.1.1
                #search lan






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 hours ago









                intikaintika

                1875




                1875






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494324%2fhow-to-setup-dns-manually-on-linux%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Entries order in /etc/network/interfaces

                    新発田市

                    Grub takes very long (several minutes) to open Menu (in Multi-Boot-System)