trying to close two ports with firewalld, leaving everything else open

Is the infant mortality rate among African-American babies in Youngstown, Ohio greater than that of babies in Iran?

How much steel armor can you wear and still be able to swim?

Harmonic Series Phase Difference?

Fibonacci sequence and other metallic sequences emerged in the form of fractions

How to write a nice frame challenge?

What is "dot" sign in •NO?

How can I ping multiple IP addresses at the same time?

Do details of my undergraduate title matter?

How to make a villain when your PCs are villains?

I'm yearning in grey

How would Japanese people react to someone refusing to say “itadakimasu” for religious reasons?

Having some issue with notation in a Hilbert space

How to prevent cables getting intertwined

A medieval book with a redhead girl as a main character who allies with vampires and werewolves against scientific opposition

Can you place a web spell on a surface you cannot see?

If the mass of the Earth is decreasing by sending debris in space, does its angular momentum also decrease?

How can caller ID be faked?

Justifying Affordable Bespoke Spaceships

Why swap space doesn't get filesystem check at boot time?

How to use random to choose colors

I have found ports on my Samsung smart tv running a display service. What can I do with it?

Expand command in an argument before the main command

Are there any individual aliens that have gained superpowers in the Marvel universe?

Time at 1G acceleration to travel 100 000 light years



trying to close two ports with firewalld, leaving everything else open







.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I think I'm using the wrong technique, but not sure of the right one.



Machine: Red Hat release 7.2



firewalld.noarch: 0.3.9-14.el7



I've been asked to close two ports but insure that all other ports are open. The solution needs to be easy to turn on and off. To that end I have done:



  • bring up firewalld


  • set "trusted" as default zone # Trusted opens all ports


  • firewall-cmd --zone=trusted --add-interface=eno16780032 # only Ethernet interface on this server.


  • For testing purposes, executing nc -l port_number to have something answering on that port.


Test by: go to a different machine, execute "telnet machine_name port_number" and observe that I get a response. (Restarting nc after each test.)



Turn off port:



  • firewall-cmd --zone=trusted --remove-port port_number/tcp

Verify:



  • firewall-cmd --zone=trusted --query-port port_number/tcp

Returns "no"



At this point, nc should be listening on port_number, but it should be blocked by firewalld. I shouldn't be able to connect to it.



However, "telnet machine_name port_number" from a different machine still connects.



I'm not even trying to make it persistent at this point, just trying to get the rule to work. What am I doing wrong?



The application: We have a homegrown back end service that runs as a master/slave configuration. The slave is up at all times, to sync data with the master. Only the system designated "master" can be used by the front end. (To make it a true cluster would involve too much work, the developers tell me.)



There's a load balancer in "the cloud" (over which we don't have direct control) that points to both machines. The objective is to block two key ports on the slave so the load balancer always goes to the master. When we fail over, the ports on the "slave" (now master) are unblocked and the ports on the "master" (now slave) are blocked, forcing the load balancer to go to the new master.



This is probably not a good use of the load balancer or of firewalld, but it's an odd application and we're just trying to find something that works that doesn't involve either mucking with the load balancer or shutting down services on the slave.



Any ideas?










share|improve this question




























    0















    I think I'm using the wrong technique, but not sure of the right one.



    Machine: Red Hat release 7.2



    firewalld.noarch: 0.3.9-14.el7



    I've been asked to close two ports but insure that all other ports are open. The solution needs to be easy to turn on and off. To that end I have done:



    • bring up firewalld


    • set "trusted" as default zone # Trusted opens all ports


    • firewall-cmd --zone=trusted --add-interface=eno16780032 # only Ethernet interface on this server.


    • For testing purposes, executing nc -l port_number to have something answering on that port.


    Test by: go to a different machine, execute "telnet machine_name port_number" and observe that I get a response. (Restarting nc after each test.)



    Turn off port:



    • firewall-cmd --zone=trusted --remove-port port_number/tcp

    Verify:



    • firewall-cmd --zone=trusted --query-port port_number/tcp

    Returns "no"



    At this point, nc should be listening on port_number, but it should be blocked by firewalld. I shouldn't be able to connect to it.



    However, "telnet machine_name port_number" from a different machine still connects.



    I'm not even trying to make it persistent at this point, just trying to get the rule to work. What am I doing wrong?



    The application: We have a homegrown back end service that runs as a master/slave configuration. The slave is up at all times, to sync data with the master. Only the system designated "master" can be used by the front end. (To make it a true cluster would involve too much work, the developers tell me.)



    There's a load balancer in "the cloud" (over which we don't have direct control) that points to both machines. The objective is to block two key ports on the slave so the load balancer always goes to the master. When we fail over, the ports on the "slave" (now master) are unblocked and the ports on the "master" (now slave) are blocked, forcing the load balancer to go to the new master.



    This is probably not a good use of the load balancer or of firewalld, but it's an odd application and we're just trying to find something that works that doesn't involve either mucking with the load balancer or shutting down services on the slave.



    Any ideas?










    share|improve this question
























      0












      0








      0








      I think I'm using the wrong technique, but not sure of the right one.



      Machine: Red Hat release 7.2



      firewalld.noarch: 0.3.9-14.el7



      I've been asked to close two ports but insure that all other ports are open. The solution needs to be easy to turn on and off. To that end I have done:



      • bring up firewalld


      • set "trusted" as default zone # Trusted opens all ports


      • firewall-cmd --zone=trusted --add-interface=eno16780032 # only Ethernet interface on this server.


      • For testing purposes, executing nc -l port_number to have something answering on that port.


      Test by: go to a different machine, execute "telnet machine_name port_number" and observe that I get a response. (Restarting nc after each test.)



      Turn off port:



      • firewall-cmd --zone=trusted --remove-port port_number/tcp

      Verify:



      • firewall-cmd --zone=trusted --query-port port_number/tcp

      Returns "no"



      At this point, nc should be listening on port_number, but it should be blocked by firewalld. I shouldn't be able to connect to it.



      However, "telnet machine_name port_number" from a different machine still connects.



      I'm not even trying to make it persistent at this point, just trying to get the rule to work. What am I doing wrong?



      The application: We have a homegrown back end service that runs as a master/slave configuration. The slave is up at all times, to sync data with the master. Only the system designated "master" can be used by the front end. (To make it a true cluster would involve too much work, the developers tell me.)



      There's a load balancer in "the cloud" (over which we don't have direct control) that points to both machines. The objective is to block two key ports on the slave so the load balancer always goes to the master. When we fail over, the ports on the "slave" (now master) are unblocked and the ports on the "master" (now slave) are blocked, forcing the load balancer to go to the new master.



      This is probably not a good use of the load balancer or of firewalld, but it's an odd application and we're just trying to find something that works that doesn't involve either mucking with the load balancer or shutting down services on the slave.



      Any ideas?










      share|improve this question














      I think I'm using the wrong technique, but not sure of the right one.



      Machine: Red Hat release 7.2



      firewalld.noarch: 0.3.9-14.el7



      I've been asked to close two ports but insure that all other ports are open. The solution needs to be easy to turn on and off. To that end I have done:



      • bring up firewalld


      • set "trusted" as default zone # Trusted opens all ports


      • firewall-cmd --zone=trusted --add-interface=eno16780032 # only Ethernet interface on this server.


      • For testing purposes, executing nc -l port_number to have something answering on that port.


      Test by: go to a different machine, execute "telnet machine_name port_number" and observe that I get a response. (Restarting nc after each test.)



      Turn off port:



      • firewall-cmd --zone=trusted --remove-port port_number/tcp

      Verify:



      • firewall-cmd --zone=trusted --query-port port_number/tcp

      Returns "no"



      At this point, nc should be listening on port_number, but it should be blocked by firewalld. I shouldn't be able to connect to it.



      However, "telnet machine_name port_number" from a different machine still connects.



      I'm not even trying to make it persistent at this point, just trying to get the rule to work. What am I doing wrong?



      The application: We have a homegrown back end service that runs as a master/slave configuration. The slave is up at all times, to sync data with the master. Only the system designated "master" can be used by the front end. (To make it a true cluster would involve too much work, the developers tell me.)



      There's a load balancer in "the cloud" (over which we don't have direct control) that points to both machines. The objective is to block two key ports on the slave so the load balancer always goes to the master. When we fail over, the ports on the "slave" (now master) are unblocked and the ports on the "master" (now slave) are blocked, forcing the load balancer to go to the new master.



      This is probably not a good use of the load balancer or of firewalld, but it's an odd application and we're just trying to find something that works that doesn't involve either mucking with the load balancer or shutting down services on the slave.



      Any ideas?







      load-balancing firewalld master-slave firewall-cmd






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 31 at 19:22









      Ron ChristianRon Christian

      11




      11




















          1 Answer
          1






          active

          oldest

          votes


















          0














          IIRC the philosophy behind firewalld is to close anything and open just the ports you need. So just the inverse you are trying to do. Therefore commands like --add-port will add the port specified to be open.

          As an example, adding port 80 will just add another ACCEPT rule to iptables but since the target for the zone trusted is ACCEPT already, this rule just has no meaning.



          $ firewall-cmd --zone=trusted --add-port=80/tcp

          $ iptables -L -n | grep 80
          ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 ctstate NEW


          Same if you remove the port with --remove-port, which should give a hint if the corresponding port is not configured.



          $ firewall-cmd --zone=trusted --remove-port 80/tcp
          success
          $ firewall-cmd --zone=trusted --remove-port 80/tcp
          Warning: NOT_ENABLED: '80:tcp' not in 'trusted'
          success



          firewalld also provides rich-rules which can be used for what you want to achieve.



          The command as follows would close port 80/tcp.



          firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" port port="80" protocol="tcp" reject'


          If you want to allow a single IP address to connect to that port, you could add a source.



          firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'


          The source parameter also accepts subnets in CIDR notation.



          firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.0/24" port port="80" protocol="tcp" reject'





          share|improve this answer























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "2"
            ;
            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%2fserverfault.com%2fquestions%2f969706%2ftrying-to-close-two-ports-with-firewalld-leaving-everything-else-open%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














            IIRC the philosophy behind firewalld is to close anything and open just the ports you need. So just the inverse you are trying to do. Therefore commands like --add-port will add the port specified to be open.

            As an example, adding port 80 will just add another ACCEPT rule to iptables but since the target for the zone trusted is ACCEPT already, this rule just has no meaning.



            $ firewall-cmd --zone=trusted --add-port=80/tcp

            $ iptables -L -n | grep 80
            ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 ctstate NEW


            Same if you remove the port with --remove-port, which should give a hint if the corresponding port is not configured.



            $ firewall-cmd --zone=trusted --remove-port 80/tcp
            success
            $ firewall-cmd --zone=trusted --remove-port 80/tcp
            Warning: NOT_ENABLED: '80:tcp' not in 'trusted'
            success



            firewalld also provides rich-rules which can be used for what you want to achieve.



            The command as follows would close port 80/tcp.



            firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" port port="80" protocol="tcp" reject'


            If you want to allow a single IP address to connect to that port, you could add a source.



            firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'


            The source parameter also accepts subnets in CIDR notation.



            firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.0/24" port port="80" protocol="tcp" reject'





            share|improve this answer



























              0














              IIRC the philosophy behind firewalld is to close anything and open just the ports you need. So just the inverse you are trying to do. Therefore commands like --add-port will add the port specified to be open.

              As an example, adding port 80 will just add another ACCEPT rule to iptables but since the target for the zone trusted is ACCEPT already, this rule just has no meaning.



              $ firewall-cmd --zone=trusted --add-port=80/tcp

              $ iptables -L -n | grep 80
              ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 ctstate NEW


              Same if you remove the port with --remove-port, which should give a hint if the corresponding port is not configured.



              $ firewall-cmd --zone=trusted --remove-port 80/tcp
              success
              $ firewall-cmd --zone=trusted --remove-port 80/tcp
              Warning: NOT_ENABLED: '80:tcp' not in 'trusted'
              success



              firewalld also provides rich-rules which can be used for what you want to achieve.



              The command as follows would close port 80/tcp.



              firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" port port="80" protocol="tcp" reject'


              If you want to allow a single IP address to connect to that port, you could add a source.



              firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'


              The source parameter also accepts subnets in CIDR notation.



              firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.0/24" port port="80" protocol="tcp" reject'





              share|improve this answer

























                0












                0








                0







                IIRC the philosophy behind firewalld is to close anything and open just the ports you need. So just the inverse you are trying to do. Therefore commands like --add-port will add the port specified to be open.

                As an example, adding port 80 will just add another ACCEPT rule to iptables but since the target for the zone trusted is ACCEPT already, this rule just has no meaning.



                $ firewall-cmd --zone=trusted --add-port=80/tcp

                $ iptables -L -n | grep 80
                ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 ctstate NEW


                Same if you remove the port with --remove-port, which should give a hint if the corresponding port is not configured.



                $ firewall-cmd --zone=trusted --remove-port 80/tcp
                success
                $ firewall-cmd --zone=trusted --remove-port 80/tcp
                Warning: NOT_ENABLED: '80:tcp' not in 'trusted'
                success



                firewalld also provides rich-rules which can be used for what you want to achieve.



                The command as follows would close port 80/tcp.



                firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" port port="80" protocol="tcp" reject'


                If you want to allow a single IP address to connect to that port, you could add a source.



                firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'


                The source parameter also accepts subnets in CIDR notation.



                firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.0/24" port port="80" protocol="tcp" reject'





                share|improve this answer













                IIRC the philosophy behind firewalld is to close anything and open just the ports you need. So just the inverse you are trying to do. Therefore commands like --add-port will add the port specified to be open.

                As an example, adding port 80 will just add another ACCEPT rule to iptables but since the target for the zone trusted is ACCEPT already, this rule just has no meaning.



                $ firewall-cmd --zone=trusted --add-port=80/tcp

                $ iptables -L -n | grep 80
                ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 ctstate NEW


                Same if you remove the port with --remove-port, which should give a hint if the corresponding port is not configured.



                $ firewall-cmd --zone=trusted --remove-port 80/tcp
                success
                $ firewall-cmd --zone=trusted --remove-port 80/tcp
                Warning: NOT_ENABLED: '80:tcp' not in 'trusted'
                success



                firewalld also provides rich-rules which can be used for what you want to achieve.



                The command as follows would close port 80/tcp.



                firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" port port="80" protocol="tcp" reject'


                If you want to allow a single IP address to connect to that port, you could add a source.



                firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'


                The source parameter also accepts subnets in CIDR notation.



                firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.0/24" port port="80" protocol="tcp" reject'






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jun 1 at 9:39









                ThomasThomas

                3,33841525




                3,33841525



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Server Fault!


                    • 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%2fserverfault.com%2fquestions%2f969706%2ftrying-to-close-two-ports-with-firewalld-leaving-everything-else-open%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

                    Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

                    Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

                    What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company