CentOS7: Network Manager is using wrong search domain












3















With Network Manager in Red Hat 7, I am seeing an issue where the old/wrong search domain is being used after changing the hostname. In /etc/resolv.conf, I see:



# Generated by NetworkManager
search **ec2.internal** d.sample.com
nameserver 172.31.0.2


When I type hostname, I see my desired output:



[root@testing01 ~]# hostname
testing01.d.sample.com


But instead of replacing the search domains, it is appending the new domain name to the search domains. I want to completely get rid of ec2.internal and give this domain the ax altogether. Editing the /etc/resolv.conf file directly gets clobbered by Network Manager. I don't want to disable Network Manager, and I'd rather not disable NM's management of /etc/resolv.conf unless I absolutely have to.



So, 1) Why does NM keep reverting my search domain and 2) how can I fix this using nmcli or command line tools only?










share|improve this question





























    3















    With Network Manager in Red Hat 7, I am seeing an issue where the old/wrong search domain is being used after changing the hostname. In /etc/resolv.conf, I see:



    # Generated by NetworkManager
    search **ec2.internal** d.sample.com
    nameserver 172.31.0.2


    When I type hostname, I see my desired output:



    [root@testing01 ~]# hostname
    testing01.d.sample.com


    But instead of replacing the search domains, it is appending the new domain name to the search domains. I want to completely get rid of ec2.internal and give this domain the ax altogether. Editing the /etc/resolv.conf file directly gets clobbered by Network Manager. I don't want to disable Network Manager, and I'd rather not disable NM's management of /etc/resolv.conf unless I absolutely have to.



    So, 1) Why does NM keep reverting my search domain and 2) how can I fix this using nmcli or command line tools only?










    share|improve this question



























      3












      3








      3


      1






      With Network Manager in Red Hat 7, I am seeing an issue where the old/wrong search domain is being used after changing the hostname. In /etc/resolv.conf, I see:



      # Generated by NetworkManager
      search **ec2.internal** d.sample.com
      nameserver 172.31.0.2


      When I type hostname, I see my desired output:



      [root@testing01 ~]# hostname
      testing01.d.sample.com


      But instead of replacing the search domains, it is appending the new domain name to the search domains. I want to completely get rid of ec2.internal and give this domain the ax altogether. Editing the /etc/resolv.conf file directly gets clobbered by Network Manager. I don't want to disable Network Manager, and I'd rather not disable NM's management of /etc/resolv.conf unless I absolutely have to.



      So, 1) Why does NM keep reverting my search domain and 2) how can I fix this using nmcli or command line tools only?










      share|improve this question
















      With Network Manager in Red Hat 7, I am seeing an issue where the old/wrong search domain is being used after changing the hostname. In /etc/resolv.conf, I see:



      # Generated by NetworkManager
      search **ec2.internal** d.sample.com
      nameserver 172.31.0.2


      When I type hostname, I see my desired output:



      [root@testing01 ~]# hostname
      testing01.d.sample.com


      But instead of replacing the search domains, it is appending the new domain name to the search domains. I want to completely get rid of ec2.internal and give this domain the ax altogether. Editing the /etc/resolv.conf file directly gets clobbered by Network Manager. I don't want to disable Network Manager, and I'd rather not disable NM's management of /etc/resolv.conf unless I absolutely have to.



      So, 1) Why does NM keep reverting my search domain and 2) how can I fix this using nmcli or command line tools only?







      centos rhel dns networkmanager resolv.conf






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 19 '18 at 18:49









      nwildner

      14.1k14176




      14.1k14176










      asked Jan 12 '17 at 1:03









      James SheweyJames Shewey

      4831512




      4831512






















          3 Answers
          3






          active

          oldest

          votes


















          3














          The /etc/resolv.conf file will always be overwritten when there is a change or update to the network. You can control what is written by editing files in the /etc/resolvconf/resolv.conf.d/ folder... namely the head file.



          Place this in the /etc/resolvconf/resolv.conf.d/head file:



          nameserver 172.31.0.2
          search testing01.d.sample.com


          Now this will be the header of the /etc/resolv.conf each time it's updated.



          Update



          For Redhat based systems, use these steps:



          Edit your network script which is located at: /etc/sysconfig/network-scripts. You will see an entry for the network devices detected (i.e. ifcfg-eth0 for the network adapter eth0).



          Edit this file (/etc/sysconfig/network-scripts/ifcfg-eth0):



          Append this line:



          DOMAIN=sample.com


          Also run this command:



          $ sudo hostnamectl set-hostname --static "testing01.d.sample.com"


          You'll most likely have to reboot the system to make the changes take effect.






          share|improve this answer


























          • This did not work on Red Hat. The file did not exist and creating it did not solve the problem. It seems like this might work on Ubuntu/Debian only.

            – James Shewey
            Jan 12 '17 at 5:44











          • @JamesShewey I updated my answer to include the Red Hat specifics. By the way, there are usually a number of ways of achieving a desired result. I notice you also posted a variation.

            – L. D. James
            Jan 12 '17 at 20:48



















          2














          After a few hours of poking around, I was able to resolve this. It turns out, this was being set via DHCP:



          nmcli -f ip4 device show eth0
          IP4.ADDRESS[1]: 172.31.53.162/20
          IP4.GATEWAY: 172.31.48.1
          IP4.DNS[1]: 172.31.0.2
          IP4.DOMAIN[1]: ec2.internal


          I was able to override IP4.DOMAIN[1] by overriding a network interface's ipv4.dns-search value:



          nmcli connection modify uuid `nmcli connection show --active | grep 802-3-ethernet | awk '{print $(NF-2)}' | tail -n 1` ipv4.dns-search d.sample.com


          Or more simply,



          nmcli connection modify System eth0 ipv4.dns-search "d.sample.com"


          Then you have to restart NetworkManager



          systemctl restart NetworkManager.service


          I also found that because I was working with an Amazon instance, I needed to update my cloud.cfg file.






          share|improve this answer





















          • 1





            Restarting NetworkManager to apply network configuration is wrong. Instead, reactive the connection profile via nmcli connection up, nmcli device connect, nmcli device reapply or nmcli device modify.

            – thaller
            Jan 12 '17 at 9:28



















          0














          If "nmcli connection modify ..." has changed your connection file but not your active connection:



          nmcli c load /etc/NetworkManager/system-connections/the-connection-name[-possibly-uuid-too]



          man nmcli:
          connection--
          load filename...
          Load/reload one or more connection files from disk. Use this after manually editing a connection file to ensure that NetworkManager is aware of its latest state.






          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%2f336727%2fcentos7-network-manager-is-using-wrong-search-domain%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            The /etc/resolv.conf file will always be overwritten when there is a change or update to the network. You can control what is written by editing files in the /etc/resolvconf/resolv.conf.d/ folder... namely the head file.



            Place this in the /etc/resolvconf/resolv.conf.d/head file:



            nameserver 172.31.0.2
            search testing01.d.sample.com


            Now this will be the header of the /etc/resolv.conf each time it's updated.



            Update



            For Redhat based systems, use these steps:



            Edit your network script which is located at: /etc/sysconfig/network-scripts. You will see an entry for the network devices detected (i.e. ifcfg-eth0 for the network adapter eth0).



            Edit this file (/etc/sysconfig/network-scripts/ifcfg-eth0):



            Append this line:



            DOMAIN=sample.com


            Also run this command:



            $ sudo hostnamectl set-hostname --static "testing01.d.sample.com"


            You'll most likely have to reboot the system to make the changes take effect.






            share|improve this answer


























            • This did not work on Red Hat. The file did not exist and creating it did not solve the problem. It seems like this might work on Ubuntu/Debian only.

              – James Shewey
              Jan 12 '17 at 5:44











            • @JamesShewey I updated my answer to include the Red Hat specifics. By the way, there are usually a number of ways of achieving a desired result. I notice you also posted a variation.

              – L. D. James
              Jan 12 '17 at 20:48
















            3














            The /etc/resolv.conf file will always be overwritten when there is a change or update to the network. You can control what is written by editing files in the /etc/resolvconf/resolv.conf.d/ folder... namely the head file.



            Place this in the /etc/resolvconf/resolv.conf.d/head file:



            nameserver 172.31.0.2
            search testing01.d.sample.com


            Now this will be the header of the /etc/resolv.conf each time it's updated.



            Update



            For Redhat based systems, use these steps:



            Edit your network script which is located at: /etc/sysconfig/network-scripts. You will see an entry for the network devices detected (i.e. ifcfg-eth0 for the network adapter eth0).



            Edit this file (/etc/sysconfig/network-scripts/ifcfg-eth0):



            Append this line:



            DOMAIN=sample.com


            Also run this command:



            $ sudo hostnamectl set-hostname --static "testing01.d.sample.com"


            You'll most likely have to reboot the system to make the changes take effect.






            share|improve this answer


























            • This did not work on Red Hat. The file did not exist and creating it did not solve the problem. It seems like this might work on Ubuntu/Debian only.

              – James Shewey
              Jan 12 '17 at 5:44











            • @JamesShewey I updated my answer to include the Red Hat specifics. By the way, there are usually a number of ways of achieving a desired result. I notice you also posted a variation.

              – L. D. James
              Jan 12 '17 at 20:48














            3












            3








            3







            The /etc/resolv.conf file will always be overwritten when there is a change or update to the network. You can control what is written by editing files in the /etc/resolvconf/resolv.conf.d/ folder... namely the head file.



            Place this in the /etc/resolvconf/resolv.conf.d/head file:



            nameserver 172.31.0.2
            search testing01.d.sample.com


            Now this will be the header of the /etc/resolv.conf each time it's updated.



            Update



            For Redhat based systems, use these steps:



            Edit your network script which is located at: /etc/sysconfig/network-scripts. You will see an entry for the network devices detected (i.e. ifcfg-eth0 for the network adapter eth0).



            Edit this file (/etc/sysconfig/network-scripts/ifcfg-eth0):



            Append this line:



            DOMAIN=sample.com


            Also run this command:



            $ sudo hostnamectl set-hostname --static "testing01.d.sample.com"


            You'll most likely have to reboot the system to make the changes take effect.






            share|improve this answer















            The /etc/resolv.conf file will always be overwritten when there is a change or update to the network. You can control what is written by editing files in the /etc/resolvconf/resolv.conf.d/ folder... namely the head file.



            Place this in the /etc/resolvconf/resolv.conf.d/head file:



            nameserver 172.31.0.2
            search testing01.d.sample.com


            Now this will be the header of the /etc/resolv.conf each time it's updated.



            Update



            For Redhat based systems, use these steps:



            Edit your network script which is located at: /etc/sysconfig/network-scripts. You will see an entry for the network devices detected (i.e. ifcfg-eth0 for the network adapter eth0).



            Edit this file (/etc/sysconfig/network-scripts/ifcfg-eth0):



            Append this line:



            DOMAIN=sample.com


            Also run this command:



            $ sudo hostnamectl set-hostname --static "testing01.d.sample.com"


            You'll most likely have to reboot the system to make the changes take effect.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 12 '17 at 20:40

























            answered Jan 12 '17 at 1:16









            L. D. JamesL. D. James

            849514




            849514













            • This did not work on Red Hat. The file did not exist and creating it did not solve the problem. It seems like this might work on Ubuntu/Debian only.

              – James Shewey
              Jan 12 '17 at 5:44











            • @JamesShewey I updated my answer to include the Red Hat specifics. By the way, there are usually a number of ways of achieving a desired result. I notice you also posted a variation.

              – L. D. James
              Jan 12 '17 at 20:48



















            • This did not work on Red Hat. The file did not exist and creating it did not solve the problem. It seems like this might work on Ubuntu/Debian only.

              – James Shewey
              Jan 12 '17 at 5:44











            • @JamesShewey I updated my answer to include the Red Hat specifics. By the way, there are usually a number of ways of achieving a desired result. I notice you also posted a variation.

              – L. D. James
              Jan 12 '17 at 20:48

















            This did not work on Red Hat. The file did not exist and creating it did not solve the problem. It seems like this might work on Ubuntu/Debian only.

            – James Shewey
            Jan 12 '17 at 5:44





            This did not work on Red Hat. The file did not exist and creating it did not solve the problem. It seems like this might work on Ubuntu/Debian only.

            – James Shewey
            Jan 12 '17 at 5:44













            @JamesShewey I updated my answer to include the Red Hat specifics. By the way, there are usually a number of ways of achieving a desired result. I notice you also posted a variation.

            – L. D. James
            Jan 12 '17 at 20:48





            @JamesShewey I updated my answer to include the Red Hat specifics. By the way, there are usually a number of ways of achieving a desired result. I notice you also posted a variation.

            – L. D. James
            Jan 12 '17 at 20:48













            2














            After a few hours of poking around, I was able to resolve this. It turns out, this was being set via DHCP:



            nmcli -f ip4 device show eth0
            IP4.ADDRESS[1]: 172.31.53.162/20
            IP4.GATEWAY: 172.31.48.1
            IP4.DNS[1]: 172.31.0.2
            IP4.DOMAIN[1]: ec2.internal


            I was able to override IP4.DOMAIN[1] by overriding a network interface's ipv4.dns-search value:



            nmcli connection modify uuid `nmcli connection show --active | grep 802-3-ethernet | awk '{print $(NF-2)}' | tail -n 1` ipv4.dns-search d.sample.com


            Or more simply,



            nmcli connection modify System eth0 ipv4.dns-search "d.sample.com"


            Then you have to restart NetworkManager



            systemctl restart NetworkManager.service


            I also found that because I was working with an Amazon instance, I needed to update my cloud.cfg file.






            share|improve this answer





















            • 1





              Restarting NetworkManager to apply network configuration is wrong. Instead, reactive the connection profile via nmcli connection up, nmcli device connect, nmcli device reapply or nmcli device modify.

              – thaller
              Jan 12 '17 at 9:28
















            2














            After a few hours of poking around, I was able to resolve this. It turns out, this was being set via DHCP:



            nmcli -f ip4 device show eth0
            IP4.ADDRESS[1]: 172.31.53.162/20
            IP4.GATEWAY: 172.31.48.1
            IP4.DNS[1]: 172.31.0.2
            IP4.DOMAIN[1]: ec2.internal


            I was able to override IP4.DOMAIN[1] by overriding a network interface's ipv4.dns-search value:



            nmcli connection modify uuid `nmcli connection show --active | grep 802-3-ethernet | awk '{print $(NF-2)}' | tail -n 1` ipv4.dns-search d.sample.com


            Or more simply,



            nmcli connection modify System eth0 ipv4.dns-search "d.sample.com"


            Then you have to restart NetworkManager



            systemctl restart NetworkManager.service


            I also found that because I was working with an Amazon instance, I needed to update my cloud.cfg file.






            share|improve this answer





















            • 1





              Restarting NetworkManager to apply network configuration is wrong. Instead, reactive the connection profile via nmcli connection up, nmcli device connect, nmcli device reapply or nmcli device modify.

              – thaller
              Jan 12 '17 at 9:28














            2












            2








            2







            After a few hours of poking around, I was able to resolve this. It turns out, this was being set via DHCP:



            nmcli -f ip4 device show eth0
            IP4.ADDRESS[1]: 172.31.53.162/20
            IP4.GATEWAY: 172.31.48.1
            IP4.DNS[1]: 172.31.0.2
            IP4.DOMAIN[1]: ec2.internal


            I was able to override IP4.DOMAIN[1] by overriding a network interface's ipv4.dns-search value:



            nmcli connection modify uuid `nmcli connection show --active | grep 802-3-ethernet | awk '{print $(NF-2)}' | tail -n 1` ipv4.dns-search d.sample.com


            Or more simply,



            nmcli connection modify System eth0 ipv4.dns-search "d.sample.com"


            Then you have to restart NetworkManager



            systemctl restart NetworkManager.service


            I also found that because I was working with an Amazon instance, I needed to update my cloud.cfg file.






            share|improve this answer















            After a few hours of poking around, I was able to resolve this. It turns out, this was being set via DHCP:



            nmcli -f ip4 device show eth0
            IP4.ADDRESS[1]: 172.31.53.162/20
            IP4.GATEWAY: 172.31.48.1
            IP4.DNS[1]: 172.31.0.2
            IP4.DOMAIN[1]: ec2.internal


            I was able to override IP4.DOMAIN[1] by overriding a network interface's ipv4.dns-search value:



            nmcli connection modify uuid `nmcli connection show --active | grep 802-3-ethernet | awk '{print $(NF-2)}' | tail -n 1` ipv4.dns-search d.sample.com


            Or more simply,



            nmcli connection modify System eth0 ipv4.dns-search "d.sample.com"


            Then you have to restart NetworkManager



            systemctl restart NetworkManager.service


            I also found that because I was working with an Amazon instance, I needed to update my cloud.cfg file.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Feb 19 '18 at 18:46









            nwildner

            14.1k14176




            14.1k14176










            answered Jan 12 '17 at 7:23









            James SheweyJames Shewey

            4831512




            4831512








            • 1





              Restarting NetworkManager to apply network configuration is wrong. Instead, reactive the connection profile via nmcli connection up, nmcli device connect, nmcli device reapply or nmcli device modify.

              – thaller
              Jan 12 '17 at 9:28














            • 1





              Restarting NetworkManager to apply network configuration is wrong. Instead, reactive the connection profile via nmcli connection up, nmcli device connect, nmcli device reapply or nmcli device modify.

              – thaller
              Jan 12 '17 at 9:28








            1




            1





            Restarting NetworkManager to apply network configuration is wrong. Instead, reactive the connection profile via nmcli connection up, nmcli device connect, nmcli device reapply or nmcli device modify.

            – thaller
            Jan 12 '17 at 9:28





            Restarting NetworkManager to apply network configuration is wrong. Instead, reactive the connection profile via nmcli connection up, nmcli device connect, nmcli device reapply or nmcli device modify.

            – thaller
            Jan 12 '17 at 9:28











            0














            If "nmcli connection modify ..." has changed your connection file but not your active connection:



            nmcli c load /etc/NetworkManager/system-connections/the-connection-name[-possibly-uuid-too]



            man nmcli:
            connection--
            load filename...
            Load/reload one or more connection files from disk. Use this after manually editing a connection file to ensure that NetworkManager is aware of its latest state.






            share|improve this answer




























              0














              If "nmcli connection modify ..." has changed your connection file but not your active connection:



              nmcli c load /etc/NetworkManager/system-connections/the-connection-name[-possibly-uuid-too]



              man nmcli:
              connection--
              load filename...
              Load/reload one or more connection files from disk. Use this after manually editing a connection file to ensure that NetworkManager is aware of its latest state.






              share|improve this answer


























                0












                0








                0







                If "nmcli connection modify ..." has changed your connection file but not your active connection:



                nmcli c load /etc/NetworkManager/system-connections/the-connection-name[-possibly-uuid-too]



                man nmcli:
                connection--
                load filename...
                Load/reload one or more connection files from disk. Use this after manually editing a connection file to ensure that NetworkManager is aware of its latest state.






                share|improve this answer













                If "nmcli connection modify ..." has changed your connection file but not your active connection:



                nmcli c load /etc/NetworkManager/system-connections/the-connection-name[-possibly-uuid-too]



                man nmcli:
                connection--
                load filename...
                Load/reload one or more connection files from disk. Use this after manually editing a connection file to ensure that NetworkManager is aware of its latest state.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 19 mins ago









                BobDoddsBobDodds

                112




                112






























                    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%2f336727%2fcentos7-network-manager-is-using-wrong-search-domain%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

                    サソリ

                    広島県道265号伴広島線

                    Accessing regular linux commands in Huawei's Dopra Linux