Why isn't the Iptables persistent service saving my changes?











up vote
12
down vote

favorite
12












I followed this tutorial to set up IP rules on ubuntu 12.04. Everything worked fine on setup -- but now I've made changes to the firewall that do not persist upon reboot. I do not understand why that is. Here is a demonstration of how I am using iptables-persistent. What am I doing wrong?



$ sudo service iptables-persistent start
* Loading iptables rules... * IPv4... * IPv6...

$ sudo iptables -L //shows a certain rule
$ iptables -D INPUT ... //command successfully drops the rule
$ sudo iptables -L //shows rule has been deleted

$ sudo service iptables-persistent restart
* Loading iptables rules... * IPv4... * IPv6... [ OK ]
$ sudo iptables -L //rule is back









share|improve this question
























  • I'm noticing the iptables -D INPUT rule isn't in sudo are you sure it's actually reporting a success? Does the behavior change if you do run it within sudo?
    – Bratchley
    Apr 21 '14 at 16:29















up vote
12
down vote

favorite
12












I followed this tutorial to set up IP rules on ubuntu 12.04. Everything worked fine on setup -- but now I've made changes to the firewall that do not persist upon reboot. I do not understand why that is. Here is a demonstration of how I am using iptables-persistent. What am I doing wrong?



$ sudo service iptables-persistent start
* Loading iptables rules... * IPv4... * IPv6...

$ sudo iptables -L //shows a certain rule
$ iptables -D INPUT ... //command successfully drops the rule
$ sudo iptables -L //shows rule has been deleted

$ sudo service iptables-persistent restart
* Loading iptables rules... * IPv4... * IPv6... [ OK ]
$ sudo iptables -L //rule is back









share|improve this question
























  • I'm noticing the iptables -D INPUT rule isn't in sudo are you sure it's actually reporting a success? Does the behavior change if you do run it within sudo?
    – Bratchley
    Apr 21 '14 at 16:29













up vote
12
down vote

favorite
12









up vote
12
down vote

favorite
12






12





I followed this tutorial to set up IP rules on ubuntu 12.04. Everything worked fine on setup -- but now I've made changes to the firewall that do not persist upon reboot. I do not understand why that is. Here is a demonstration of how I am using iptables-persistent. What am I doing wrong?



$ sudo service iptables-persistent start
* Loading iptables rules... * IPv4... * IPv6...

$ sudo iptables -L //shows a certain rule
$ iptables -D INPUT ... //command successfully drops the rule
$ sudo iptables -L //shows rule has been deleted

$ sudo service iptables-persistent restart
* Loading iptables rules... * IPv4... * IPv6... [ OK ]
$ sudo iptables -L //rule is back









share|improve this question















I followed this tutorial to set up IP rules on ubuntu 12.04. Everything worked fine on setup -- but now I've made changes to the firewall that do not persist upon reboot. I do not understand why that is. Here is a demonstration of how I am using iptables-persistent. What am I doing wrong?



$ sudo service iptables-persistent start
* Loading iptables rules... * IPv4... * IPv6...

$ sudo iptables -L //shows a certain rule
$ iptables -D INPUT ... //command successfully drops the rule
$ sudo iptables -L //shows rule has been deleted

$ sudo service iptables-persistent restart
* Loading iptables rules... * IPv4... * IPv6... [ OK ]
$ sudo iptables -L //rule is back






iptables iptables-persistent






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 21 '14 at 16:12

























asked Apr 21 '14 at 15:59









bernie2436

2,000153855




2,000153855












  • I'm noticing the iptables -D INPUT rule isn't in sudo are you sure it's actually reporting a success? Does the behavior change if you do run it within sudo?
    – Bratchley
    Apr 21 '14 at 16:29


















  • I'm noticing the iptables -D INPUT rule isn't in sudo are you sure it's actually reporting a success? Does the behavior change if you do run it within sudo?
    – Bratchley
    Apr 21 '14 at 16:29
















I'm noticing the iptables -D INPUT rule isn't in sudo are you sure it's actually reporting a success? Does the behavior change if you do run it within sudo?
– Bratchley
Apr 21 '14 at 16:29




I'm noticing the iptables -D INPUT rule isn't in sudo are you sure it's actually reporting a success? Does the behavior change if you do run it within sudo?
– Bratchley
Apr 21 '14 at 16:29










3 Answers
3






active

oldest

votes

















up vote
35
down vote



accepted










iptables-persistent does not work that way. Restarting the iptables-persistent "service" does not capture the current state of the iptables and save it; all it does is reinstate the iptables rules that were saved when the package was last configured.



To configure iptables-persistent, you need to tell it about your current iptables ruleset.



One way to accomplish that is as follows:



iptables-save >/etc/iptables/rules.v4
ip6tables-save >/etc/iptables/rules.v6


Or, equivalently, the iptables-persistent package also provides the following:



dpkg-reconfigure iptables-persistent


(You will need to answer yes to the questions about whether to save the rules.)



After that, the next time iptables-persistent is started/restarted, the iptables rulesets you expect will be loaded.






share|improve this answer




























    up vote
    5
    down vote













    Very simple way to save the current iptables rules is to use the command:



    sudo service netfilter-persistent save



    Using the above, which works at least in Ubuntu after installing the netfilter-persistent (and iptables-persistent) package, there is no need to run manually the iptables commands or to reconfigure the package (as suggested by even the accepted Answer above).






    share|improve this answer























    • Is it sudo service netfilter-persistent save or sudo service netfilter-persistent save . ? (Dot at the end.)
      – Tomasz
      Feb 27 at 15:15










    • Thanks for noting that, the correct command is w/o the dot at the end of line. Corrected the Answer accordingly.
      – OpenITeX
      Nov 23 at 22:26


















    up vote
    3
    down vote













    $ iptables ... DROP //command successfully drops the rule
    $ sudo iptables -L //shows rule has been deleted


    That's not what DROP means or does. From man iptables:




    ...the special values ACCEPT, DROP, QUEUE or RETURN. ACCEPT means to let the packet through. DROP means to drop the packet on the floor. QUEUE means...




    So what you've done is add a new rule. It may effectively supersede any number of other rules, but those rules still exist.



    When checking stuff like this (your iptables -L output), I would feed it though grep "string unique to this rule" rather than use your eyes. It's easier and faster to do, and less error prone.



    iptables -L | grep "some unique string"


    If you want to delete a rule, use the -D switch; the man page describes two forms of this:




    -D, --delete chain rule-specification



    -D, --delete chain rulenum



    Delete one or more rules from the selected chain. There are two versions of this command: the rule can be specified as a number in the chain (starting at 1 for the first rule) or a rule to match.







    share|improve this answer





















    • sorry that was unclear. I am using the -D option to DROP a rule. See the change above
      – bernie2436
      Apr 21 '14 at 16:13






    • 2




      -D stands for "delete" not "DROP" Using the term "DROP" to mean anything other than a jump target when talking about iptables is confusing as hell.
      – Bratchley
      Apr 21 '14 at 16:27











    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',
    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%2f125833%2fwhy-isnt-the-iptables-persistent-service-saving-my-changes%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








    up vote
    35
    down vote



    accepted










    iptables-persistent does not work that way. Restarting the iptables-persistent "service" does not capture the current state of the iptables and save it; all it does is reinstate the iptables rules that were saved when the package was last configured.



    To configure iptables-persistent, you need to tell it about your current iptables ruleset.



    One way to accomplish that is as follows:



    iptables-save >/etc/iptables/rules.v4
    ip6tables-save >/etc/iptables/rules.v6


    Or, equivalently, the iptables-persistent package also provides the following:



    dpkg-reconfigure iptables-persistent


    (You will need to answer yes to the questions about whether to save the rules.)



    After that, the next time iptables-persistent is started/restarted, the iptables rulesets you expect will be loaded.






    share|improve this answer

























      up vote
      35
      down vote



      accepted










      iptables-persistent does not work that way. Restarting the iptables-persistent "service" does not capture the current state of the iptables and save it; all it does is reinstate the iptables rules that were saved when the package was last configured.



      To configure iptables-persistent, you need to tell it about your current iptables ruleset.



      One way to accomplish that is as follows:



      iptables-save >/etc/iptables/rules.v4
      ip6tables-save >/etc/iptables/rules.v6


      Or, equivalently, the iptables-persistent package also provides the following:



      dpkg-reconfigure iptables-persistent


      (You will need to answer yes to the questions about whether to save the rules.)



      After that, the next time iptables-persistent is started/restarted, the iptables rulesets you expect will be loaded.






      share|improve this answer























        up vote
        35
        down vote



        accepted







        up vote
        35
        down vote



        accepted






        iptables-persistent does not work that way. Restarting the iptables-persistent "service" does not capture the current state of the iptables and save it; all it does is reinstate the iptables rules that were saved when the package was last configured.



        To configure iptables-persistent, you need to tell it about your current iptables ruleset.



        One way to accomplish that is as follows:



        iptables-save >/etc/iptables/rules.v4
        ip6tables-save >/etc/iptables/rules.v6


        Or, equivalently, the iptables-persistent package also provides the following:



        dpkg-reconfigure iptables-persistent


        (You will need to answer yes to the questions about whether to save the rules.)



        After that, the next time iptables-persistent is started/restarted, the iptables rulesets you expect will be loaded.






        share|improve this answer












        iptables-persistent does not work that way. Restarting the iptables-persistent "service" does not capture the current state of the iptables and save it; all it does is reinstate the iptables rules that were saved when the package was last configured.



        To configure iptables-persistent, you need to tell it about your current iptables ruleset.



        One way to accomplish that is as follows:



        iptables-save >/etc/iptables/rules.v4
        ip6tables-save >/etc/iptables/rules.v6


        Or, equivalently, the iptables-persistent package also provides the following:



        dpkg-reconfigure iptables-persistent


        (You will need to answer yes to the questions about whether to save the rules.)



        After that, the next time iptables-persistent is started/restarted, the iptables rulesets you expect will be loaded.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 21 '14 at 16:32









        Steven Monday

        1,143911




        1,143911
























            up vote
            5
            down vote













            Very simple way to save the current iptables rules is to use the command:



            sudo service netfilter-persistent save



            Using the above, which works at least in Ubuntu after installing the netfilter-persistent (and iptables-persistent) package, there is no need to run manually the iptables commands or to reconfigure the package (as suggested by even the accepted Answer above).






            share|improve this answer























            • Is it sudo service netfilter-persistent save or sudo service netfilter-persistent save . ? (Dot at the end.)
              – Tomasz
              Feb 27 at 15:15










            • Thanks for noting that, the correct command is w/o the dot at the end of line. Corrected the Answer accordingly.
              – OpenITeX
              Nov 23 at 22:26















            up vote
            5
            down vote













            Very simple way to save the current iptables rules is to use the command:



            sudo service netfilter-persistent save



            Using the above, which works at least in Ubuntu after installing the netfilter-persistent (and iptables-persistent) package, there is no need to run manually the iptables commands or to reconfigure the package (as suggested by even the accepted Answer above).






            share|improve this answer























            • Is it sudo service netfilter-persistent save or sudo service netfilter-persistent save . ? (Dot at the end.)
              – Tomasz
              Feb 27 at 15:15










            • Thanks for noting that, the correct command is w/o the dot at the end of line. Corrected the Answer accordingly.
              – OpenITeX
              Nov 23 at 22:26













            up vote
            5
            down vote










            up vote
            5
            down vote









            Very simple way to save the current iptables rules is to use the command:



            sudo service netfilter-persistent save



            Using the above, which works at least in Ubuntu after installing the netfilter-persistent (and iptables-persistent) package, there is no need to run manually the iptables commands or to reconfigure the package (as suggested by even the accepted Answer above).






            share|improve this answer














            Very simple way to save the current iptables rules is to use the command:



            sudo service netfilter-persistent save



            Using the above, which works at least in Ubuntu after installing the netfilter-persistent (and iptables-persistent) package, there is no need to run manually the iptables commands or to reconfigure the package (as suggested by even the accepted Answer above).







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 23 at 22:25

























            answered Nov 3 '16 at 16:53









            OpenITeX

            15116




            15116












            • Is it sudo service netfilter-persistent save or sudo service netfilter-persistent save . ? (Dot at the end.)
              – Tomasz
              Feb 27 at 15:15










            • Thanks for noting that, the correct command is w/o the dot at the end of line. Corrected the Answer accordingly.
              – OpenITeX
              Nov 23 at 22:26


















            • Is it sudo service netfilter-persistent save or sudo service netfilter-persistent save . ? (Dot at the end.)
              – Tomasz
              Feb 27 at 15:15










            • Thanks for noting that, the correct command is w/o the dot at the end of line. Corrected the Answer accordingly.
              – OpenITeX
              Nov 23 at 22:26
















            Is it sudo service netfilter-persistent save or sudo service netfilter-persistent save . ? (Dot at the end.)
            – Tomasz
            Feb 27 at 15:15




            Is it sudo service netfilter-persistent save or sudo service netfilter-persistent save . ? (Dot at the end.)
            – Tomasz
            Feb 27 at 15:15












            Thanks for noting that, the correct command is w/o the dot at the end of line. Corrected the Answer accordingly.
            – OpenITeX
            Nov 23 at 22:26




            Thanks for noting that, the correct command is w/o the dot at the end of line. Corrected the Answer accordingly.
            – OpenITeX
            Nov 23 at 22:26










            up vote
            3
            down vote













            $ iptables ... DROP //command successfully drops the rule
            $ sudo iptables -L //shows rule has been deleted


            That's not what DROP means or does. From man iptables:




            ...the special values ACCEPT, DROP, QUEUE or RETURN. ACCEPT means to let the packet through. DROP means to drop the packet on the floor. QUEUE means...




            So what you've done is add a new rule. It may effectively supersede any number of other rules, but those rules still exist.



            When checking stuff like this (your iptables -L output), I would feed it though grep "string unique to this rule" rather than use your eyes. It's easier and faster to do, and less error prone.



            iptables -L | grep "some unique string"


            If you want to delete a rule, use the -D switch; the man page describes two forms of this:




            -D, --delete chain rule-specification



            -D, --delete chain rulenum



            Delete one or more rules from the selected chain. There are two versions of this command: the rule can be specified as a number in the chain (starting at 1 for the first rule) or a rule to match.







            share|improve this answer





















            • sorry that was unclear. I am using the -D option to DROP a rule. See the change above
              – bernie2436
              Apr 21 '14 at 16:13






            • 2




              -D stands for "delete" not "DROP" Using the term "DROP" to mean anything other than a jump target when talking about iptables is confusing as hell.
              – Bratchley
              Apr 21 '14 at 16:27















            up vote
            3
            down vote













            $ iptables ... DROP //command successfully drops the rule
            $ sudo iptables -L //shows rule has been deleted


            That's not what DROP means or does. From man iptables:




            ...the special values ACCEPT, DROP, QUEUE or RETURN. ACCEPT means to let the packet through. DROP means to drop the packet on the floor. QUEUE means...




            So what you've done is add a new rule. It may effectively supersede any number of other rules, but those rules still exist.



            When checking stuff like this (your iptables -L output), I would feed it though grep "string unique to this rule" rather than use your eyes. It's easier and faster to do, and less error prone.



            iptables -L | grep "some unique string"


            If you want to delete a rule, use the -D switch; the man page describes two forms of this:




            -D, --delete chain rule-specification



            -D, --delete chain rulenum



            Delete one or more rules from the selected chain. There are two versions of this command: the rule can be specified as a number in the chain (starting at 1 for the first rule) or a rule to match.







            share|improve this answer





















            • sorry that was unclear. I am using the -D option to DROP a rule. See the change above
              – bernie2436
              Apr 21 '14 at 16:13






            • 2




              -D stands for "delete" not "DROP" Using the term "DROP" to mean anything other than a jump target when talking about iptables is confusing as hell.
              – Bratchley
              Apr 21 '14 at 16:27













            up vote
            3
            down vote










            up vote
            3
            down vote









            $ iptables ... DROP //command successfully drops the rule
            $ sudo iptables -L //shows rule has been deleted


            That's not what DROP means or does. From man iptables:




            ...the special values ACCEPT, DROP, QUEUE or RETURN. ACCEPT means to let the packet through. DROP means to drop the packet on the floor. QUEUE means...




            So what you've done is add a new rule. It may effectively supersede any number of other rules, but those rules still exist.



            When checking stuff like this (your iptables -L output), I would feed it though grep "string unique to this rule" rather than use your eyes. It's easier and faster to do, and less error prone.



            iptables -L | grep "some unique string"


            If you want to delete a rule, use the -D switch; the man page describes two forms of this:




            -D, --delete chain rule-specification



            -D, --delete chain rulenum



            Delete one or more rules from the selected chain. There are two versions of this command: the rule can be specified as a number in the chain (starting at 1 for the first rule) or a rule to match.







            share|improve this answer












            $ iptables ... DROP //command successfully drops the rule
            $ sudo iptables -L //shows rule has been deleted


            That's not what DROP means or does. From man iptables:




            ...the special values ACCEPT, DROP, QUEUE or RETURN. ACCEPT means to let the packet through. DROP means to drop the packet on the floor. QUEUE means...




            So what you've done is add a new rule. It may effectively supersede any number of other rules, but those rules still exist.



            When checking stuff like this (your iptables -L output), I would feed it though grep "string unique to this rule" rather than use your eyes. It's easier and faster to do, and less error prone.



            iptables -L | grep "some unique string"


            If you want to delete a rule, use the -D switch; the man page describes two forms of this:




            -D, --delete chain rule-specification



            -D, --delete chain rulenum



            Delete one or more rules from the selected chain. There are two versions of this command: the rule can be specified as a number in the chain (starting at 1 for the first rule) or a rule to match.








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 21 '14 at 16:06









            goldilocks

            61.1k13150204




            61.1k13150204












            • sorry that was unclear. I am using the -D option to DROP a rule. See the change above
              – bernie2436
              Apr 21 '14 at 16:13






            • 2




              -D stands for "delete" not "DROP" Using the term "DROP" to mean anything other than a jump target when talking about iptables is confusing as hell.
              – Bratchley
              Apr 21 '14 at 16:27


















            • sorry that was unclear. I am using the -D option to DROP a rule. See the change above
              – bernie2436
              Apr 21 '14 at 16:13






            • 2




              -D stands for "delete" not "DROP" Using the term "DROP" to mean anything other than a jump target when talking about iptables is confusing as hell.
              – Bratchley
              Apr 21 '14 at 16:27
















            sorry that was unclear. I am using the -D option to DROP a rule. See the change above
            – bernie2436
            Apr 21 '14 at 16:13




            sorry that was unclear. I am using the -D option to DROP a rule. See the change above
            – bernie2436
            Apr 21 '14 at 16:13




            2




            2




            -D stands for "delete" not "DROP" Using the term "DROP" to mean anything other than a jump target when talking about iptables is confusing as hell.
            – Bratchley
            Apr 21 '14 at 16:27




            -D stands for "delete" not "DROP" Using the term "DROP" to mean anything other than a jump target when talking about iptables is confusing as hell.
            – Bratchley
            Apr 21 '14 at 16:27


















            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f125833%2fwhy-isnt-the-iptables-persistent-service-saving-my-changes%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

            Morgemoulin

            Scott Moir

            Souastre