Detecting whether netplan is managing network config (shell)

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
1
down vote

favorite
1












I would like to figure out in a shell script in an LXD container, whether the container is being managed by Netplan. This can be a bit of an unknown as I have a mix of 16.04 systems 18.04 systems and upgraded 18.04 systems.



In order to write correct network config to the container, I need to detect if the config is static in /etc/network/interfaces or in a Netplan yaml file.



I could really use something like netplan status but since that command does not exist I need alternatives.



I have asked around a fair bit, and there seems to be no official way.The suggestions I have had so far:




  1. cat /etc/network/interfaces and look for the Netplan info message there. I don't like this approach, as this would obviously be prone to breakage.

  2. Someone suggested I could just look for /etc/netplan - but that will not work on upgraded systems as there Netplan is disabled but still installed.

  3. Another suggestion was the inverse: that I could check if ifupdown or systemd is managing the network. Problem is, I am not sure how to do this in a practical sense.






share|improve this question
























    up vote
    1
    down vote

    favorite
    1












    I would like to figure out in a shell script in an LXD container, whether the container is being managed by Netplan. This can be a bit of an unknown as I have a mix of 16.04 systems 18.04 systems and upgraded 18.04 systems.



    In order to write correct network config to the container, I need to detect if the config is static in /etc/network/interfaces or in a Netplan yaml file.



    I could really use something like netplan status but since that command does not exist I need alternatives.



    I have asked around a fair bit, and there seems to be no official way.The suggestions I have had so far:




    1. cat /etc/network/interfaces and look for the Netplan info message there. I don't like this approach, as this would obviously be prone to breakage.

    2. Someone suggested I could just look for /etc/netplan - but that will not work on upgraded systems as there Netplan is disabled but still installed.

    3. Another suggestion was the inverse: that I could check if ifupdown or systemd is managing the network. Problem is, I am not sure how to do this in a practical sense.






    share|improve this question






















      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      I would like to figure out in a shell script in an LXD container, whether the container is being managed by Netplan. This can be a bit of an unknown as I have a mix of 16.04 systems 18.04 systems and upgraded 18.04 systems.



      In order to write correct network config to the container, I need to detect if the config is static in /etc/network/interfaces or in a Netplan yaml file.



      I could really use something like netplan status but since that command does not exist I need alternatives.



      I have asked around a fair bit, and there seems to be no official way.The suggestions I have had so far:




      1. cat /etc/network/interfaces and look for the Netplan info message there. I don't like this approach, as this would obviously be prone to breakage.

      2. Someone suggested I could just look for /etc/netplan - but that will not work on upgraded systems as there Netplan is disabled but still installed.

      3. Another suggestion was the inverse: that I could check if ifupdown or systemd is managing the network. Problem is, I am not sure how to do this in a practical sense.






      share|improve this question












      I would like to figure out in a shell script in an LXD container, whether the container is being managed by Netplan. This can be a bit of an unknown as I have a mix of 16.04 systems 18.04 systems and upgraded 18.04 systems.



      In order to write correct network config to the container, I need to detect if the config is static in /etc/network/interfaces or in a Netplan yaml file.



      I could really use something like netplan status but since that command does not exist I need alternatives.



      I have asked around a fair bit, and there seems to be no official way.The suggestions I have had so far:




      1. cat /etc/network/interfaces and look for the Netplan info message there. I don't like this approach, as this would obviously be prone to breakage.

      2. Someone suggested I could just look for /etc/netplan - but that will not work on upgraded systems as there Netplan is disabled but still installed.

      3. Another suggestion was the inverse: that I could check if ifupdown or systemd is managing the network. Problem is, I am not sure how to do this in a practical sense.








      share|improve this question











      share|improve this question




      share|improve this question










      asked May 8 at 13:52









      Arni J

      153




      153




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          You may be able to check for the ifstate file from ifupdown, which will tell you whether that's what was used to configure the network:



          /run/network/ifstate


          If that's there and it contains text, you can expect that ifupdown is in use. If it's not present, the system is likely managed via netplan (but that won't tell you whether it's NetworkManager or systemd)



          Then, if you want to know what backend is used for a particular interface, you can ask netplan, and parse the output to get the information you need:



          netplan generate --mapping enp3s0


          It outputs text like this:



          id=enp3s0, backend=NetworkManager, set_name=(null), match_name=enp3s0, match_mac=(null), match_driver=(null)


          That way you can also know using what matching rules the interface was configured (you use the "final" name of an interface to check the mapping, it tells you what matching rule is in the netplan YAML that matches for it).






          share|improve this answer




















          • Thank you for your thorough reply. I am now looking for /run/network/ifstate to ascertain what network config to write, and everything seems to work well :)
            – Arni J
            May 13 at 19:49










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "89"
          ;
          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',
          convertImagesToLinks: true,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1033592%2fdetecting-whether-netplan-is-managing-network-config-shell%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          You may be able to check for the ifstate file from ifupdown, which will tell you whether that's what was used to configure the network:



          /run/network/ifstate


          If that's there and it contains text, you can expect that ifupdown is in use. If it's not present, the system is likely managed via netplan (but that won't tell you whether it's NetworkManager or systemd)



          Then, if you want to know what backend is used for a particular interface, you can ask netplan, and parse the output to get the information you need:



          netplan generate --mapping enp3s0


          It outputs text like this:



          id=enp3s0, backend=NetworkManager, set_name=(null), match_name=enp3s0, match_mac=(null), match_driver=(null)


          That way you can also know using what matching rules the interface was configured (you use the "final" name of an interface to check the mapping, it tells you what matching rule is in the netplan YAML that matches for it).






          share|improve this answer




















          • Thank you for your thorough reply. I am now looking for /run/network/ifstate to ascertain what network config to write, and everything seems to work well :)
            – Arni J
            May 13 at 19:49














          up vote
          2
          down vote



          accepted










          You may be able to check for the ifstate file from ifupdown, which will tell you whether that's what was used to configure the network:



          /run/network/ifstate


          If that's there and it contains text, you can expect that ifupdown is in use. If it's not present, the system is likely managed via netplan (but that won't tell you whether it's NetworkManager or systemd)



          Then, if you want to know what backend is used for a particular interface, you can ask netplan, and parse the output to get the information you need:



          netplan generate --mapping enp3s0


          It outputs text like this:



          id=enp3s0, backend=NetworkManager, set_name=(null), match_name=enp3s0, match_mac=(null), match_driver=(null)


          That way you can also know using what matching rules the interface was configured (you use the "final" name of an interface to check the mapping, it tells you what matching rule is in the netplan YAML that matches for it).






          share|improve this answer




















          • Thank you for your thorough reply. I am now looking for /run/network/ifstate to ascertain what network config to write, and everything seems to work well :)
            – Arni J
            May 13 at 19:49












          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          You may be able to check for the ifstate file from ifupdown, which will tell you whether that's what was used to configure the network:



          /run/network/ifstate


          If that's there and it contains text, you can expect that ifupdown is in use. If it's not present, the system is likely managed via netplan (but that won't tell you whether it's NetworkManager or systemd)



          Then, if you want to know what backend is used for a particular interface, you can ask netplan, and parse the output to get the information you need:



          netplan generate --mapping enp3s0


          It outputs text like this:



          id=enp3s0, backend=NetworkManager, set_name=(null), match_name=enp3s0, match_mac=(null), match_driver=(null)


          That way you can also know using what matching rules the interface was configured (you use the "final" name of an interface to check the mapping, it tells you what matching rule is in the netplan YAML that matches for it).






          share|improve this answer












          You may be able to check for the ifstate file from ifupdown, which will tell you whether that's what was used to configure the network:



          /run/network/ifstate


          If that's there and it contains text, you can expect that ifupdown is in use. If it's not present, the system is likely managed via netplan (but that won't tell you whether it's NetworkManager or systemd)



          Then, if you want to know what backend is used for a particular interface, you can ask netplan, and parse the output to get the information you need:



          netplan generate --mapping enp3s0


          It outputs text like this:



          id=enp3s0, backend=NetworkManager, set_name=(null), match_name=enp3s0, match_mac=(null), match_driver=(null)


          That way you can also know using what matching rules the interface was configured (you use the "final" name of an interface to check the mapping, it tells you what matching rule is in the netplan YAML that matches for it).







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 10 at 20:39









          Mathieu Trudel-Lapierre

          1,9921130




          1,9921130











          • Thank you for your thorough reply. I am now looking for /run/network/ifstate to ascertain what network config to write, and everything seems to work well :)
            – Arni J
            May 13 at 19:49
















          • Thank you for your thorough reply. I am now looking for /run/network/ifstate to ascertain what network config to write, and everything seems to work well :)
            – Arni J
            May 13 at 19:49















          Thank you for your thorough reply. I am now looking for /run/network/ifstate to ascertain what network config to write, and everything seems to work well :)
          – Arni J
          May 13 at 19:49




          Thank you for your thorough reply. I am now looking for /run/network/ifstate to ascertain what network config to write, and everything seems to work well :)
          – Arni J
          May 13 at 19:49












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1033592%2fdetecting-whether-netplan-is-managing-network-config-shell%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          pylint3 and pip3 broken

          Missing snmpget and snmpwalk

          How to enroll fingerprints to Ubuntu 17.10 with VFS491