IPtables allow traffic from only an ip and one port to one port












2















I have this command for allow traffic to one port only from one ip:



iptables -I INPUT ! -s $BUNGEE_IP -p tcp --dport $PORT -j DROP


But I would like allow only a single port of "$BUNGEE_IP", something like this, but dosen't work:



iptables -I INPUT ! -s $BUNGEE_IP:$PORT -p tcp --dport $PORT -j DROP


How can i do this?










share|improve this question



























    2















    I have this command for allow traffic to one port only from one ip:



    iptables -I INPUT ! -s $BUNGEE_IP -p tcp --dport $PORT -j DROP


    But I would like allow only a single port of "$BUNGEE_IP", something like this, but dosen't work:



    iptables -I INPUT ! -s $BUNGEE_IP:$PORT -p tcp --dport $PORT -j DROP


    How can i do this?










    share|improve this question

























      2












      2








      2








      I have this command for allow traffic to one port only from one ip:



      iptables -I INPUT ! -s $BUNGEE_IP -p tcp --dport $PORT -j DROP


      But I would like allow only a single port of "$BUNGEE_IP", something like this, but dosen't work:



      iptables -I INPUT ! -s $BUNGEE_IP:$PORT -p tcp --dport $PORT -j DROP


      How can i do this?










      share|improve this question














      I have this command for allow traffic to one port only from one ip:



      iptables -I INPUT ! -s $BUNGEE_IP -p tcp --dport $PORT -j DROP


      But I would like allow only a single port of "$BUNGEE_IP", something like this, but dosen't work:



      iptables -I INPUT ! -s $BUNGEE_IP:$PORT -p tcp --dport $PORT -j DROP


      How can i do this?







      iptables






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 15 at 22:15









      ElseElse

      111




      111






















          1 Answer
          1






          active

          oldest

          votes


















          1














          I think this should do what you want, where 192.168.0.12 represents the IP you want to allow and port 80 the port from that IP you want to allow:



          #!/bin/sh
          #
          # 1110080_firewall 2019.01.05 Ver:0.01
          # Most basic iptables firewall.
          # Currently for this question:
          # https://askubuntu.com/questions/1110080/iptables-allow-traffic-from-only-an-ip-and-one-port-to-one-port
          #

          # The location of the iptables program
          #
          IPTABLES=/sbin/iptables

          #Set some stuff
          #
          EXTIF="ens5"
          UNIVERSE="0.0.0.0/0"

          echo 1110080_firewall $FWVER begin.

          #Clearing any previous configuration
          #
          $IPTABLES -P INPUT DROP
          $IPTABLES -F INPUT
          $IPTABLES -P OUTPUT ACCEPT
          $IPTABLES -F OUTPUT
          #$IPTABLES -P FORWARD DROP
          $IPTABLES -F FORWARD
          #$IPTABLES -t nat -F

          # Reset all IPTABLES counters
          $IPTABLES -Z

          # loopback interfaces are valid.
          #
          $IPTABLES -A INPUT -i lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT
          $IPTABLES -A INPUT -i $EXTIF -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

          $IPTABLES -A INPUT -i $EXTIF -s 192.168.0.12 -p tcp --sport 80 --dport 80 -j ACCEPT

          #$IPTABLES -A INPUT -j DROP

          echo 1110080_firewall $FWVER done.





          share|improve this answer























            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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2faskubuntu.com%2fquestions%2f1110080%2fiptables-allow-traffic-from-only-an-ip-and-one-port-to-one-port%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









            1














            I think this should do what you want, where 192.168.0.12 represents the IP you want to allow and port 80 the port from that IP you want to allow:



            #!/bin/sh
            #
            # 1110080_firewall 2019.01.05 Ver:0.01
            # Most basic iptables firewall.
            # Currently for this question:
            # https://askubuntu.com/questions/1110080/iptables-allow-traffic-from-only-an-ip-and-one-port-to-one-port
            #

            # The location of the iptables program
            #
            IPTABLES=/sbin/iptables

            #Set some stuff
            #
            EXTIF="ens5"
            UNIVERSE="0.0.0.0/0"

            echo 1110080_firewall $FWVER begin.

            #Clearing any previous configuration
            #
            $IPTABLES -P INPUT DROP
            $IPTABLES -F INPUT
            $IPTABLES -P OUTPUT ACCEPT
            $IPTABLES -F OUTPUT
            #$IPTABLES -P FORWARD DROP
            $IPTABLES -F FORWARD
            #$IPTABLES -t nat -F

            # Reset all IPTABLES counters
            $IPTABLES -Z

            # loopback interfaces are valid.
            #
            $IPTABLES -A INPUT -i lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT
            $IPTABLES -A INPUT -i $EXTIF -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

            $IPTABLES -A INPUT -i $EXTIF -s 192.168.0.12 -p tcp --sport 80 --dport 80 -j ACCEPT

            #$IPTABLES -A INPUT -j DROP

            echo 1110080_firewall $FWVER done.





            share|improve this answer




























              1














              I think this should do what you want, where 192.168.0.12 represents the IP you want to allow and port 80 the port from that IP you want to allow:



              #!/bin/sh
              #
              # 1110080_firewall 2019.01.05 Ver:0.01
              # Most basic iptables firewall.
              # Currently for this question:
              # https://askubuntu.com/questions/1110080/iptables-allow-traffic-from-only-an-ip-and-one-port-to-one-port
              #

              # The location of the iptables program
              #
              IPTABLES=/sbin/iptables

              #Set some stuff
              #
              EXTIF="ens5"
              UNIVERSE="0.0.0.0/0"

              echo 1110080_firewall $FWVER begin.

              #Clearing any previous configuration
              #
              $IPTABLES -P INPUT DROP
              $IPTABLES -F INPUT
              $IPTABLES -P OUTPUT ACCEPT
              $IPTABLES -F OUTPUT
              #$IPTABLES -P FORWARD DROP
              $IPTABLES -F FORWARD
              #$IPTABLES -t nat -F

              # Reset all IPTABLES counters
              $IPTABLES -Z

              # loopback interfaces are valid.
              #
              $IPTABLES -A INPUT -i lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT
              $IPTABLES -A INPUT -i $EXTIF -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

              $IPTABLES -A INPUT -i $EXTIF -s 192.168.0.12 -p tcp --sport 80 --dport 80 -j ACCEPT

              #$IPTABLES -A INPUT -j DROP

              echo 1110080_firewall $FWVER done.





              share|improve this answer


























                1












                1








                1







                I think this should do what you want, where 192.168.0.12 represents the IP you want to allow and port 80 the port from that IP you want to allow:



                #!/bin/sh
                #
                # 1110080_firewall 2019.01.05 Ver:0.01
                # Most basic iptables firewall.
                # Currently for this question:
                # https://askubuntu.com/questions/1110080/iptables-allow-traffic-from-only-an-ip-and-one-port-to-one-port
                #

                # The location of the iptables program
                #
                IPTABLES=/sbin/iptables

                #Set some stuff
                #
                EXTIF="ens5"
                UNIVERSE="0.0.0.0/0"

                echo 1110080_firewall $FWVER begin.

                #Clearing any previous configuration
                #
                $IPTABLES -P INPUT DROP
                $IPTABLES -F INPUT
                $IPTABLES -P OUTPUT ACCEPT
                $IPTABLES -F OUTPUT
                #$IPTABLES -P FORWARD DROP
                $IPTABLES -F FORWARD
                #$IPTABLES -t nat -F

                # Reset all IPTABLES counters
                $IPTABLES -Z

                # loopback interfaces are valid.
                #
                $IPTABLES -A INPUT -i lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT
                $IPTABLES -A INPUT -i $EXTIF -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

                $IPTABLES -A INPUT -i $EXTIF -s 192.168.0.12 -p tcp --sport 80 --dport 80 -j ACCEPT

                #$IPTABLES -A INPUT -j DROP

                echo 1110080_firewall $FWVER done.





                share|improve this answer













                I think this should do what you want, where 192.168.0.12 represents the IP you want to allow and port 80 the port from that IP you want to allow:



                #!/bin/sh
                #
                # 1110080_firewall 2019.01.05 Ver:0.01
                # Most basic iptables firewall.
                # Currently for this question:
                # https://askubuntu.com/questions/1110080/iptables-allow-traffic-from-only-an-ip-and-one-port-to-one-port
                #

                # The location of the iptables program
                #
                IPTABLES=/sbin/iptables

                #Set some stuff
                #
                EXTIF="ens5"
                UNIVERSE="0.0.0.0/0"

                echo 1110080_firewall $FWVER begin.

                #Clearing any previous configuration
                #
                $IPTABLES -P INPUT DROP
                $IPTABLES -F INPUT
                $IPTABLES -P OUTPUT ACCEPT
                $IPTABLES -F OUTPUT
                #$IPTABLES -P FORWARD DROP
                $IPTABLES -F FORWARD
                #$IPTABLES -t nat -F

                # Reset all IPTABLES counters
                $IPTABLES -Z

                # loopback interfaces are valid.
                #
                $IPTABLES -A INPUT -i lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT
                $IPTABLES -A INPUT -i $EXTIF -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

                $IPTABLES -A INPUT -i $EXTIF -s 192.168.0.12 -p tcp --sport 80 --dport 80 -j ACCEPT

                #$IPTABLES -A INPUT -j DROP

                echo 1110080_firewall $FWVER done.






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 16 at 7:37









                Doug SmythiesDoug Smythies

                7,21631530




                7,21631530






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Ask Ubuntu!


                    • 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%2faskubuntu.com%2fquestions%2f1110080%2fiptables-allow-traffic-from-only-an-ip-and-one-port-to-one-port%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

                    flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                    Mangá

                     ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕